Convert to system tasks
authorMichael M Slusarz <slusarz@curecanti.org>
Sat, 25 Jul 2009 23:59:14 +0000 (17:59 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 25 Jul 2009 23:59:14 +0000 (17:59 -0600)
turba/lib/LoginTasks/SystemTask/UpgradeLists.php [new file with mode: 0644]
turba/lib/LoginTasks/SystemTask/UpgradePrefs.php [new file with mode: 0644]
turba/lib/LoginTasks/Task/UpgradeLists.php [deleted file]
turba/lib/LoginTasks/Task/UpgradePrefs.php [deleted file]

diff --git a/turba/lib/LoginTasks/SystemTask/UpgradeLists.php b/turba/lib/LoginTasks/SystemTask/UpgradeLists.php
new file mode 100644 (file)
index 0000000..6bbf394
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/**
+ * Login system task for upgrading contact lists after upgrading to Turba 2.2.
+ *
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_LoginTasks
+ */
+class Turba_LoginTasks_SystemTask_UpgradeList extends Horde_LoginTasks_SystemTask
+{
+    /**
+     * The interval at which to run the task.
+     *
+     * @var integer
+     */
+    public $interval = Horde_LoginTasks::ONCE;
+
+    /**
+     * Cache array used in _updateShareName().
+     *
+     * @var array
+     */
+    protected $_cache = array();
+
+    /**
+     * Holds an array of Horde_Share_Object objects.
+     *
+     * @var array
+     */
+    protected $_shares = array();
+
+    /**
+     * Perform all functions for this task.
+     *
+     * @return mixed True | PEAR_Error
+     */
+    public function execute()
+    {
+        if (!empty($_SESSION['turba']['has_share'])) {
+            $criteria = array('__type' => 'Group');
+            $sources = array_keys($GLOBALS['cfgSources']);
+            foreach ($sources as $sourcekey) {
+                $driver = Turba_Driver::singleton($sourcekey);
+                $lists = $driver->search($criteria);
+                if (is_a($lists, 'PEAR_Error')) {
+                    return $lists;
+                }
+                $cnt = $lists->count();
+                for ($j = 0; $j < $cnt; ++$j) {
+                    $list = $lists->next();
+                    $attributes = $list->getAttributes();
+                    $members = @unserialize($attributes['__members']);
+                    if (is_array($members) && !empty($members[0])) {
+                        $c = count($members);
+                        for ($i = 0; $i < $c; ++$i) {
+                            if (substr_count($members[$i], ':') == 2) {
+                                preg_match('/^([a-zA-Z0-9]+:[a-zA-Z0-9]+)(:[a-zA-Z0-9]+)$/', $members[$i], $matches);
+                                $source = $matches[1];
+                                $contact_key = substr($matches[2], 1);
+                            } elseif (substr_count($members[$i], ':') == 1) {
+                                list($source, $contact_key) = explode(':', $members[$i]);
+                            } else {
+                                break;
+                            }
+                            $source = $this->_updateShareName($source);
+                            $members[$i] = $source . ':' . $contact_key;
+                        }
+                        $list->setValue('__members', serialize($members));
+                        $list->store();
+                    }
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Helper function to update a 'legacy' share name
+     * to the new flattened share style.
+     */
+    protected function _updateShareName($book)
+    {
+        // No sense going through all the logic if we know we're empty.
+        if (empty($book)) {
+            return $book;
+        }
+
+        if (empty($this->_shares)) {
+            $this->_shares = Turba::listShares();
+        }
+
+        // Have we seen this one yet?
+        if (!empty($this->_cache[$book])) {
+            return $this->_cache[$book];
+        }
+
+        // Is it an unmodified share key already?
+        if (strpos($book, ':') !== false) {
+            list($source, $key) = explode(':', $book, 2);
+            $source = trim($source);
+            $key = trim($key);
+            if (isset($this->_shares[$key])) {
+                $params = @unserialize($this->_shares[$key]->get('params'));
+                // I'm not sure if this would ever be not true, but...
+                if ($params['source'] == $source) {
+                    $this->_cache[$book] = $key;
+                    return $key;
+                }
+            } else {
+                // Maybe a key the upgrade script modified?
+                foreach ($this->_shares as $skey => $share) {
+                    $params = @unserialize($share->get('params'));
+                    if ($params['name'] == $key &&
+                        $params['source'] == $source) {
+
+                       $this->_cache[$book] = $skey;
+                       return $skey;
+                    }
+                }
+            }
+        } else {
+            // Need to check if this is a default address book for
+            // one of our sources that is share enabled.
+            foreach ($this->_shares as $skey => $share) {
+                $params = @unserialize($share->get('params'));
+                if ($params['source'] == $book &&
+                    !empty($params['default'])) {
+                    $this->_cache[$book] = $skey;
+                    return $skey;
+                }
+            }
+        }
+
+        // Special case for contacts from an IMSP source. The cfgSource
+        // keys changed from 2.1 to 2.2 due to needs of the share code.
+        if (strpos($book, 'IMSP_')) {
+            // @TODO: Perform magical matching of IMSP-# to username.bookname.
+        }
+
+        // Must be a normal, non-shared source, just pass it back.
+        $this->_cache[$book] = $book;
+
+        return $book;
+    }
+
+}
diff --git a/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php b/turba/lib/LoginTasks/SystemTask/UpgradePrefs.php
new file mode 100644 (file)
index 0000000..50190ad
--- /dev/null
@@ -0,0 +1,222 @@
+<?php
+/**
+ * Login system task for upgrading user prefs after upgrading to Turba 2.2.
+ *
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_LoginTasks
+ */
+class Turba_LoginTasks_SystemTask_UpgradePrefs extends Horde_LoginTasks_SystemTask
+{
+    /**
+     * The interval at which to run the task.
+     *
+     * @var integer
+     */
+    public $interval = Horde_LoginTasks::ONCE;
+
+    /**
+     * Cache array used in _updateShareName().
+     *
+     * @var array
+     */
+    protected $_cache = array();
+
+    /**
+     * Holds an array of Horde_Share_Object objects.
+     *
+     * @var array
+     */
+    protected $_shares;
+
+    /**
+     * Perform all functions for this task.
+     *
+     * @return mixed True | PEAR_Error
+     */
+    public function execute()
+    {
+        global $registry;
+
+        if (!empty($_SESSION['turba']['has_share'])) {
+            $this->_doAddressbooks();
+            $this->_doColumns();
+            $this->_doAddSource();
+
+            // Now take care of non-Turba prefs.
+            $apps = $registry->listApps(null, true);
+            if (!empty($apps['imp'])) {
+                $registry->loadPrefs('imp');
+                $this->_doImp();
+            }
+
+            if (!empty($apps['kronolith'])) {
+                $registry->loadPrefs('kronolith');
+                $this->_doKronolith();
+            }
+
+            $registry->loadPrefs('turba');
+        }
+
+        return true;
+    }
+
+    /**
+     * Update Turba's addressbooks pref.
+     */
+    protected function _doAddressbooks()
+    {
+        global $prefs;
+
+        $abooks = explode("\n", $prefs->getValue('addressbooks'));
+        if (is_array($abooks) && !empty($abooks[0])) {
+            $new_prefs = array();
+            foreach ($abooks as $abook) {
+                $new_prefs[] = $this->_updateShareName($abook);
+            }
+
+            return $prefs->setValue('addressbooks', implode("\n", $new_prefs));
+        }
+
+        return true;
+    }
+
+    /**
+     * Update Turba's columns pref
+     */
+    protected function _doColumns()
+    {
+        global $prefs;
+
+        // Turba's columns pref
+        $abooks = explode("\n", $prefs->getValue('columns'));
+        if (is_array($abooks) && !empty($abooks[0])) {
+            $new_prefs = array();
+            $cnt = count($abooks);
+            for ($i = 0; $i < $cnt; ++$i) {
+                $colpref = explode("\t", $abooks[$i]);
+                $colpref[0] = $this->_updateShareName($colpref[0]);
+                $abooks[$i] = implode("\t", $colpref);
+            }
+            return $prefs->setValue('columns', implode("\n", $abooks));
+        }
+
+        return true;
+    }
+
+    /**
+     * TODO
+     */
+    protected function _doAddsource()
+    {
+        global $prefs;
+
+        $newName = $this->_updateShareName($prefs->getValue('add_source'));
+        if (!empty($newName)) {
+            return $prefs->setValue('add_source', $newName);
+        }
+    }
+
+    /**
+     * Helper function to update a 'legacy' share name
+     * to the new flattened share style.
+     */
+    protected function _updateShareName($book)
+    {
+        // No sense going through all the logic if we know we're empty.
+        if (empty($book)) {
+            return $book;
+        }
+
+        if (empty($this->_shares)) {
+            $this->_shares = Turba::listShares();
+        }
+
+        // Have we seen this one yet?
+        if (!empty($this->_cache[$book])) {
+            return $this->_cache[$book];
+        }
+
+        // Is it an unmodified share key already?
+        if (strpos($book, ':') !== false) {
+            list($source, $key) = explode(':', $book, 2);
+            $source = trim($source);
+            $key = trim($key);
+            if (isset($this->_shares[$key])) {
+                $params = @unserialize($this->_shares[$key]->get('params'));
+                // I'm not sure if this would ever be not true, but...
+                if ($params['source'] == $source) {
+                    $this->_cache[$book] = $key;
+                    return $key;
+                }
+            } else {
+                // Maybe a key the upgrade script modified?
+                foreach ($this->_shares as $skey => $share) {
+                    $params = @unserialize($share->get('params'));
+                    if (!empty($params['name']) && $params['name'] == $key &&
+                        $params['source'] == $source) {
+
+                       $this->_cache[$book] = $skey;
+                       return $skey;
+                    }
+                }
+            }
+        } else {
+            // Need to check if this is a default address book for
+            // one of our sources that is share enabled.
+            foreach ($this->_shares as $skey => $share) {
+                $params = @unserialize($share->get('params'));
+                if ($params['source'] == $book &&
+                    !empty($params['default'])) {
+                    $this->_cache[$book] = $skey;
+                    return $skey;
+                }
+            }
+        }
+
+        // Must be a normal, non-shared source, just pass it back.
+        $this->_cache[$book] = $book;
+
+        return $book;
+    }
+
+    /**
+     * Update IMP's search_sources pref
+     */
+    protected function _doImp()
+    {
+        global $prefs;
+
+        $imp_pref = $prefs->getValue('search_sources');
+        if (!empty($imp_pref)) {
+            $books = explode("\t", $imp_pref);
+            $new_books = array();
+            foreach ($books as $book) {
+                $new_books[] = $this->_updateShareName($book);
+            }
+            $books = implode("\t", $new_books);
+            return $prefs->setValue('search_sources', $books);
+        }
+
+        return true;
+    }
+
+    /**
+     * Update Kronolith's search_abook pref
+     */
+    protected function _doKronolith()
+    {
+        global $prefs;
+
+        $books = @unserialize($prefs->getValue('search_abook'));
+        if (!empty($books)) {
+            $new_books = array();
+            foreach ($books as $book) {
+                $new_books[] = $this->_updateShareName($book);
+            }
+            return $prefs->setValue('search_abook', serialize($new_books));
+        }
+
+        return true;
+    }
+
+}
diff --git a/turba/lib/LoginTasks/Task/UpgradeLists.php b/turba/lib/LoginTasks/Task/UpgradeLists.php
deleted file mode 100644 (file)
index 4bbe612..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/**
- * Login task for upgrading contact lists after upgrading to Turba 2.2.
- *
- * @author  Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Horde_LoginTasks
- */
-class Turba_LoginTasks_Task_UpgradeList extends Horde_LoginTasks_Task
-{
-    /**
-     * The interval at which to run the task.
-     *
-     * @var integer
-     */
-    public $interval = Horde_LoginTasks::FIRST_LOGIN;
-
-    /**
-     * The style of the page output.
-     *
-     * @var integer
-     */
-    public $display = Horde_LoginTasks::DISPLAY_NONE;
-
-    /**
-     * The priority of the task.
-     *
-     * @var integer
-     */
-    public $priority = Horde_LoginTasks::PRIORITY_HIGH;
-
-    /**
-     * Cache array used in _updateShareName().
-     *
-     * @var array
-     */
-    protected $_cache = array();
-
-    /**
-     * Holds an array of Horde_Share_Object objects.
-     *
-     * @var array
-     */
-    protected $_shares = array();
-
-    /**
-     * Perform all functions for this task.
-     *
-     * @return mixed True | PEAR_Error
-     */
-    public function execute()
-    {
-        if (!empty($_SESSION['turba']['has_share'])) {
-            $criteria = array('__type' => 'Group');
-            $sources = array_keys($GLOBALS['cfgSources']);
-            foreach ($sources as $sourcekey) {
-                $driver = Turba_Driver::singleton($sourcekey);
-                $lists = $driver->search($criteria);
-                if (is_a($lists, 'PEAR_Error')) {
-                    return $lists;
-                }
-                $cnt = $lists->count();
-                for ($j = 0; $j < $cnt; ++$j) {
-                    $list = $lists->next();
-                    $attributes = $list->getAttributes();
-                    $members = @unserialize($attributes['__members']);
-                    if (is_array($members) && !empty($members[0])) {
-                        $c = count($members);
-                        for ($i = 0; $i < $c; ++$i) {
-                            if (substr_count($members[$i], ':') == 2) {
-                                preg_match('/^([a-zA-Z0-9]+:[a-zA-Z0-9]+)(:[a-zA-Z0-9]+)$/', $members[$i], $matches);
-                                $source = $matches[1];
-                                $contact_key = substr($matches[2], 1);
-                            } elseif (substr_count($members[$i], ':') == 1) {
-                                list($source, $contact_key) = explode(':', $members[$i]);
-                            } else {
-                                break;
-                            }
-                            $source = $this->_updateShareName($source);
-                            $members[$i] = $source . ':' . $contact_key;
-                        }
-                        $list->setValue('__members', serialize($members));
-                        $list->store();
-                    }
-                }
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Helper function to update a 'legacy' share name
-     * to the new flattened share style.
-     */
-    protected function _updateShareName($book)
-    {
-        // No sense going through all the logic if we know we're empty.
-        if (empty($book)) {
-            return $book;
-        }
-
-        if (empty($this->_shares)) {
-            $this->_shares = Turba::listShares();
-        }
-
-        // Have we seen this one yet?
-        if (!empty($this->_cache[$book])) {
-            return $this->_cache[$book];
-        }
-
-        // Is it an unmodified share key already?
-        if (strpos($book, ':') !== false) {
-            list($source, $key) = explode(':', $book, 2);
-            $source = trim($source);
-            $key = trim($key);
-            if (isset($this->_shares[$key])) {
-                $params = @unserialize($this->_shares[$key]->get('params'));
-                // I'm not sure if this would ever be not true, but...
-                if ($params['source'] == $source) {
-                    $this->_cache[$book] = $key;
-                    return $key;
-                }
-            } else {
-                // Maybe a key the upgrade script modified?
-                foreach ($this->_shares as $skey => $share) {
-                    $params = @unserialize($share->get('params'));
-                    if ($params['name'] == $key &&
-                        $params['source'] == $source) {
-
-                       $this->_cache[$book] = $skey;
-                       return $skey;
-                    }
-                }
-            }
-        } else {
-            // Need to check if this is a default address book for
-            // one of our sources that is share enabled.
-            foreach ($this->_shares as $skey => $share) {
-                $params = @unserialize($share->get('params'));
-                if ($params['source'] == $book &&
-                    !empty($params['default'])) {
-                    $this->_cache[$book] = $skey;
-                    return $skey;
-                }
-            }
-        }
-
-        // Special case for contacts from an IMSP source. The cfgSource
-        // keys changed from 2.1 to 2.2 due to needs of the share code.
-        if (strpos($book, 'IMSP_')) {
-            // @TODO: Perform magical matching of IMSP-# to username.bookname.
-        }
-
-        // Must be a normal, non-shared source, just pass it back.
-        $this->_cache[$book] = $book;
-
-        return $book;
-    }
-
-}
diff --git a/turba/lib/LoginTasks/Task/UpgradePrefs.php b/turba/lib/LoginTasks/Task/UpgradePrefs.php
deleted file mode 100644 (file)
index 8a921b1..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-<?php
-/**
- * Login task for upgrading user prefs after upgrading to Turba 2.2
- *
- * @author  Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Horde_LoginTasks
- */
-class Turba_LoginTasks_Task_UpgradePrefs extends Horde_LoginTasks_Task
-{
-    /**
-     * The interval at which to run the task.
-     *
-     * @var integer
-     */
-    public $interval = Horde_LoginTasks::FIRST_LOGIN;
-
-    /**
-     * The style of the page output.
-     *
-     * @var integer
-     */
-    public $display = Horde_LoginTasks::DISPLAY_NONE;
-
-    /**
-     * The priority of the task.
-     *
-     * @var integer
-     */
-    public $priority = Horde_LoginTasks::PRIORITY_HIGH;
-
-    /**
-     * Cache array used in _updateShareName().
-     *
-     * @var array
-     */
-    protected $_cache = array();
-
-    /**
-     * Holds an array of Horde_Share_Object objects.
-     *
-     * @var array
-     */
-    protected $_shares;
-
-    /**
-     * Perform all functions for this task.
-     *
-     * @return mixed True | PEAR_Error
-     */
-    public function execute()
-    {
-        global $registry;
-
-        if (!empty($_SESSION['turba']['has_share'])) {
-            $this->_doAddressbooks();
-            $this->_doColumns();
-            $this->_doAddSource();
-
-            // Now take care of non-Turba prefs.
-            $apps = $registry->listApps(null, true);
-            if (!empty($apps['imp'])) {
-                $registry->loadPrefs('imp');
-                $this->_doImp();
-            }
-
-            if (!empty($apps['kronolith'])) {
-                $registry->loadPrefs('kronolith');
-                $this->_doKronolith();
-            }
-
-            $registry->loadPrefs('turba');
-        }
-
-        return true;
-    }
-
-    /**
-     * Update Turba's addressbooks pref.
-     */
-    protected function _doAddressbooks()
-    {
-        global $prefs;
-
-        $abooks = explode("\n", $prefs->getValue('addressbooks'));
-        if (is_array($abooks) && !empty($abooks[0])) {
-            $new_prefs = array();
-            foreach ($abooks as $abook) {
-                $new_prefs[] = $this->_updateShareName($abook);
-            }
-
-            return $prefs->setValue('addressbooks', implode("\n", $new_prefs));
-        }
-
-        return true;
-    }
-
-    /**
-     * Update Turba's columns pref
-     */
-    protected function _doColumns()
-    {
-        global $prefs;
-
-        // Turba's columns pref
-        $abooks = explode("\n", $prefs->getValue('columns'));
-        if (is_array($abooks) && !empty($abooks[0])) {
-            $new_prefs = array();
-            $cnt = count($abooks);
-            for ($i = 0; $i < $cnt; ++$i) {
-                $colpref = explode("\t", $abooks[$i]);
-                $colpref[0] = $this->_updateShareName($colpref[0]);
-                $abooks[$i] = implode("\t", $colpref);
-            }
-            return $prefs->setValue('columns', implode("\n", $abooks));
-        }
-
-        return true;
-    }
-
-    /**
-     * TODO
-     */
-    protected function _doAddsource()
-    {
-        global $prefs;
-
-        $newName = $this->_updateShareName($prefs->getValue('add_source'));
-        if (!empty($newName)) {
-            return $prefs->setValue('add_source', $newName);
-        }
-    }
-
-    /**
-     * Helper function to update a 'legacy' share name
-     * to the new flattened share style.
-     */
-    protected function _updateShareName($book)
-    {
-        // No sense going through all the logic if we know we're empty.
-        if (empty($book)) {
-            return $book;
-        }
-
-        if (empty($this->_shares)) {
-            $this->_shares = Turba::listShares();
-        }
-
-        // Have we seen this one yet?
-        if (!empty($this->_cache[$book])) {
-            return $this->_cache[$book];
-        }
-
-        // Is it an unmodified share key already?
-        if (strpos($book, ':') !== false) {
-            list($source, $key) = explode(':', $book, 2);
-            $source = trim($source);
-            $key = trim($key);
-            if (isset($this->_shares[$key])) {
-                $params = @unserialize($this->_shares[$key]->get('params'));
-                // I'm not sure if this would ever be not true, but...
-                if ($params['source'] == $source) {
-                    $this->_cache[$book] = $key;
-                    return $key;
-                }
-            } else {
-                // Maybe a key the upgrade script modified?
-                foreach ($this->_shares as $skey => $share) {
-                    $params = @unserialize($share->get('params'));
-                    if (!empty($params['name']) && $params['name'] == $key &&
-                        $params['source'] == $source) {
-
-                       $this->_cache[$book] = $skey;
-                       return $skey;
-                    }
-                }
-            }
-        } else {
-            // Need to check if this is a default address book for
-            // one of our sources that is share enabled.
-            foreach ($this->_shares as $skey => $share) {
-                $params = @unserialize($share->get('params'));
-                if ($params['source'] == $book &&
-                    !empty($params['default'])) {
-                    $this->_cache[$book] = $skey;
-                    return $skey;
-                }
-            }
-        }
-
-        // Must be a normal, non-shared source, just pass it back.
-        $this->_cache[$book] = $book;
-
-        return $book;
-    }
-
-    /**
-     * Update IMP's search_sources pref
-     */
-    protected function _doImp()
-    {
-        global $prefs;
-
-        $imp_pref = $prefs->getValue('search_sources');
-        if (!empty($imp_pref)) {
-            $books = explode("\t", $imp_pref);
-            $new_books = array();
-            foreach ($books as $book) {
-                $new_books[] = $this->_updateShareName($book);
-            }
-            $books = implode("\t", $new_books);
-            return $prefs->setValue('search_sources', $books);
-        }
-
-        return true;
-    }
-
-    /**
-     * Update Kronolith's search_abook pref
-     */
-    protected function _doKronolith()
-    {
-        global $prefs;
-
-        $books = @unserialize($prefs->getValue('search_abook'));
-        if (!empty($books)) {
-            $new_books = array();
-            foreach ($books as $book) {
-                $new_books[] = $this->_updateShareName($book);
-            }
-            return $prefs->setValue('search_abook', serialize($new_books));
-        }
-
-        return true;
-    }
-
-}