public function saveAction() { $concept = $this->_getConcept(); $form = Editor_Forms_Concept::getInstance(null === $concept); $formData = $this->getRequest()->getParams(); if (!$this->getRequest()->isPost()) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('No POST data recieved')); $this->_helper->redirector('edit'); } $this->_checkConceptTenantForEdit($concept); if (!$form->isValid($formData)) { return $this->_forward('edit'); } else { //@FIXME should upgrade multi hidden fields to allow easy submission (change name to template something) array_shift($formData['inScheme']); $form->populate($formData); if (null === $concept) { $this->_requireAccess('editor.concepts', 'propose', self::RESPONSE_TYPE_PARTIAL_HTML); $concept = new Editor_Models_Concept(new Api_Models_Concept()); } else { $this->_requireAccess('editor.concepts', 'edit', self::RESPONSE_TYPE_PARTIAL_HTML); } $formData = $form->getValues(); $oldData = $concept->getData(); //by reference. $extraData = $concept->transformFormData($formData); $concept->setConceptData($formData, $extraData); try { $user = OpenSKOS_Db_Table_Users::fromIdentity(); $extraData = array_merge($extraData, array('tenant' => $user->tenant, 'modified_by' => (int) $user->id, 'modified_timestamp' => date("Y-m-d\\TH:i:s\\Z"), 'toBeChecked' => isset($extraData['toBeChecked']) ? (bool) $extraData['toBeChecked'] : false)); if (!isset($extraData['uuid']) || empty($extraData['uuid'])) { $extraData['uuid'] = $concept['uuid']; $extraData['created_by'] = $extraData['modified_by']; $extraData['created_timestamp'] = $extraData['modified_timestamp']; } else { if (isset($oldData['created_by'])) { $extraData['created_by'] = $oldData['created_by']; } if (isset($oldData['created_timestamp'])) { $extraData['created_timestamp'] = $oldData['created_timestamp']; } if (isset($oldData['collection'])) { $extraData['collection'] = $oldData['collection']; } if (isset($oldData['approved_by'])) { $extraData['approved_by'] = $oldData['approved_by']; } if (isset($oldData['approved_timestamp'])) { $extraData['approved_timestamp'] = $oldData['approved_timestamp']; } if (isset($oldData['deleted_by'])) { $extraData['deleted_by'] = $oldData['deleted_by']; } if (isset($oldData['deleted_timestamp'])) { $extraData['deleted_timestamp'] = $oldData['deleted_timestamp']; } } if ($extraData['status'] === 'approved' && $oldData['status'] !== 'approved') { $extraData['approved_timestamp'] = $extraData['modified_timestamp']; $extraData['approved_by'] = $extraData['modified_by']; } if ($extraData['status'] !== 'approved') { $formData['approved_by'] = ''; $formData['approved_timestamp'] = ''; $extraData['approved_by'] = ''; $extraData['approved_timestamp'] = ''; } if ($extraData['status'] !== 'expired') { $formData['deleted_by'] = ''; $formData['deleted_timestamp'] = ''; $extraData['deleted_by'] = ''; $extraData['deleted_timestamp'] = ''; } if (!isset($extraData['collection'])) { if (isset($concept['inScheme']) && isset($concept['inScheme'][0])) { $firstConceptScheme = Editor_Models_ApiClient::factory()->getConceptSchemes($concept['inScheme'][0]); $firstConceptScheme = array_shift($firstConceptScheme); if (!empty($firstConceptScheme) && isset($firstConceptScheme['collection'])) { $extraData['collection'] = $firstConceptScheme['collection']; } } } $concept->setConceptData($formData, $extraData); if ($concept->save($extraData)) { if (!isset($concept['inScheme'])) { $newSchemes = array(); } else { $newSchemes = $concept['inScheme']; } if (!isset($oldData['inScheme'])) { $oldSchemes = array(); } else { $oldSchemes = $oldData['inScheme']; } $concept->updateConceptSchemes($newSchemes, $oldSchemes); } else { return $this->_forward('edit', 'concept', 'editor', array('errors' => $concept->getErrors())); } } catch (Zend_Exception $e) { return $this->_forward('edit', 'concept', 'editor', array('errors' => array(new Editor_Models_ConceptValidator_Error('unknown', $e->getMessage())))); } $this->_helper->redirector('view', 'concept', 'editor', array('uuid' => $extraData['uuid'])); } }
/** * Delete a concept scheme from everywhere. * * @param bool $commit, optional, Default: true * @param bool $deletedBy, optional */ public function delete($commit = true, $deletedBy = null) { if (null === $deletedBy) { $actionUser = OpenSKOS_Db_Table_Users::fromIdentity(); if (null !== $actionUser) { $deletedBy = $actionUser->id; } } $affectedConceptsQuery = '(inScheme:"' . $this['uri'] . '" OR topConceptOf:"' . $this['uri'] . '") AND tenant:' . $this['tenant']; // Update affected concepts by steps. $rows = 1000; do { // Get concepts which has the scheme in topConceptOf or inScheme. $concepts = Editor_Models_ApiClient::factory()->getConceptsByQuery($affectedConceptsQuery, array('rows' => $rows)); if (count($concepts['data']) > 0) { // Remove the concept from topConceptOf or inScheme of each concept. Delete concept if it does not have other schemes in inScheme. foreach ($concepts['data'] as $key => $concept) { $concept = new Editor_Models_Concept($concept); $data = $concept->getData(); $updateData = array(); $updateExtraData = array(); if (isset($data['inScheme'])) { $updateData['inScheme'] = array_diff($data['inScheme'], array($this['uri'])); } if (isset($data['topConceptOf'])) { $updateData['topConceptOf'] = array_diff($data['topConceptOf'], array($this['uri'])); } if (empty($updateData['inScheme'])) { $updateExtraData['deleted'] = true; $updateExtraData['deleted_by'] = $deletedBy; } $concept->update($updateData, $updateExtraData, false, true); if ($key == count($concepts['data']) - 1 && $commit) { $this->solr()->commit(); } } } } while (count($concepts['data']) == $rows); // Update the concept scheme $updateExtraData['deleted'] = true; $updateExtraData['deleted_by'] = $deletedBy; $this->update(array(), $updateExtraData); // Commit if ($commit) { $this->solr()->commit(); } }