Author: david
Date: Thu Jul 26 14:05:43 2012
New Revision: 11986
Log:
Regenerate derivatives
Modified:
trunk/lib/task/digitalObjectRegenDerivativesTask.class.php
Modified: trunk/lib/task/digitalObjectRegenDerivativesTask.class.php
==============================================================================
--- trunk/lib/task/digitalObjectRegenDerivativesTask.class.php Thu Jul 26
14:04:49 2012 (r11985)
+++ trunk/lib/task/digitalObjectRegenDerivativesTask.class.php Thu Jul 26
14:05:43 2012 (r11986)
@@ -21,19 +21,16 @@
{
protected function configure()
{
- $this->addArguments(array(
- new sfCommandArgument('publicationStatusId',
sfCommandArgument::REQUIRED, 'Desired publication status identifier'),
- new sfCommandArgument('slug', sfCommandArgument::REQUIRED, 'Resource
slug')
- ));
+ //$this->addArguments(array());
$this->addOptions(array(
new sfCommandOption('application', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'cli'),
new sfCommandOption('connection', null,
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
- new sfCommandOption('force', 'f', sfCommandOption::PARAMETER_NONE,
'Force update of descendants', null),
- new sfCommandOption('ignore-descendants', 'i',
sfCommandOption::PARAMETER_NONE, 'Don\'t update descendants', null),
- new sfCommandOption('no-confirm', 'y', sfCommandOption::PARAMETER_NONE,
'No confirmation message', null),
- new sfCommandOption('repo', 'r', sfCommandOption::PARAMETER_NONE,
'Update all description in given repository', null)
+ new sfCommandOption('slug', 'l', sfCommandOption::PARAMETER_OPTIONAL,
'Information object slug', null),
+ //new sfCommandOption('repo', 'r', sfCommandOption::PARAMETER_NONE,
'Update all description in given repository', null)
+ new sfCommandOption('index', null, sfCommandOption::PARAMETER_NONE,
'Update search index (defaults to false)', null),
+ new sfCommandOption('force', 'f', sfCommandOption::PARAMETER_NONE, 'No
confirmation message', null)
));
$this->namespace = 'digitalobject';
@@ -46,100 +43,99 @@
protected function execute($arguments = array(), $options = array())
{
+ sfContext::createInstance($this->configuration);
$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);
-
- if (!$options['repo'])
+ if (isset($options['index']))
{
- $resource = QubitInformationObject::get($criteria)->__get(0);
+ QubitSearch::getInstance()->disabled = false;
+ QubitSearch::getInstance()->enableBatch(); // Batched update is faster
}
else
{
- $resource = QubitRepository::get($criteria)->__get(0);
+ QubitSearch::getInstance()->disabled = true;
}
- $publicationStatus = QubitTerm::getById($arguments['publicationStatusId']);
-
+ // Get all master digital objects
+ $query = 'SELECT do.id
+ FROM digital_object do JOIN information_object io ON
do.information_object_id = io.id';
- // Check if the resource exists
- if (!isset($resource))
+ // Limit to a branch
+ if ($options['slug'])
{
- throw new sfException('Resource not found');
- }
+ $q2 = 'SELECT io.id, io.lft, io.rgt
+ FROM information_object io JOIN slug ON io.id = slug.object_id
+ WHERE slug.slug = ?';
- // 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');
+ $row = QubitPdo::fetchOne($q2, array($options['slug']));
+
+ if (false === $row)
+ {
+ throw new sfException("Invalid slug");
+ }
+
+ $query .= ' WHERE io.lft >= '.$row->lft.' and io.rgt <= '.$row->rgt;
}
// Final confirmation
- if (!$options['no-confirm'])
+ if (!isset($options['force']))
{
- if (!$this->askConfirmation(array(
- 'Please, confirm that you want to change',
- 'the publication status of "' . $resource->__toString() . '"',
- 'to "' . $publicationStatus . '" (y/N)'), 'QUESTION_LARGE', false))
- {
- $this->logSection('tools', 'Bye!');
+ $confirm = array();
+ $confirm[] = 'Continuing will regenerate the dervivatives for ALL
digital objects';
+
+ if ($options['slug'])
+ {
+ $confirm[] = 'within the '.$options['slug'].' branch';
+ }
+
+ $confirm[] = 'This will PERMANENTLY DELETE any existing derivatives';
+ $confirm[] = '';
+ $confirm[] = 'Continue? (y/N)';
+
+ if (!$this->askConfirmation($confirm, 'QUESTION_LARGE', false))
+ {
+ $this->logSection('digital object', 'Bye!');
- return 1;
- }
+ return 1;
+ }
}
// Do work
- if (!$options['repo'])
- {
- self::updatePublicationStatus($resource, $publicationStatus, $options);
- }
- else
+ foreach (QubitPdo::fetchAll($query) as $item)
{
- $criteria = new Criteria;
- $criteria->add(QubitInformationObject::REPOSITORY_ID, $resource->id);
+ $do = QubitDigitalObject::getById($item->id);
- foreach(QubitInformationObject::get($criteria) as $item)
+ if (null == $do)
{
- self::updatePublicationStatus($item, $publicationStatus, $options);
+ continue;
}
- }
- echo "\n";
- }
+ $this->logSection('digital object', 'Regenerating derivatives for
'.$do->name.'...');
- protected static function updatePublicationStatus($resource,
$publicationStatus, $options)
- {
- // 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 '^';
- }
+ // Delete existing derivatives
+ foreach ($do->descendants as $derivative)
+ {
+ $derivative->delete();
}
+
+ $do->createRepresentations(QubitTerm::MASTER_ID, $conn);
+
+ if (isset($options['index']))
+ {
+ // Update index
+ QubitSearch::updateInformationObject($do->informationObject);
+ }
+
+ // Destroy out-of-scope objects
+ QubitDigitalObject::clearCache();
+ QubitInformationObject::clearCache();
+ }
+
+ // Warn user to manually update search index
+ if (!isset($options['index']))
+ {
+ $this->logSection('Done!', 'Please update the search index manually with
"php symfony search:populate QubitSearch" to reflect any changes.');
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.