Author: sevein
Date: Tue Jan 3 15:08:38 2012
New Revision: 10545
Log:
Fix file name
Added:
trunk/lib/task/migrate/QubitMigrate111.class.php
- copied unchanged from r10544,
trunk/lib/task/migrate/QubitMigrate111.clas.php
Deleted:
trunk/lib/task/migrate/QubitMigrate111.clas.php
Copied: trunk/lib/task/migrate/QubitMigrate111.class.php (from r10544,
trunk/lib/task/migrate/QubitMigrate111.clas.php)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/lib/task/migrate/QubitMigrate111.class.php Tue Jan 3 15:08:38
2012 (r10545, copy of r10544,
trunk/lib/task/migrate/QubitMigrate111.clas.php)
@@ -0,0 +1,367 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Upgrade qubit version 1.2 data for version 1.3 schema
+ *
+ * @package qubit
+ * @subpackage migration
+ * @version svn: $Id: QubitMigrate110.class.php 10379 2011-12-08 21:26:13Z
david $
+ */
+class QubitMigrate111 extends QubitMigrate
+{
+ const
+ MILESTONE = '1.1',
+ INIT_VERSION = 75,
+ FINAL_VERSION = null;
+
+ public function execute()
+ {
+ $this->slugData();
+ $this->alterData();
+ $this->sortData();
+
+ return $this->getData();
+ }
+
+ /**
+ * Controller for calling methods to alter data
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function alterData()
+ {
+ switch ($this->version)
+ {
+ case 75:
+ $this->addJobSchedulingSettings();
+
+ case 76:
+ $this->addSwordSettings();
+ }
+
+ // Delete "stub" objects
+ $this->deleteStubObjects();
+
+ return $this;
+ }
+
+ /**
+ * Add job scheduling settings
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function addJobSchedulingSettings()
+ {
+ $this->data['QubitSetting']['QubitSetting_useJobScheduler'] = array(
+ 'name' => 'use_job_scheduler',
+ 'value' => array('en' => '0'),
+ 'source_culture' => 'en'
+ );
+
+ return $this;
+ }
+
+ /**
+ * Add SWORD settings
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function addSwordSettings()
+ {
+ $this->data['QubitSetting']['QubitSetting_swordDepositDir'] = array(
+ 'name' => 'sword_deposit_dir',
+ 'value' => array('en' => '/tmp'),
+ 'source_culture' => 'en'
+ );
+
+ return $this;
+ }
+
+ /**
+ * Slugs are inserted when some resources are inserted, but slugs are dumped
+ * separately when data is dumped. So loading slug data will try to insert
+ * duplicate slugs. To work around this, turn slugs into resource properties
+ * and drop slug data
+ */
+ protected function slugData()
+ {
+ if (!isset($this->data['QubitSlug']))
+ {
+ return $this;
+ }
+
+ $slug = array();
+ foreach ($this->data['QubitSlug'] as $item)
+ {
+ $slug[$item['object_id']] = $item['slug'];
+ }
+
+ unset($this->data['QubitSlug']);
+
+ foreach ($this->data as $table => $value)
+ {
+ foreach ($value as $row => $value)
+ {
+ if (isset ($slug[$row]))
+ {
+ $this->data[$table][$row]['slug'] = $slug[$row];
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Call all sort methods
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function sortData()
+ {
+ // Sort objects within classes
+ $this->sortQubitInformationObjects();
+ $this->sortQubitTerms();
+
+ // Sort classes
+ $this->sortClasses();
+
+ return $this;
+ }
+
+ /**
+ * Sort information objects by lft value so that parent objects are inserted
+ * before their children.
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function sortQubitInformationObjects()
+ {
+ QubitMigrate::sortByLft($this->data['QubitInformationObject']);
+
+ return $this;
+ }
+
+ /**
+ * Sort term objects with pre-defined IDs to start of array to prevent
+ * pre-emptive assignment by auto-increment
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function sortQubitTerms()
+ {
+ $qubitTermConstantIds = array(
+ 'ROOT_ID',
+ //EventType taxonomy
+ 'CREATION_ID',
+ 'CUSTODY_ID',
+ 'PUBLICATION_ID',
+ 'CONTRIBUTION_ID',
+ 'COLLECTION_ID',
+ 'ACCUMULATION_ID',
+ //NoteType taxonomy
+ 'TITLE_NOTE_ID',
+ 'PUBLICATION_NOTE_ID',
+ 'SOURCE_NOTE_ID',
+ 'SCOPE_NOTE_ID',
+ 'DISPLAY_NOTE_ID',
+ 'ARCHIVIST_NOTE_ID',
+ 'GENERAL_NOTE_ID',
+ 'OTHER_DESCRIPTIVE_DATA_ID',
+ 'MAINTENANCE_NOTE_ID',
+ //CollectionType taxonomy
+ 'ARCHIVAL_MATERIAL_ID',
+ 'PUBLISHED_MATERIAL_ID',
+ 'ARTEFACT_MATERIAL_ID',
+ //ActorEntityType taxonomy
+ 'CORPORATE_BODY_ID',
+ 'PERSON_ID',
+ 'FAMILY_ID',
+ //OtherNameType taxonomy
+ 'FAMILY_NAME_FIRST_NAME_ID',
+ //MediaType taxonomy
+ 'AUDIO_ID',
+ 'IMAGE_ID',
+ 'TEXT_ID',
+ 'VIDEO_ID',
+ 'OTHER_ID',
+ //Digital Object Usage taxonomy
+ 'MASTER_ID',
+ 'REFERENCE_ID',
+ 'THUMBNAIL_ID',
+ 'COMPOUND_ID',
+ //Physical Object Type taxonomy
+ 'LOCATION_ID',
+ 'CONTAINER_ID',
+ 'ARTEFACT_ID',
+ //Relation Type taxonomy
+ 'HAS_PHYSICAL_OBJECT_ID',
+ //Actor name type taxonomy
+ 'PARALLEL_FORM_OF_NAME_ID',
+ 'OTHER_FORM_OF_NAME_ID',
+ //Actor relation type taxonomy
+ 'HIERARCHICAL_RELATION_ID',
+ 'TEMPORAL_RELATION_ID',
+ 'FAMILY_RELATION_ID',
+ 'ASSOCIATIVE_RELATION_ID',
+ //Relation NOTE type taxonomy
+ 'RELATION_NOTE_DESCRIPTION_ID',
+ 'RELATION_NOTE_DATE_ID',
+ //Term relation taxonomy
+ 'ALTERNATIVE_LABEL_ID',
+ 'TERM_RELATION_ASSOCIATIVE_ID',
+ //Status types taxonomy
+ 'STATUS_TYPE_PUBLICATION_ID',
+ // Publication status taxonomy
+ 'PUBLICATION_STATUS_DRAFT_ID',
+ 'PUBLICATION_STATUS_PUBLISHED_ID',
+ // Name access point
+ 'NAME_ACCESS_POINT_ID',
+ // ISDF relation type taxonomy
+ 'ISDF_HIERARCHICAL_RELATION_ID',
+ 'ISDF_TEMPORAL_RELATION_ID',
+ 'ISDF_ASSOCIATIVE_RELATION_ID',
+ // ISAAR standardized form name
+ 'STANDARDIZED_FORM_OF_NAME_ID',
+ 'EXTERNAL_URI_ID',
+ // Relation types
+ 'ACCESSION_ID',
+ 'RIGHT_ID',
+ 'DONOR_ID',
+ // Rights basis
+ 'RIGHT_BASIS_COPYRIGHT_ID',
+ 'RIGHT_BASIS_LICENSE_ID',
+ 'RIGHT_BASIS_STATUTE_ID',
+ 'RIGHT_BASIS_POLICY_ID'
+ );
+
+ // Restack array with Constant values at top
+ $qubitTermArray = $this->data['QubitTerm'];
+ foreach ($qubitTermConstantIds as $key => $constantName)
+ {
+ foreach ($qubitTermArray as $key => $term)
+ {
+ if (isset($term['id']) && $term['id'] == '<?php echo
QubitTerm::'.$constantName.'."\n" ?>')
+ {
+ $newTermArray[$key] = $term;
+ unset($qubitTermArray[$key]);
+ break;
+ }
+ }
+ }
+
+ // Sort remainder of array by lft values
+ QubitMigrate::sortByLft($qubitTermArray);
+
+ // Append remaining (variable id) terms to the end of the new array
+ foreach ($qubitTermArray as $key => $term)
+ {
+ $newTermArray[$key] = $term;
+ }
+
+ $this->data['QubitTerm'] = $newTermArray;
+
+ return $this;
+ }
+
+ /**
+ * Sort ORM classes to avoid foreign key constraint failures on data load
+ *
+ * @return QubitMigrate111 this object
+ */
+ protected function sortClasses()
+ {
+ $ormSortOrder = array(
+ 'QubitTaxonomy',
+ 'QubitTerm',
+ 'QubitActor',
+ 'QubitRepository',
+ 'QubitInformationObject',
+ 'QubitDigitalObject',
+ 'QubitEvent',
+ 'QubitFunction',
+ 'QubitPhysicalObject',
+ 'QubitStaticPage',
+ 'QubitUser',
+ 'QubitObjectTermRelation',
+ 'QubitOtherName',
+ 'QubitRelation',
+ 'QubitAclGroup',
+ 'QubitAclUserGroup',
+ 'QubitAclPermission',
+ 'QubitContactInformation',
+ 'QubitMenu',
+ 'QubitNote',
+ 'QubitOaiRepository',
+ 'QubitOaiHarvest',
+ 'QubitProperty',
+ 'QubitSetting'
+ );
+
+ $originalData = $this->data;
+
+ foreach ($ormSortOrder as $i => $className)
+ {
+ if (isset($originalData[$className]))
+ {
+ $sortedData[$className] = $originalData[$className];
+ unset($originalData[$className]);
+ }
+ }
+
+ // If their are classes in the original data that are not listed in the
+ // ormSortOrder array then tack them on to the end of the sorted data
+ if (count($originalData))
+ {
+ foreach ($originalData as $className => $classData)
+ {
+ $sortedData[$className] = $classData;
+ }
+ }
+
+ $this->data = $sortedData;
+
+ return $this;
+ }
+
+ protected function getUniqueSlug($str)
+ {
+ $slug = $root = QubitSlug::slugify($str);
+
+ for ($i = 0; $i < 100; $i++)
+ {
+ foreach ($this->data['QubitRepository'] as $item)
+ {
+ if (isset($item['slug']) && $item['slug'] == $slug)
+ {
+ $slug = $root.'-'.($i + 1);
+
+ break;
+ }
+ }
+
+ // If $slug hasn't been incremented this pass
+ if ($slug == $root || $slug == $root.'-'.$i)
+ {
+ return $slug;
+ }
+ }
+ }
+}
--
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.