コード例 #1
0
 /**
  * Processes a single import command.
  *
  * @since  1.0.0
  * @param  array $item The import command.
  */
 protected function process_item($item, $source)
 {
     $res = false;
     lib2()->array->equip($item, 'task', 'data');
     $task = $item['task'];
     $data = $item['data'];
     $model = MS_Factory::create('MS_Model_Import');
     $model->source_key = $source;
     // Set MS_STOP_EMAILS modifier to suppress any outgoing emails.
     MS_Plugin::set_modifier('MS_STOP_EMAILS', true);
     // Possible tasks are defined in ms-view-settings-import.js
     switch ($task) {
         case 'start':
             lib2()->array->equip($item, 'clear');
             $clear = lib2()->is_true($item['clear']);
             $model->start($clear);
             $res = true;
             break;
         case 'import-membership':
             // Function expects an object, not an array!
             $data = (object) $data;
             $model->import_membership($data);
             $res = true;
             break;
         case 'import-member':
             // Function expects an object, not an array!
             $data = (object) $data;
             $model->import_member($data);
             $res = true;
             break;
         case 'import-settings':
             lib2()->array->equip($item, 'setting', 'value');
             $setting = $item['setting'];
             $value = $item['value'];
             $model->import_setting($setting, $value);
             $res = true;
             break;
         case 'done':
             $model->done();
             $res = true;
             break;
     }
     /**
      * After the import action was complated notify other objects and
      * add-ons.
      *
      * @since  1.0.0
      */
     do_action('ms_import_action_' . $task, $item);
     return $res;
 }