protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
     $criteria = new Criteria();
     $criteria->add(QubitSlug::SLUG, $arguments['slug']);
     $criteria->addJoin(QubitSlug::OBJECT_ID, QubitObject::ID);
     $resource = QubitInformationObject::get($criteria)->__get(0);
     $publicationStatus = QubitTerm::getById($arguments['publicationStatusId']);
     // Check if the resource exists
     if (!isset($resource)) {
         throw new sfException('Resource not found');
     }
     // Check if the given status is correct and exists
     if (!isset($publicationStatus)) {
         throw new sfException('Publication status not found');
     }
     if (QubitTaxonomy::PUBLICATION_STATUS_ID != $publicationStatus->taxonomyId) {
         throw new sfException('Given term is not part of the publication status taxonomy');
     }
     // Final confirmation
     if (!$options['no-confirm']) {
         if (!$this->askConfirmation(array('Please, confirm that you want to change', 'the publication status of "' . $resource . '"', 'to "' . $publicationStatus . '" (y/N)'), 'QUESTION_LARGE', false)) {
             $this->logSection('tools', 'Bye!');
             return 1;
         }
     }
     // Start work
     $resource->setPublicationStatus($publicationStatus->id);
     $resource->save();
     echo '+';
     // Update pub status of descendants
     if (!$options['ignore-descendants']) {
         foreach ($resource->descendants as $descendant) {
             if (null === ($descendantPubStatus = $descendant->getPublicationStatus())) {
                 $descendantPubStatus = new QubitStatus();
                 $descendantPubStatus->typeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
                 $descendantPubStatus->objectId = $descendant->id;
             }
             if ($options['force'] || $publicationStatus->id != $descendantPubStatus->statusId) {
                 $descendantPubStatus->statusId = $publicationStatus->id;
                 $descendantPubStatus->save();
                 echo '^';
             }
         }
     }
     echo "\n";
 }
 public function getStatus($options = array())
 {
     $criteria = new Criteria();
     $criteria->add(QubitStatus::OBJECT_ID, $this->id);
     $criteria->add(QubitStatus::TYPE_ID, $options['typeId']);
     return QubitStatus::getOne($criteria);
 }
 protected function updateStatus()
 {
     if (!QubitAcl::check($this->resource, 'publish')) {
         // if the user does not have 'publish' permission, use default publication
         // status setting
         $pubStatusId = sfConfig::get('app_defaultPubStatus', QubitTerm::PUBLICATION_STATUS_DRAFT_ID);
     } else {
         $pubStatusId = $this->form->getValue('publicationStatus');
     }
     // Only update publicationStatus if its value has changed because it
     // triggers a resource-intensive update of all its descendants
     $oldStatus = $this->resource->getStatus(array('typeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID));
     if (!isset($oldStatus) && isset($pubStatusId) || $pubStatusId !== $oldStatus->statusId) {
         $this->resource->setPublicationStatus($pubStatusId);
         // Set pub status for child levels
         foreach ($this->resource->informationObjectsRelatedByparentId as $child) {
             $child->setPublicationStatus($pubStatusId);
         }
         // Update pub status of descendants
         foreach ($this->resource->descendants as $descendant) {
             if (null === ($descendantPubStatus = $descendant->getStatus(array('typeId' => QubitTerm::STATUS_TYPE_PUBLICATION_ID)))) {
                 $descendantPubStatus = new QubitStatus();
                 $descendantPubStatus->typeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
                 $descendantPubStatus->objectId = $descendant->id;
             }
             if ($pubStatusId != $descendantPubStatus->statusId) {
                 $descendantPubStatus->statusId = $pubStatusId;
                 $descendantPubStatus->save();
             }
         }
     }
 }
Beispiel #4
0
 public static function getstatussRelatedBystatusIdById($id, array $options = array())
 {
     $criteria = new Criteria();
     self::addstatussRelatedBystatusIdCriteriaById($criteria, $id);
     return QubitStatus::get($criteria, $options);
 }