CVS update: /cowiki/htdocs/setup/class/task/
[email protected] 16 May 2005 22:22:45 -0000
| Newsgroups | gmane.comp.php.cowiki.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: dgorski Date: 2005/05/16 15:22:45 Modified: cowiki/htdocs/setup/class/task/class.TaskMigrator.php Log: Rewrite File Changes: Directory: /cowiki/htdocs/setup/class/task/ =========================================== File [changed]: class.TaskMigrator.php Url: http://cowiki.tigris.org/source/browse/cowiki/htdocs/setup/class/task/class.TaskMigrator.php?r1=1.7&r2=1.8 Delta lines: +36 -39 --------------------- --- class.TaskMigrator.php 12 May 2005 17:05:06 -0000 1.7 +++ class.TaskMigrator.php 16 May 2005 22:22:43 -0000 1.8 @@ -2,7 +2,7 @@ /** * - * $Id: class.TaskMigrator.php,v 1.7 2005/05/12 17:05:06 dgorski Exp $ + * $Id: class.TaskMigrator.php,v 1.8 2005/05/16 22:22:43 dgorski Exp $ * * This file is part of coWiki. coWiki is free software under the terms of * the GNU General Public License (GPL). Read the LICENSE file. If you did @@ -17,7 +17,7 @@ * @author Daniel T. Gorski, <[email protected]> * @copyright (C) Daniel T. Gorski, {@link http://www.develnet.org} * @license http://www.gnu.org/licenses/gpl.html - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * */ @@ -32,6 +32,10 @@ */ class TaskMigrator extends AbstractTask { + private $nMigCount = 0; + + // -------------------------------------------------------------------- + public function __construct($Tpl) { parent::__construct($Tpl); parent::checkValidUser(); @@ -45,21 +49,19 @@ // Get migrator classes that are scheduled $aMig = $this->getMigratorClasses(); - // Count pending tasks - $nCount = 0; - foreach ($aMig as $k => $v) { + // Instantiate migrator class $Mig = new $v($this->State); if ($Mig->isRequired()) { - // Get description(s) count - $nCount += sizeof($Mig->getDescription()); + // Get required Migrator classes count + $this->nMigCount++; } } - return $nCount != 0; + return $this->nMigCount != 0; } // -------------------------------------------------------------------- @@ -101,27 +103,16 @@ // ---------------------------------------------------------------- - // Count pending tasks - $nCount = 0; - - foreach ($aMig as $k => $v) { - // Instantiate migrator class - $Mig = new $v($this->State); - - // Get description(s) count - $nCount += sizeof($Mig->getDescription()); - } - $sStr = '<table width="100%" cellpadding="0" cellspacing="0"'; $sStr .= ' border="0">'; $sStr .= '<tr>'; $sStr .= '<td>'; $sStr .= 'Your coWiki installation is not up-to-date. '; - if ($nCount == 1) { + if ($this->nMigCount == 1) { $sStr .= 'Following update is pending:'; } else { - $sStr .= 'Following '.$nCount.' updates are pending:'; + $sStr .= 'Following '.$this->nMigCount.' updates are pending:'; } $sStr .= '</td>'; @@ -145,24 +136,13 @@ // Instantiate class $Mig = new $v($this->State); - // Description might be either a string or an array - $mDesc = $Mig->getDescription(); - - if (is_string($mDesc)) { + if ($Mig->isRequired()) { $sStr .= '<li>'; -# $sStr .= $this->getMigrationDate($k); - $sStr .= $mDesc . '<br/>'; +# $sStr .= $this->getMigrationDate($k) . ': '; + $sStr .= $Mig->getDescription() . '<br/>'; $sStr .= '</li>'; } - if (is_array($mDesc)) { - foreach ($mDesc as $sDesc) { - $sStr .= '<li>'; -# $sStr .= $this->getMigrationDate($k); - $sStr .= $sDesc . '<br/>'; - $sStr .= '</li>'; - } - } } $sStr .= '</ul>'; @@ -217,8 +197,14 @@ // -------------------------------------------------------------------- private function getMigratorClasses() { - $aMig = array(); + static $aCache = null; + + // Data already there? + if ($aCache != null) { + return $aCache; + } + $aMig = array(); $sDir = './class/task/migrator/'; // Read all migrator classes @@ -231,8 +217,6 @@ $sKey = substr($sFileName, 15, -4); $sVal = substr($sFileName, 6, -4); -# Check COWIKI_VERSION_DATE - $aMig[$sKey] = $sVal; } } @@ -241,6 +225,9 @@ // Sort migrator files by their keys (dates) ksort($aMig); + // Remember in static variable + $aCache = $aMig; + return $aMig; } @@ -254,7 +241,17 @@ return strftime( '%B %d, %Y', strtotime(str_replace('_', '-', $sDate)) - ) . ': '; + ); + } + + // -------------------------------------------------------------------- + + private function getMigrationStamp($sDate) { + if ($sDate == '0') { + return 0; + } + + return strtotime(str_replace('_', '-', $sDate)); } } // of class