]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #965: Allowing upgrades to be loaded from other locations.
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 22 May 2009 16:33:19 +0000 (16:33 +0000)
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 22 May 2009 16:33:19 +0000 (16:33 +0000)
git-svn-id: https://code.elgg.org/elgg/trunk@3301 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/database.php

index 9db5cf37c38bdba33e75f9b8d6fdc2a8c1a16844..4aa87992091fff96ea8282979fb0fe9f3e54a98e 100644 (file)
                }\r
                \r
         }\r
-        \r
-        function db_upgrade($version) {\r
+        
+        /**
+         * Upgrade the database schema in an ordered sequence.
+         * 
+         * Makes use of schema upgrade files
+         * 
+         * This is a about as core as it comes, so don't start running this from your plugins!
+         *
+         * @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example)
+         * @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/)
+         * @return bool
+         */\r
+        function db_upgrade($version, $fromdir = "") {\r
                \r
                global $CONFIG;\r
                \r
                // Elgg and its database must be installed to upgrade it!\r
-               if (!is_db_installed() || !is_installed()) return false;\r
+               if (!is_db_installed() || !is_installed()) return false;
                \r
-               $version = (int) $version;\r
+               $version = (int) $version;
+               if (!$fromdir)
+                       $fromdir = $CONFIG->path . 'engine/schema/upgrades/';\r
                \r
-               if ($handle = opendir($CONFIG->path . 'engine/schema/upgrades/')) {\r
+               if ($handle = opendir($fromdir)) {\r
                        \r
                        $sqlupgrades = array();\r
                        \r
                        while ($sqlfile = readdir($handle)) {\r
                                \r
-                               if (!is_dir($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile)) {\r
+                               if (!is_dir($fromdir . $sqlfile)) {\r
                                        if (preg_match('/([0-9]*)\.sql/',$sqlfile,$matches)) {\r
                                                $sql_version = (int) $matches[1];\r
                                                if ($sql_version > $version) {\r
                        if (sizeof($sqlupgrades) > 0) {\r
                                foreach($sqlupgrades as $sqlfile) {\r
                                        try {\r
-                                               run_sql_script($CONFIG->path . 'engine/schema/upgrades/' . $sqlfile);\r
+                                               run_sql_script($fromdir . $sqlfile);\r
                                        } catch (DatabaseException $e) {\r
                                                error_log($e->getmessage());\r
                                        }\r