Ignore:
Timestamp:
Mar 6, 2008, 3:29:29 AM (16 years ago)
Author:
rvelices
Message:
  • plugins.php does only the tabsheet - nothing else
  • need to review plugins_update.php upgrade action
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_plugins.inc.php

    r2245 r2255  
    8686
    8787/**
     88 * Activates a plugin. It will be loaded only on the next page ...
     89 * @param string $plugin_id the plugin to activate
     90 * @param array $errors errors to be returned
     91 */
     92function activate_plugin($plugin_id, &$errors)
     93{
     94  // the plugin_id must exist in the DB as inactive
     95  $db_plugins = get_db_plugins('', $plugin_id);
     96  if (!empty($db_plugins))
     97  {
     98    $crt_db_plugin = $db_plugins[0];
     99    if ($crt_db_plugin['state'] != 'inactive')
     100    {
     101      array_push($errors, 'CANNOT ACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
     102      return false;
     103    }
     104  }
     105  else
     106  {
     107    array_push($errors, 'CANNOT ACTIVATE - NOT INSTALLED');
     108    return false;
     109  }
     110
     111  // now try to activate it
     112  $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
     113  if (file_exists($file_to_include))
     114  {
     115    include_once($file_to_include);
     116    if (function_exists('plugin_activate'))
     117    {
     118      plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
     119    }
     120  }
     121  if (empty($errors))
     122  {
     123    $query = '
     124UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
     125    pwg_query($query);
     126    return true;
     127  }
     128  return false;
     129}
     130
     131
     132/**
     133 * Deactivates a plugin. It will be unloaded only on the next page ...
     134 * @param string $plugin_id the plugin to activate
     135 * @param array $errors errors to be returned
     136 */
     137function deactivate_plugin($plugin_id, &$errors)
     138{
     139  // the plugin_id must exist in the DB as inactive
     140  $db_plugins = get_db_plugins('', $plugin_id);
     141  if (!empty($db_plugins))
     142  {
     143    $crt_db_plugin = $db_plugins[0];
     144    if ($crt_db_plugin['state'] != 'active')
     145    {
     146      array_push($errors, 'CANNOT DEACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
     147      return false;
     148    }
     149  }
     150  else
     151  {
     152    array_push($errors, 'CANNOT DEACTIVATE - NOT INSTALLED');
     153    return false;
     154  }
     155
     156  // now try to deactivate it
     157  $query = '
     158UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
     159  pwg_query($query);
     160
     161  $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
     162  if (file_exists($file_to_include))
     163  {
     164    include_once($file_to_include);
     165    if (function_exists('plugin_deactivate'))
     166    {
     167      plugin_deactivate($plugin_id);
     168    }
     169  }
     170  return true;
     171}
     172
     173
     174/**
    88175 * Retrieves an url for a plugin page.
    89176 * @param string file - php script full name
     
    288375  return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name']));
    289376}
     377
    290378function extension_author_compare($a, $b)
    291379{
     
    295383}
    296384
     385function plugin_author_compare($a, $b)
     386{
     387  return strcasecmp( $a['author'], $b['author']);
     388}
     389
     390function plugin_version_compare($a, $b)
     391{
     392  return version_compare( $a['version'], $b['version']);
     393}
     394
    297395?>
Note: See TracChangeset for help on using the changeset viewer.