[icinga-checkins] icinga.org: icinga-web/next: Migrate old filter to new ones

git at icinga.org git at icinga.org
Thu Apr 18 15:57:16 CEST 2013


Module: icinga-web
Branch: next
Commit: 6fe69ed763e0cbecf93bdd78ca9bec7456c094ca
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=6fe69ed763e0cbecf93bdd78ca9bec7456c094ca

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Apr 18 12:53:52 2013 +0200

Migrate old filter to new ones

Rewrite the cronk upgrade system. Move iterator
into a abstract iterator class to implement
specific hooks into own classes.

refs #3981

---

 etc/build.xml                                      |    4 +-
 ...ronkUpgradeTask.php => CronkDropLayoutTask.php} |   54 ++++++-------------
 ...onkUpgradeTask.php => CronkUpgradeAbstract.php} |   48 +++++++++++++----
 3 files changed, 56 insertions(+), 50 deletions(-)

diff --git a/etc/build.xml b/etc/build.xml
index 2b269c9..456cd40 100644
--- a/etc/build.xml
+++ b/etc/build.xml
@@ -155,7 +155,7 @@
     </target>
 
     <target name="drop-customcronk-layout">
-        <taskdef name="upgradeCronkTo18" classname="etc.lib.cronkUpgradeTask"/>
-        <upgradeCronkTo18 />
+        <taskdef name="cronkdroplayout" classname="etc.lib.CronkDropLayoutTask"/>
+        <cronkdroplayout />
     </target>
 </project>
diff --git a/etc/lib/cronkUpgradeTask.php b/etc/lib/CronkDropLayoutTask.php
similarity index 52%
copy from etc/lib/cronkUpgradeTask.php
copy to etc/lib/CronkDropLayoutTask.php
index 7322963..a2748a1 100644
--- a/etc/lib/cronkUpgradeTask.php
+++ b/etc/lib/CronkDropLayoutTask.php
@@ -21,42 +21,22 @@
 // -----------------------------------------------------------------------------
 // {{{ICINGA_LICENSE_CODE}}}
 
-require 'agaviConsoleTask.php';
-require 'CronkStruct.php';
-
-class cronkUpgradeTask extends agaviConsoleTask {
-
-    public function main() {
-        parent::main();
-
-       $cronksQuery = Doctrine_Query::create()
-       ->select('*')
-       ->from('Cronk c');
-
-        $cronks = $cronksQuery->execute();
-
-        /** @var $cronk Cronk */
-        $cronk = null;
-
-        /** @var $structs CronkStruct[] */
-        $structs = array();
-
-        foreach ($cronks as $cronk) {
-            $cronkStruct = new CronkStruct($cronk);
-            $this->log('Testing cronk '. $cronkStruct->getName());
-
-            $cronkStruct->dropLayoutState();
-
-            $update = $cronkStruct->persistToDatabase();
-            if ($update) {
-                $this->log('Columns upgraded', Project::MSG_WARN);
-                continue;
-            }
-
-            $this->log('Nothing to to', Project::MSG_INFO);
-
-        }
+require 'CronkUpgradeAbstract.php';
+
+/**
+ * Class cronkUpgradeTask
+ *
+ * Specific caller class to drop state from cronks
+ */
+class CronkDropLayoutTask extends CronkUpgradeAbstract {
+
+    /**
+     * Drops the layout state from each cronk
+     *
+     * @param CronkStruct $struct
+     * @return mixed|void
+     */
+    protected function upgradeMethod(CronkStruct $struct) {
+        $struct->dropLayoutState();
     }
-
-
 }
diff --git a/etc/lib/cronkUpgradeTask.php b/etc/lib/CronkUpgradeAbstract.php
similarity index 63%
rename from etc/lib/cronkUpgradeTask.php
rename to etc/lib/CronkUpgradeAbstract.php
index 7322963..af6f95e 100644
--- a/etc/lib/cronkUpgradeTask.php
+++ b/etc/lib/CronkUpgradeAbstract.php
@@ -2,20 +2,20 @@
 // {{{ICINGA_LICENSE_CODE}}}
 // -----------------------------------------------------------------------------
 // This file is part of icinga-web.
-// 
+//
 // Copyright (c) 2009-2013 Icinga Developer Team.
 // All rights reserved.
-// 
+//
 // icinga-web is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // the Free Software Foundation, either version 3 of the License, or
 // (at your option) any later version.
-// 
+//
 // icinga-web 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 icinga-web.  If not, see <http://www.gnu.org/licenses/>.
 // -----------------------------------------------------------------------------
@@ -24,14 +24,35 @@
 require 'agaviConsoleTask.php';
 require 'CronkStruct.php';
 
-class cronkUpgradeTask extends agaviConsoleTask {
+/**
+ * Class cronkUpgradeAbstract
+ *
+ * Abstract model to call update methods on CronkStruct
+ * object.
+ */
+abstract class CronkUpgradeAbstract extends agaviConsoleTask {
 
+    /**
+     * Phing default entry poing
+     */
     public function main() {
         parent::main();
+        $this->cronkStructIterator();
+    }
 
-       $cronksQuery = Doctrine_Query::create()
-       ->select('*')
-       ->from('Cronk c');
+    /**
+     * Cronk iterator
+     *
+     * Queries the database, iterate over all
+     * cronks and create a CronkStructure object.
+     *
+     * For each cronk the abstract method in this class
+     * is called
+     */
+    protected function cronkStructIterator() {
+        $cronksQuery = Doctrine_Query::create()
+            ->select('*')
+            ->from('Cronk c');
 
         $cronks = $cronksQuery->execute();
 
@@ -45,11 +66,11 @@ class cronkUpgradeTask extends agaviConsoleTask {
             $cronkStruct = new CronkStruct($cronk);
             $this->log('Testing cronk '. $cronkStruct->getName());
 
-            $cronkStruct->dropLayoutState();
+            $this->upgradeMethod($cronkStruct);
 
             $update = $cronkStruct->persistToDatabase();
             if ($update) {
-                $this->log('Columns upgraded', Project::MSG_WARN);
+                $this->log('Cronk changed', Project::MSG_WARN);
                 continue;
             }
 
@@ -58,5 +79,10 @@ class cronkUpgradeTask extends agaviConsoleTask {
         }
     }
 
-
+    /**
+     * Notifier function to modify cronk data
+     * @param CronkStruct $struct
+     * @return mixed
+     */
+    abstract protected function upgradeMethod(CronkStruct $struct);
 }





More information about the icinga-checkins mailing list