Esempio n. 1
0
         // Gets new DB object to prevent connection time out.
         fwrite(STDERR, $job->id . ': ' . $e->getMessage() . "\n");
         $job->error($e->getMessage())->finish()->save();
     }
     break;
 case OpenSKOS_Db_Table_Row_Job::JOB_TASK_DELETE_CONCEPT_SCHEME:
     $job->start()->save();
     try {
         $response = Api_Models_Concepts::factory()->getConcepts('uuid:' . $job->getParam('uuid'));
         if (!isset($response['response']['docs']) || 1 !== count($response['response']['docs'])) {
             throw new Zend_Exception('The requested concept scheme was not found');
         }
         $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept(array_shift($response['response']['docs'])));
         $conceptScheme->delete(true, $job['user']);
         // Clears the schemes cache after the scheme is removed.
         OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY);
         $model = new OpenSKOS_Db_Table_Jobs();
         // Gets new DB object to prevent connection time out.
         $job = $model->find($job->id)->current();
         // Gets new DB object to prevent connection time out.
         $job->finish()->save();
     } catch (Zend_Exception $e) {
         $model = new OpenSKOS_Db_Table_Jobs();
         // Gets new DB object to prevent connection time out.
         $job = $model->find($job->id)->current();
         // Gets new DB object to prevent connection time out.
         fwrite(STDERR, $job->id . ': ' . $e->getMessage() . "\n");
         $job->error($e->getMessage())->finish()->save();
     }
     break;
 default:
 /**
  * Assign icon to a scheme.
  * 
  */
 public function assignIconAction()
 {
     $this->_requireAccess('editor.concept-schemes', 'manage-icons', self::RESPONSE_TYPE_JSON);
     $schemeUuid = $this->getRequest()->getParam('schemeUuid');
     $iconToAssign = $this->getRequest()->getParam('iconFile');
     $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor');
     if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['uploadPath'])) {
         $iconsUploadPath = APPLICATION_PATH . $editorOptions['schemeIcons']['uploadPath'] . '/' . $this->_tenant->code;
     } else {
         $iconsUploadPath = APPLICATION_PATH . Editor_Forms_UploadIcon::DEFAULT_UPLOAD_PATH . '/' . $this->_tenant->code;
     }
     if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['assignPath'])) {
         $iconsAssignPath = APPLICATION_PATH . $editorOptions['schemeIcons']['assignPath'] . '/' . $this->_tenant->code;
     } else {
         $iconsAssignPath = APPLICATION_PATH . Editor_Forms_UploadIcon::DEFAULT_ASSIGN_PATH . '/' . $this->_tenant->code;
     }
     if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['extension'])) {
         $iconsExtension = $editorOptions['schemeIcons']['extension'];
     } else {
         $iconsExtension = 'png';
     }
     copy($iconsUploadPath . '/' . $iconToAssign, $iconsAssignPath . '/' . $schemeUuid . '.' . $iconsExtension);
     // Clears the schemes cache after a scheme icon is changed.
     OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY);
     $this->getHelper('json')->sendJson(array('status' => 'ok', 'result' => array('newIconPath' => Editor_Models_ConceptScheme::buildIconPath($schemeUuid))));
 }
Esempio n. 3
0
 /**
  * Get all ConceptScheme documents for the current tenant.
  * The result is once cached in Zend_Registry and retrieved from there when search again.
  *  
  * @param string $uri, optional If specified - selects the specified concept scheme
  * @param string $tenant, optional If specified concept schemes for this tenant will be returned. If not - concept schemes for current tenant.
  * @return array An array of concept scheme documents data, or the single concept scheme data if uri is specified.
  */
 public function getConceptSchemes($uri = null, $tenant = null, $inCollections = array())
 {
     if (null === $tenant) {
         $tenant = $this->_getCurrentTenant()->code;
     }
     if (null === $inCollections) {
         $inCollections = array();
     }
     $conceptSchemes = OpenSKOS_Cache::getCache()->load(self::CONCEPT_SCHEMES_CACHE_KEY);
     if ($conceptSchemes === false) {
         $conceptSchemes = array();
     }
     $schemesCacheKey = $tenant . implode('', $inCollections);
     if (!isset($conceptSchemes[$schemesCacheKey])) {
         $query = 'class:ConceptScheme tenant:' . $tenant;
         if (!empty($inCollections)) {
             if (count($inCollections) == 1) {
                 $query .= sprintf(' collection:%s', $inCollections[0]);
             } else {
                 $query .= sprintf(' collection:(%s)', implode(' OR ', $inCollections));
             }
         }
         $response = Api_Models_Concepts::factory()->setQueryParams(array('rows' => self::DEFAULT_MAX_ROWS_LIMIT))->getConcepts($query);
         $response = $response['response'];
         $conceptSchemes[$schemesCacheKey] = array();
         if ($response['numFound'] > 0) {
             foreach ($response['docs'] as $doc) {
                 $doc['iconPath'] = Editor_Models_ConceptScheme::buildIconPath($doc['uuid'], $this->_tenant);
                 $conceptSchemes[$schemesCacheKey][] = $doc;
             }
         }
         usort($conceptSchemes[$schemesCacheKey], array('Editor_Models_ConceptScheme', 'compareDocs'));
         OpenSKOS_Cache::getCache()->save($conceptSchemes, self::CONCEPT_SCHEMES_CACHE_KEY);
     }
     if (null !== $uri) {
         if (!is_array($uri)) {
             $uri = array($uri);
         }
         $schemes = array();
         foreach ($conceptSchemes[$schemesCacheKey] as $schemeLine) {
             if (isset($schemeLine['uri']) && in_array($schemeLine['uri'], $uri)) {
                 $schemes[$schemeLine['uri']] = $schemeLine;
             }
         }
         return $schemes;
     }
     return $conceptSchemes[$schemesCacheKey];
 }