aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/extension/manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/extension/manager.php')
-rw-r--r--phpBB/phpbb/extension/manager.php150
1 files changed, 54 insertions, 96 deletions
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 4b4109bd85..1ce8425fff 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -161,6 +161,47 @@ class manager
}
/**
+ * Update the database entry for an extension
+ *
+ * @param string $name Extension name to update
+ * @param array $data Data to update in the database
+ * @param string $action Action to perform, by default 'update', may be also 'insert' or 'delete'
+ */
+ protected function update_state($name, $data, $action = 'update')
+ {
+ switch ($action)
+ {
+ case 'insert':
+ $this->extensions[$name] = $data;
+ $this->extensions[$name]['ext_path'] = $this->get_extension_path($name);
+ ksort($this->extensions);
+ $sql = 'INSERT INTO ' . $this->extension_table . ' ' . $this->db->sql_build_array('INSERT', $data);
+ $this->db->sql_query($sql);
+ break;
+
+ case 'update':
+ $this->extensions[$name] = array_merge($this->extensions[$name], $data);
+ $sql = 'UPDATE ' . $this->extension_table . '
+ SET ' . $this->db->sql_build_array('UPDATE', $data) . "
+ WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
+ $this->db->sql_query($sql);
+ break;
+
+ case 'delete':
+ unset($this->extensions[$name]);
+ $sql = 'DELETE FROM ' . $this->extension_table . "
+ WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
+ $this->db->sql_query($sql);
+ break;
+ }
+
+ if ($this->cache)
+ {
+ $this->cache->purge();
+ }
+ }
+
+ /**
* Runs a step of the extension enabling process.
*
* Allows the exentension to enable in a long running script that works
@@ -197,35 +238,7 @@ class manager
'ext_state' => serialize($state),
);
- $this->extensions[$name] = $extension_data;
- $this->extensions[$name]['ext_path'] = $this->get_extension_path($extension_data['ext_name']);
- ksort($this->extensions);
-
- $sql = 'SELECT COUNT(ext_name) as row_count
- FROM ' . $this->extension_table . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $result = $this->db->sql_query($sql);
- $count = $this->db->sql_fetchfield('row_count');
- $this->db->sql_freeresult($result);
-
- if ($count)
- {
- $sql = 'UPDATE ' . $this->extension_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $this->db->sql_query($sql);
- }
- else
- {
- $sql = 'INSERT INTO ' . $this->extension_table . '
- ' . $this->db->sql_build_array('INSERT', $extension_data);
- $this->db->sql_query($sql);
- }
-
- if ($this->cache)
- {
- $this->cache->purge();
- }
+ $this->update_state($name, $extension_data, $this->is_configured($name) ? 'update' : 'insert');
if ($active)
{
@@ -272,46 +285,15 @@ class manager
$extension = $this->get_extension($name);
$state = $extension->disable_step($old_state);
-
- // continue until the state is false
- if ($state !== false)
- {
- $extension_data = array(
- 'ext_state' => serialize($state),
- );
- $this->extensions[$name]['ext_state'] = serialize($state);
-
- $sql = 'UPDATE ' . $this->extension_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $this->db->sql_query($sql);
-
- if ($this->cache)
- {
- $this->cache->purge();
- }
-
- return true;
- }
+ $active = ($state !== false);
$extension_data = array(
- 'ext_active' => false,
- 'ext_state' => serialize(false),
+ 'ext_active' => $active,
+ 'ext_state' => serialize($state),
);
- $this->extensions[$name]['ext_active'] = false;
- $this->extensions[$name]['ext_state'] = serialize(false);
+ $this->update_state($name, $extension_data);
- $sql = 'UPDATE ' . $this->extension_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $this->db->sql_query($sql);
-
- if ($this->cache)
- {
- $this->cache->purge();
- }
-
- return false;
+ return $active;
}
/**
@@ -357,40 +339,16 @@ class manager
$extension = $this->get_extension($name);
$state = $extension->purge_step($old_state);
+ $purged = ($state === false);
- // continue until the state is false
- if ($state !== false)
- {
- $extension_data = array(
- 'ext_state' => serialize($state),
- );
- $this->extensions[$name]['ext_state'] = serialize($state);
-
- $sql = 'UPDATE ' . $this->extension_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $this->db->sql_query($sql);
-
- if ($this->cache)
- {
- $this->cache->purge();
- }
-
- return true;
- }
-
- unset($this->extensions[$name]);
-
- $sql = 'DELETE FROM ' . $this->extension_table . "
- WHERE ext_name = '" . $this->db->sql_escape($name) . "'";
- $this->db->sql_query($sql);
+ $extension_data = array(
+ 'ext_state' => serialize($state),
+ );
- if ($this->cache)
- {
- $this->cache->purge();
- }
+ $this->update_state($name, $extension_data, $purged ? 'delete' : 'update');
- return false;
+ // continue until the state is false
+ return !$purged;
}
/**