Skip to content

Commit

Permalink
Don't initialize tagger in constructor.
Browse files Browse the repository at this point in the history
This break down migration if content is migrated down first.
  • Loading branch information
yunosh committed Feb 24, 2014
1 parent 39a63c1 commit 1cb0bc4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 26 deletions.
8 changes: 1 addition & 7 deletions ansel/migration/4_ansel_upgrade_tagstocontent.php
Expand Up @@ -14,11 +14,8 @@
*/
class AnselUpgradeTagsToContent extends Horde_Db_Migration_Base
{

public function __construct(Horde_Db_Adapter $connection, $version = null)
public function up()
{
parent::__construct($connection, $version);

$GLOBALS['injector']->getInstance('Horde_Autoloader')->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Content_/', $GLOBALS['registry']->get('fileroot', 'content') . '/lib/'));
if (!class_exists('Content_Tagger')) {
throw new Ansel_Exception('The Content_Tagger class could not be found. Make sure the Content application is installed.');
Expand All @@ -30,10 +27,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)
'image' => (int)$types[1]);
$this->_tagger = $GLOBALS['injector']->getInstance('Content_Tagger');
$this->_shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create('ansel');
}

public function up()
{
if (strtolower($this->adapterName()) == 'pdo_sqlite') {
$this->announce('Migrating Ansel 1.x tags to Sqlite is not supported. Your existing tag data will not be removed, but will be unavailable from within Ansel.');
return;
Expand Down
8 changes: 1 addition & 7 deletions ansel/migration/5_ansel_upgrade_categoriestotags.php
Expand Up @@ -14,11 +14,8 @@
*/
class AnselUpgradeCategoriesToTags extends Horde_Db_Migration_Base
{

public function __construct(Horde_Db_Adapter $connection, $version = null)
public function up()
{
parent::__construct($connection, $version);

$GLOBALS['injector']->getInstance('Horde_Autoloader')->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Content_/', $GLOBALS['registry']->get('fileroot', 'content') . '/lib/'));
if (!class_exists('Content_Tagger')) {
throw new Horde_Exception('The Content_Tagger class could not be found. Make sure the Content application is installed.');
Expand All @@ -30,10 +27,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)
'image' => (int)$types[1]);
$this->_tagger = $GLOBALS['injector']->getInstance('Content_Tagger');
$this->_shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create('ansel');
}

public function up()
{
/* Gallery tags */
$t = $this->_connection->table('ansel_shares');
$cols = $t->getColumns();
Expand Down
6 changes: 3 additions & 3 deletions kronolith/migration/18_kronolith_upgrade_categoriestotags.php
Expand Up @@ -15,10 +15,8 @@
*/
class KronolithUpgradeCategoriesToTags extends Horde_Db_Migration_Base
{
public function __construct(Horde_Db_Adapter $connection, $version = null)
protected function _init()
{
parent::__construct($connection, $version);

// Can't use Kronolith's tagger since we can't init kronolith.
$GLOBALS['injector']->getInstance('Horde_Autoloader')->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Content_/', $GLOBALS['registry']->get('fileroot', 'content') . '/lib/'));
if (!class_exists('Content_Tagger')) {
Expand All @@ -33,6 +31,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)

public function up()
{
$this->_init();
$sql = 'SELECT event_uid, event_category, event_creator_id, calendar_id FROM kronolith_events';
$this->announce('Migrating event categories to tags.');
$rows = $this->select($sql);
Expand Down Expand Up @@ -63,6 +62,7 @@ public function up()

public function down()
{
$this->_init();
$this->addColumn('kronolith_events', 'event_category', 'string', array('limit' => 80));
$this->announce('Migrating event tags to categories.');
$sql = 'UPDATE kronolith_events SET event_category = ? WHERE event_uid = ?';
Expand Down
6 changes: 3 additions & 3 deletions mnemo/migration/6_mnemo_upgrade_categoriestotags.php
Expand Up @@ -15,10 +15,8 @@
*/
class MnemoUpgradeCategoriesToTags extends Horde_Db_Migration_Base
{
public function __construct(Horde_Db_Adapter $connection, $version = null)
protected function _init()
{
parent::__construct($connection, $version);

// Can't use Mnemo's tagger since we can't init Mnemo.
$GLOBALS['injector']->getInstance('Horde_Autoloader')
->addClassPathMapper(
Expand All @@ -44,6 +42,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)

public function up()
{
$this->_init();
if ($this->_shares) {
$sql = 'SELECT memo_uid, memo_category, memo_owner FROM mnemo_memos';
$this->announce('Migrating note categories to tags.');
Expand All @@ -68,6 +67,7 @@ public function up()

public function down()
{
$this->_init();
$this->addColumn('mnemo_memos', 'memo_category', 'string', array('limit' => 80));
$this->announce('Migrating note tags to categories.');
$sql = 'UPDATE mnemo_memos SET memo_category = ? WHERE memo_uid = ?';
Expand Down
6 changes: 3 additions & 3 deletions nag/migration/10_nag_upgrade_categoriestotags.php
Expand Up @@ -14,10 +14,8 @@
*/
class NagUpgradeCategoriesToTags extends Horde_Db_Migration_Base
{
public function __construct(Horde_Db_Adapter $connection, $version = null)
protected function _init()
{
parent::__construct($connection, $version);

// Can't use Nag's tagger since we can't init Nag.
$GLOBALS['injector']->getInstance('Horde_Autoloader')
->addClassPathMapper(
Expand All @@ -43,6 +41,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)

public function up()
{
$this->_init();
$sql = 'SELECT task_uid, task_category, task_creator, task_owner FROM nag_tasks';
$this->announce('Migrating task categories to tags.');
$rows = $this->select($sql);
Expand Down Expand Up @@ -77,6 +76,7 @@ public function up()

public function down()
{
$this->_init();
$this->addColumn('nag_tasks', 'task_category', 'string', array('limit' => 80));
$this->announce('Migrating task tags to categories.');
$sql = 'UPDATE nag_tasks SET task_category = ? WHERE task_uid = ?';
Expand Down
6 changes: 3 additions & 3 deletions turba/migration/10_turba_upgrade_categoriestotags.php
Expand Up @@ -25,10 +25,8 @@ class TurbaUpgradeCategoriesToTags extends Horde_Db_Migration_Base
{
protected $_shares = null;

public function __construct(Horde_Db_Adapter $connection, $version = null)
protected function _init()
{
parent::__construct($connection, $version);

// Skip if run during unit tests when we don't need to migrate data.
if (getenv('HORDE_UNIT_TEST')) {
return;
Expand Down Expand Up @@ -61,6 +59,7 @@ public function __construct(Horde_Db_Adapter $connection, $version = null)

public function up()
{
$this->_init();
if ($this->_shares) {
$sql = 'SELECT object_uid, object_category, owner_id FROM turba_objects';
$this->announce('Migrating contact categories to tags.');
Expand Down Expand Up @@ -89,6 +88,7 @@ public function up()

public function down()
{
$this->_init();
$this->addColumn('turba_objects', 'object_category', 'string', array('limit' => 80));
$this->announce('Migrating contact tags to categories.');
$sql = 'UPDATE turba_objects SET object_category = ? WHERE object_uid = ?';
Expand Down

0 comments on commit 1cb0bc4

Please sign in to comment.