aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/extension/manager.php
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-01-31 13:53:33 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2013-02-06 11:31:50 -0600
commitaa67fa6dd83e329c3b6edbb356eae3eeda1ba69f (patch)
tree1cb0241b093b25f102b60fa1d85bdedcbf89d16a /phpBB/includes/extension/manager.php
parent8d3a82a4fa8ced50fbc1d1019ef439d1d5c81e71 (diff)
downloadforums-aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f.tar
forums-aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f.tar.gz
forums-aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f.tar.bz2
forums-aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f.tar.xz
forums-aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f.zip
[feature/migrations] Automatically install/revert migrations for extensions
Migrations from ext/ext_name/migrations/ are automatically installed when enabling the extension and automatically reverted when the extension is purged. PHPBB3-11318
Diffstat (limited to 'phpBB/includes/extension/manager.php')
-rw-r--r--phpBB/includes/extension/manager.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php
index 8136dfa90b..018324d5d6 100644
--- a/phpBB/includes/extension/manager.php
+++ b/phpBB/includes/extension/manager.php
@@ -173,6 +173,12 @@ class phpbb_extension_manager
$old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false;
+ // Returns false if not completed
+ if (!$this->handle_migrations($name, 'enable'))
+ {
+ return true;
+ }
+
$extension = $this->get_extension($name);
$state = $extension->enable_step($old_state);
@@ -324,6 +330,12 @@ class phpbb_extension_manager
$old_state = unserialize($this->extensions[$name]['ext_state']);
+ // Returns false if not completed
+ if (!$this->handle_migrations($name, 'purge'))
+ {
+ return true;
+ }
+
$extension = $this->get_extension($name);
$state = $extension->purge_step($old_state);
@@ -497,4 +509,54 @@ class phpbb_extension_manager
{
return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder');
}
+
+ /**
+ * Handle installing/reverting migrations
+ *
+ * @param string $extension_name Name of the extension
+ * @param string $mode enable or purge
+ * @return bool True if completed, False if not completed
+ */
+ protected function handle_migrations($extension_name, $mode)
+ {
+ $migrator = $this->container->get('migrator');
+ $migrations_path = $this->get_extension_path($extension_name) . 'migrations';
+ if (file_exists($migrations_path) && is_dir($migrations_path))
+ {
+ $migrator->load_migrations($migrations_path);
+ }
+
+ // What is a safe limit of execution time? Half the max execution time should be safe.
+ $safe_time_limit = (ini_get('max_execution_time') / 2);
+ $start_time = time();
+
+ if ($mode == 'enable')
+ {
+ while (!$migrator->finished())
+ {
+ $migrator->update();
+
+ // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
+ if ((time() - $start_time) >= $safe_time_limit)
+ {
+ return false;
+ }
+ }
+ }
+ else if ($mode == 'purge')
+ {
+ while ($migrator->migration_state() !== false)
+ {
+ $migrator->revert();
+
+ // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
+ if ((time() - $start_time) >= $safe_time_limit)
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
}