Version: current

     1 <?php
     2 class ProductImport1CAdmin extends ModelAdmin {
     3
     4     public static $managed_models = array(
     5         'Import1CLog'
     6     );
     7
     8     static $url_segment = 'import';
     9     static $menu_title = 'Импорт';
    10     static $menu_priority = -10;
    11
    12     public static $collection_controller_class = "ProductImport1CAdmin_CollectionController";
    13
    14     function getLastLog(){
    15         return Import1CLog::get_last_log();
    16     }
    17
    18     function getWaitforstart() {
    19         return false;
    20     }
    21
    22     function getIsImportCanceled() {
    23         $rs = Session::get('Import.ImportCanceled');
    24         Session::clear('Import.ImportCanceled');
    25         return $rs;
    26     }
    27 }
    28
    29 class ProductImport1CAdmin_CollectionController extends ModelAdmin_CollectionController {
    30
    31     public function getModelSidebar() {
    32         return $this->renderWith('ProductImport1CAdminModelSidebar');
    33     }
    34
    35     public function ImportForm() {
    36         $fields = new FieldSet();
    37         $actions = new FieldSet(
    38             new FormAction('cancelImport', _t('ProductImport1CAdmin.CancelImport','Cancel Import'))
    39         );
    40         $form = new Form(
    41             $this,
    42             'ImportForm',
    43             $fields,
    44             $actions
    45         );
    46         return $form;
    47     }
    48
    49     /*
    50      * Отмена импорта:
    51      * - удаление импорта  и копирование в нужную папку
    52      * - удаление файла настроек
    53      * - удаление файла start_ok
    54      *
    55      */
    56     function cancelImport($data, $form) {
    57         if (!is_file(Base1CExchanger::absolute_import_path('stop_import'))) {
    58             file_put_contents(Base1CExchanger::absolute_import_path('stop_import'), '1');
    59             $form->sessionMessage(_t('ProductImport1CAdmin.ImportTaskCanceled', 'Import Canceled.'), 'info');
    60             Session::set('Import.ImportCanceled',  _t('ProductImport1CAdmin.ImportTaskCanceled', 'Import Canceled.'));
    61         }
    62         Director::redirectBack();
    63     }
    64
    65     public function CreateForm() {
    66         return false;
    67     }
    68
    69     function getResultsTable($searchCriteria) {
    70         $tf = parent::getResultsTable($searchCriteria);
    71         $tf->setHighlightConditions(array(
    72             array('rule'=>'$Status == "process"', 'class' => 'process', 'exclusive' => false),
    73             array('rule'=>'$Status == "error"', 'class' => 'error', 'exclusive' => false),
    74         ));
    75         return $tf;
    76     }
    77 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -