Inheritance: extends Gdn_Model
示例#1
0
 /**
  * Upload file and process it for mapping.
  */
 public function actionUpload()
 {
     // Get import post
     $import = craft()->request->getRequiredPost('import');
     // Get file
     $file = \CUploadedFile::getInstanceByName('file');
     // Is file valid?
     if (!is_null($file)) {
         // Determine folder
         $folder = craft()->path->getStoragePath() . 'import/';
         // Ensure folder exists
         IOHelper::ensureFolderExists($folder);
         // Get filepath - save in storage folder
         $path = $folder . $file->getName();
         // Save file to Craft's temp folder for later use
         $file->saveAs($path);
         // Put vars in model
         $model = new ImportModel();
         $model->filetype = $file->getType();
         // Validate filetype
         if ($model->validate()) {
             // Get columns
             $columns = craft()->import->columns($path);
             // Send variables to template and display
             $this->renderTemplate('import/_map', array('import' => $import, 'file' => $path, 'columns' => $columns));
         } else {
             // Not validated, show error
             craft()->userSession->setError(Craft::t('This filetype is not valid') . ': ' . $model->filetype);
         }
     } else {
         // No file uploaded
         craft()->userSession->setError(Craft::t('Please upload a file.'));
     }
 }
 /**
  * Upload file and process it for mapping.
  */
 public function actionUpload()
 {
     // Get import post
     $import = craft()->request->getRequiredPost('import');
     // Get file
     $file = \CUploadedFile::getInstanceByName('file');
     // Is file valid?
     if (!is_null($file)) {
         // Is asset source valid?
         if (isset($import['assetsource']) && !empty($import['assetsource'])) {
             // Get source
             $source = craft()->assetSources->getSourceTypeById($import['assetsource']);
             // Get folder to save to
             $folderId = craft()->assets->getRootFolderBySourceId($import['assetsource']);
             // Save file to Craft's temp folder for later use
             $fileName = AssetsHelper::cleanAssetName($file->name);
             $filePath = AssetsHelper::getTempFilePath($file->extensionName);
             $file->saveAs($filePath);
             // Move the file by source type implementation
             $response = $source->insertFileByPath($filePath, $folderId, $fileName, true);
             // Prevent sensitive information leak. Just in case.
             $response->deleteDataItem('filePath');
             // Get file id
             $fileId = $response->getDataItem('fileId');
             // Put vars in model
             $model = new ImportModel();
             $model->filetype = $file->getType();
             // Validate filetype
             if ($model->validate()) {
                 // Get columns
                 $columns = craft()->import->columns($fileId);
                 // Send variables to template and display
                 $this->renderTemplate('import/_map', array('import' => $import, 'file' => $fileId, 'columns' => $columns));
             } else {
                 // Not validated, show error
                 craft()->userSession->setError(Craft::t('This filetype is not valid') . ': ' . $model->filetype);
             }
         } else {
             // No asset source selected
             craft()->userSession->setError(Craft::t('Please select an asset source.'));
         }
     } else {
         // No file uploaded
         craft()->userSession->setError(Craft::t('Please upload a file.'));
     }
 }
 /**
  * Restart the import process. Undo any work we've done so far and erase state.
  *
  * @since 2.0.0
  * @access public
  */
 public function restart()
 {
     $this->permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     // Delete the individual table files.
     $Imp = new ImportModel();
     try {
         $Imp->loadState();
         $Imp->deleteFiles();
     } catch (Exception $Ex) {
     }
     $Imp->deleteState();
     redirect(strtolower($this->Application) . '/import');
 }
示例#4
0
 public function Restart()
 {
     $this->Permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     // Delete the individual table files.
     $Imp = new ImportModel();
     $Imp->LoadState();
     $Imp->DeleteFiles();
     $Imp->DeleteState();
     Redirect(strtolower($this->Application) . '/import');
 }
示例#5
0
 /**
  * Restart the import process. Undo any work we've done so far and erase state.
  *
  * @since 2.0.0
  * @access public
  */
 public function restart($transientKey = '')
 {
     $this->permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     if (!Gdn::session()->validateTransientKey($transientKey) && !Gdn::request()->isAuthenticatedPostBack()) {
         throw new Gdn_UserException('The CSRF token is invalid.', 403);
     }
     // Delete the individual table files.
     $Imp = new ImportModel();
     try {
         $Imp->loadState();
         $Imp->deleteFiles();
     } catch (Exception $Ex) {
     }
     $Imp->deleteState();
     redirect(strtolower($this->Application) . '/import');
 }
 /**
  * Restart the import process. Undo any work we've done so far and erase state.
  *
  * @since 2.0.0
  * @access public
  */
 public function restart()
 {
     $this->permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     if (!Gdn::request()->isAuthenticatedPostBack(true)) {
         throw new Exception('Requires POST', 405);
     }
     // Delete the individual table files.
     $Imp = new ImportModel();
     try {
         $Imp->loadState();
         $Imp->deleteFiles();
     } catch (Exception $Ex) {
     }
     $Imp->deleteState();
     redirect(strtolower($this->Application) . '/import');
 }