Skip to content

Instantly share code, notes, and snippets.

@sevein
Created June 7, 2012 22:15
Show Gist options
  • Save sevein/2891971 to your computer and use it in GitHub Desktop.
Save sevein/2891971 to your computer and use it in GitHub Desktop.
Qubit - Issue 2344
<?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/>.
*/
/**
* Fix for issue 2344.
* Locate this file in the lib/task directory.
* Then run: $ php symfony tools:fix-issue-2344
*/
class FixIssue2344Task extends sfBaseTask
{
protected function configure()
{
$this->namespace = 'tools';
$this->name = 'fix-issue-2344';
$this->briefDescription = 'Fix issue 2344.';
$this->detailedDescription = <<<EOF
Fix issue 2344.
EOF;
}
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$conn = $databaseManager->getDatabase('propel')->getConnection();
$termIds = array(QubitTerm::ACCESSION_ID, QubitTerm::RIGHT_ID);
$criteria = new Criteria;
$criteria->add(QubitTerm::ID, $termIds, Criteria::IN);
if (count($termIds) <= count(QubitTerm::get($criteria)))
{
throw new Exception('You don\'t need this fix, thank you!');
}
// Add "Accession" relation type
$term = new QubitTerm;
$term->id = QubitTerm::ACCESSION_ID;
$term->parentId = QubitTerm::ROOT_ID;
$term->taxonomyId = QubitTaxonomy::RELATION_TYPE_ID;
$term->sourceCulture = 'en';
$term->name = 'Accession';
try
{
$term->save();
$this->logSection('fix-issue-2344', 'Accession relation type added.');
}
catch (Exception $e)
{
throw new Exception("The \"Right\" relation type could not be added.\n\n".$e->getMessage());
}
// Add "Right" relation type
$term = new QubitTerm;
$term->id = QubitTerm::RIGHT_ID;
$term->parentId = QubitTerm::ROOT_ID;
$term->taxonomyId = QubitTaxonomy::RELATION_TYPE_ID;
$term->sourceCulture = 'en';
$term->name = 'Right';
try
{
$term->save();
$this->logSection('fix-issue-2344', 'Right relation type added.');
}
catch (Exception $e)
{
throw new Exception("The \"Right\" relation type could not be added.\n\n".$e->getMessage());
}
// Set "Donor" relation type parent_id to QubitTerm::ROOT_ID
$term = QubitTerm::getById(QubitTerm::DONOR_ID);
$term->parentId = QubitTerm::ROOT_ID;
try
{
$term->save();
$this->logSection('fix-issue-2344', 'Donor relation type updated.');
}
catch (Exception $e)
{
throw new Exception("The \"Donor\" relation type could not be updated.\n\n".$e->getMessage());
}
}
}

Issue 2344

Some ICA-AtoM reported us that information objects being created from an accession are not linked back to its accession. This is only affecting a number of users as explained below.

http://code.google.com/p/qubit-toolkit/issues/detail?id=2344

The problem is in the migration class found in QubitMigrate110.class.php, where some new type of relations are intended to be added to the data set unsuccessfully:

  // New type of relations: accession and right
  $this->data['QubitTerm']['QubitTerm_accession'] = array(
    'id' => '<?php echo QubitTerm::ACCESSION_ID."\n" ?>',
    'name' => array('en' => 'Accession'),
    'source_culture' => 'en',
    'taxonomy_id' => '<?php echo QubitTaxonomy::RELATION_TYPE_ID."\n" ?>');
  $this->data['QubitTerm']['QubitTerm_accession'] = array(
    'id' => '<?php echo QubitTerm::RIGHT_ID."\n" ?>',
    'name' => array('en' => 'Right'),
    'source_culture' => 'en',
    'taxonomy_id' => '<?php echo QubitTaxonomy::RELATION_TYPE_ID."\n" ?>');
  $this->data['QubitTerm']['QubitTerm_accession'] = array(
    'id' => '<?php echo QubitTerm::DONOR_ID."\n" ?>',
    'name' => array('en' => 'Donor'),
    'source_culture' => 'en',
    'taxonomy_id' => '<?php echo QubitTaxonomy::RELATION_TYPE_ID."\n" ?>');

Notice that the array key is always the same: 'QubitTerm_accession'. Therefore, only the last item is being introduced in the database during the migration process (see propel:migrate task).

Actions

Already fixed in trunk so new users upgrading from older versions won't be affected anymore

But we need to:

  1. Make sure in the next migration script (1.3) that these two missing types of relation are added in case they can't be found.

  2. Create an extra fix that users can run in their 1.2 installations to add these two missing relation types, that we will use for hosting clients too.

  3. Update hosting clients.

  4. Share the fix on ica-atom-users.

Conclusions

The testing phase should also cover/try an ICA-AtoM upgraded from older versions. It's not the first time we find a bug here, like the database version update error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment