コード例 #1
0
ファイル: Export.php プロジェクト: rubensworks/OpenSKOS
 /**
  * Creates an openskos background job to export with the given settings to a file.
  * 
  * @return int The job id
  */
 public function exportWithBackgroundJob()
 {
     $user = OpenSKOS_Db_Table_Users::requireById($this->get('userId'));
     $tenant = OpenSKOS_Db_Table_Tenants::fromCode($user->tenant);
     $tenantCollections = $tenant->findDependentRowset('OpenSKOS_Db_Table_Collections');
     if (!$tenantCollections->count()) {
         throw new Zend_Exception('Current tenant does not have any collections. At least one is required.', 404);
     }
     // We use the first collection of the tenant for the export job,
     // because the collection is important for the jobs, but the export is not related to any specific collection.
     $firstTenantCollection = $tenantCollections->current();
     $model = new OpenSKOS_Db_Table_Jobs();
     $job = $model->fetchNew()->setFromArray(array('collection' => $firstTenantCollection->id, 'user' => $user->id, 'task' => OpenSKOS_Db_Table_Row_Job::JOB_TASK_EXPORT, 'parameters' => serialize($this->getSettings()), 'created' => new Zend_Db_Expr('NOW()')))->save();
     return $job;
 }
コード例 #2
0
 /**
  * Fully remove the concept scheme.
  * 
  */
 public function deleteAction()
 {
     $this->_requireAccess('editor.concept-schemes', 'delete', self::RESPONSE_TYPE_HTML);
     $user = $this->getCurrentUser();
     $conceptScheme = $this->_getConceptScheme();
     $getConceptSchemesWithDeleteJob = $this->_getConceptSchemesWithDeleteJob();
     if (!isset($getConceptSchemesWithDeleteJob[$conceptScheme['uuid']])) {
         $model = new OpenSKOS_Db_Table_Jobs();
         $job = $model->fetchNew()->setFromArray(array('collection' => $conceptScheme['collection'], 'user' => $user->id, 'task' => OpenSKOS_Db_Table_Row_Job::JOB_TASK_DELETE_CONCEPT_SCHEME, 'parameters' => serialize(array('uuid' => $conceptScheme['uuid'])), 'created' => new Zend_Db_Expr('NOW()')))->save();
         $this->getHelper('FlashMessenger')->addMessage(_('A job for deleting the concept scheme was added.'));
     } else {
         $this->getHelper('FlashMessenger')->addMessage(_('A job for deleting the concept scheme already exists.'));
     }
     $this->_helper->redirector('index');
 }
コード例 #3
0
 public function importAction()
 {
     $this->_requireAccess('editor.collections', 'manage');
     $collection = $this->_getCollection();
     if ($collection->OAI_baseURL) {
         $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Since this collection has an OAI Server as source, you can not upload files for import.'));
         $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
         return;
     }
     $form = $collection->getUploadForm();
     $formData = $this->_request->getPost();
     if ($form->isValid($formData)) {
         $upload = new Zend_File_Transfer_Adapter_Http();
         $path = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('upload_path');
         $tenant_path = $path . '/' . $collection->tenant;
         if (!is_dir($tenant_path)) {
             if (!@mkdir($tenant_path, 0777, true)) {
                 $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Failed to create upload folder'));
                 $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
                 return;
             }
         }
         try {
             $fileName = uniqid() . '_' . $_FILES['xml']['name'];
             $upload->addFilter('Rename', array('target' => $tenant_path . '/' . $fileName, 'overwrite' => false))->receive();
         } catch (Zend_File_Transfer_Exception $e) {
             $form->getElement('xml')->setErrors(array($e->getMessage()));
             return $this->_forward('edit');
         } catch (Zend_Filter_Exception $e) {
             $form->getElement('xml')->setErrors(array(_('A file with that name is already scheduled for import. Please delete the job if you want to import it again.')));
             return $this->_forward('edit');
         }
         $model = new OpenSKOS_Db_Table_Jobs();
         $fileinfo = $upload->getFileInfo('xml');
         $parameters = array('name' => $fileName, 'type' => $fileinfo['xml']['type'], 'size' => $fileinfo['xml']['size'], 'destination' => $fileinfo['xml']['destination'], 'deletebeforeimport' => (int) $formData['deletebeforeimport'] == 1, 'status' => $formData['status'], 'ignoreIncomingStatus' => (int) $formData['ignoreIncomingStatus'] == 1, 'lang' => $formData['lang'], 'toBeChecked' => (int) $formData['toBeChecked'] == 1, 'purge' => (int) $formData['purge'] == 1, 'onlyNewConcepts' => (int) $formData['onlyNewConcepts'] == 1, 'useUriAsIdentifier' => (int) $formData['useUriAsIdentifier'] == 1);
         $job = $model->fetchNew()->setFromArray(array('collection' => $collection->id, 'user' => Zend_Auth::getInstance()->getIdentity()->id, 'task' => OpenSKOS_Db_Table_Row_Job::JOB_TASK_IMPORT, 'parameters' => serialize($parameters), 'created' => new Zend_Db_Expr('NOW()')))->save();
     } else {
         return $this->_forward('edit');
     }
     $this->getHelper('FlashMessenger')->addMessage(_('An import job is scheduled'));
     $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
 }