runStep() public method

Run the step in the import.
public runStep ( integer $Step = 1 ) : mixed
$Step integer the step to run.
return mixed Whether the step succeeded or an array of information.
Esempio n. 1
0
 /**
  * Manage importing process.
  *
  * @since 2.0.0
  * @access public
  */
 public function go($transientKey = '')
 {
     $this->permission('Garden.Settings.Manage');
     if (!Gdn::session()->validateTransientKey($transientKey) && !Gdn::request()->isAuthenticatedPostBack()) {
         throw new Gdn_UserException('The CSRF token is invalid.', 403);
     }
     $Imp = new ImportModel();
     $Imp->loadState();
     $this->setData('Steps', $Imp->steps());
     $this->Form = new Gdn_Form();
     if ($Imp->CurrentStep < 1) {
         // Check for the import file.
         if ($Imp->ImportPath) {
             $Imp->CurrentStep = 1;
         } else {
             redirect(strtolower($this->Application) . '/import');
         }
     }
     if ($Imp->CurrentStep >= 1) {
         if ($this->Form->authenticatedPostBack()) {
             $Imp->fromPost($this->Form->formValues());
         }
         try {
             $Result = $Imp->runStep($Imp->CurrentStep);
         } catch (Exception $Ex) {
             $Result = false;
             $this->Form->addError($Ex);
             $this->setJson('Error', true);
         }
         if ($Result === true) {
             $Imp->CurrentStep++;
         } elseif ($Result === 'COMPLETE') {
             $this->setJson('Complete', true);
         }
         /*elseif(is_array($Result)) {
         			saveToConfig(array(
         				'Garden.Import.CurrentStep' => $CurrentStep,
         				'Garden.Import.CurrentStepData' => val('Data', $Result)));
         			$this->setData('CurrentStepMessage', val('Message', $Result));
         		}*/
     }
     $Imp->saveState();
     $this->Form->setValidationResults($Imp->Validation->results());
     $this->setData('Stats', val('Stats', $Imp->Data, array()));
     $this->setData('CurrentStep', $Imp->CurrentStep);
     $this->setData('CurrentStepMessage', val('CurrentStepMessage', $Imp->Data, ''));
     $this->setData('ErrorType', val('ErrorType', $Imp));
     if ($this->data('ErrorType')) {
         $this->setJson('Error', true);
     }
     $Imp->toPost($Post);
     $this->Form->formValues($Post);
     $this->addJsFile('import.js');
     $this->render();
 }