コード例 #1
0
ファイル: dbgen.php プロジェクト: armpit/e107
 *
 * Database utilities - create arrays from SQL definition
 *
 * $Source: /cvs_backup/e107_0.8/e107_files/utilities/dbgen.php,v $
 * $Revision$
 * $Date$
 * $Author$
*/
require '../../class2.php';
require_once e_HANDLER . 'db_table_admin_class.php';
if (!check_class(e_UC_MAINADMIN)) {
    exit;
}
$dbAdm = new db_table_admin();
// Create an array of all tables
$tableStruct = $dbAdm->get_table_def('', e_CORE . 'sql/core_sql.php');
$tableArray = array();
foreach ($tableStruct as $t) {
    $tableArray[$t[1]] = array('src' => e_CORE . 'sql/core_sql.php', 'desc' => 'core:' . $t[1]);
}
// Now do the plugins
$sqlFiles = e107::getPref('e_sql_list');
foreach ($sqlFiles as $p => $f) {
    $targ = e_PLUGIN . $p . '/' . $f . '.php';
    //echo $p.':'.$targ.'<br />';
    $tableStruct = $dbAdm->get_table_def('', $targ);
    foreach ($tableStruct as $t) {
        $tableArray[$t[1]] = array('src' => $targ, 'desc' => 'plug:' . $p . ':' . $t[1]);
    }
}
unset($tableStruct);
コード例 #2
0
ファイル: plugin_class.php プロジェクト: notzen/e107
 /**
  * Install routine for XML file
  * @param object $id (the number of the plugin in the DB)
  * @param object $function install|upgrade|uninstall|refresh (adds things that are missing, but doesn't change any existing settings)
  * @param object $options [optional] an array of possible options - ATM used only for uninstall:
  * 			'delete_userclasses' - to delete userclasses created
  * 			'delete_tables' - to delete DB tables
  * 			'delete_xfields' - to delete extended fields
  * 			'delete_ipool' - to delete icon pool entry
  * 			+ any defined in <pluginname>_setup.php in the uninstall_options() method.
  * @return TBD
  */
 function install_plugin_xml($id, $function = '', $options = FALSE)
 {
     global $pref;
     $sql = e107::getDb();
     $mes = e107::getMessage();
     $error = array();
     // Array of error messages
     $canContinue = TRUE;
     // Clear flag if must abort part way through
     $id = (int) $id;
     $plug = $this->getinfo($id);
     // Get plugin info from DB
     $this->current_plug = $plug;
     $txt = '';
     $path = e_PLUGIN . $plug['plugin_path'] . '/';
     $this->plugFolder = $plug['plugin_path'];
     $this->unInstallOpts = $options;
     $addons = explode(',', $plug['plugin_addons']);
     $sql_list = array();
     foreach ($addons as $addon) {
         if (substr($addon, -4) == '_sql') {
             $sql_list[] = $addon . '.php';
         }
     }
     if (!file_exists($path . 'plugin.xml') || $function == '') {
         $error[] = EPL_ADLAN_77;
         $canContinue = FALSE;
     }
     if ($canContinue && $this->parse_plugin_xml($plug['plugin_path'])) {
         $plug_vars = $this->plug_vars;
     } else {
         $error[] = EPL_ADLAN_76;
         $canContinue = FALSE;
     }
     if (varset($plug_vars['languageFiles'])) {
         $this->XmlLanguageFiles($function, $plug_vars['languageFiles'], 'pre');
         // First of all, see if there's a language file specific to install
     }
     // Next most important, if installing or upgrading, check that any dependencies are met
     if ($canContinue && $function != 'uninstall' && isset($plug_vars['dependencies'])) {
         $canContinue = $this->XmlDependencies($plug_vars['dependencies']);
     }
     if (!$canContinue) {
         return FALSE;
     }
     // All the dependencies are OK - can start the install now
     if ($canContinue) {
         $ret = $this->execute_function($path, $function, 'pre');
         if (!is_bool($ret)) {
             $txt .= $ret;
         }
     }
     // Handle tables
     if ($canContinue && count($sql_list)) {
         require_once e_HANDLER . 'db_table_admin_class.php';
         $dbHandler = new db_table_admin();
         foreach ($sql_list as $sqlFile) {
             $tableList = $dbHandler->get_table_def('', $path . $sqlFile);
             if (!is_array($tableList)) {
                 $mes->add("Can't read SQL definition: " . $path . $sqlFile, E_MESSAGE_ERROR);
                 break;
             }
             // Got the required definition here
             foreach ($tableList as $ct) {
                 // Process one table at a time (but they could be multi-language)
                 switch ($function) {
                     case 'install':
                         $sqlTable = str_replace("CREATE TABLE " . MPREFIX . '`', "CREATE TABLE `" . MPREFIX, preg_replace("/create table\\s+/si", "CREATE TABLE " . MPREFIX, $ct[0]));
                         $txt = "Adding Table: {$ct[1]} ... ";
                         $status = $this->manage_tables('add', array($sqlTable)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
                         // Pass the statement to create the table
                         $mes->add($txt, $status);
                         break;
                     case 'upgrade':
                         $tmp = $dbHandler->update_table_structure($ct, FALSE, TRUE, $pref['multilanguage']);
                         if ($tmp === FALSE) {
                             $error[] = 'Error Updating Table: ' . $ct[1];
                         } elseif ($tmp !== TRUE) {
                             $error[] = $tmp;
                         }
                         break;
                     case 'refresh':
                         // Leave things alone
                         break;
                     case 'uninstall':
                         if (vartrue($options['delete_tables'], FALSE)) {
                             $txt = "Removing Table: {$ct[1]} <br />";
                             $status = $this->manage_tables('remove', array($ct[1])) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
                             // Delete the table
                             $mes->add($txt, $status);
                         } else {
                             $mes->add("Table {$ct[1]} left in place.", E_MESSAGE_SUCCESS);
                         }
                         break;
                 }
             }
         }
     }
     if (varset($plug_vars['adminLinks'])) {
         $this->XmlAdminLinks($function, $plug_vars['adminLinks']);
     }
     if (varset($plug_vars['siteLinks'])) {
         $this->XmlSiteLinks($function, $plug_vars['siteLinks']);
     }
     if (varset($plug_vars['mainPrefs'])) {
         $this->XmlPrefs('core', $function, $plug_vars['mainPrefs']);
     }
     if (varset($plug_vars['pluginPrefs'])) {
         $this->XmlPrefs($plug['plugin_path'], $function, $plug_vars['pluginPrefs']);
     }
     if (varset($plug_vars['userClasses'])) {
         $this->XmlUserClasses($function, $plug_vars['userClasses']);
     }
     if (varset($plug_vars['extendedFields'])) {
         $this->XmlExtendedFields($function, $plug_vars['extendedFields']);
     }
     if (varset($plug_vars['languageFiles'])) {
         $this->XmlLanguageFiles($function, $plug_vars['languageFiles']);
     }
     if (varset($plug_vars['bbcodes'])) {
         $this->XmlBBcodes($function, $plug_vars);
     }
     if (varset($plug_vars['mediaCategories'])) {
         $this->XmlMediaCategories($function, $plug_vars);
     }
     $this->manage_icons($this->plugFolder, $function);
     //FIXME
     //If any commentIDs are configured, we need to remove all comments on uninstall
     if ($function == 'uninstall' && isset($plug_vars['commentID'])) {
         $txt .= 'Removing all plugin comments: (' . implode(', ', $plug_vars['commentID']) . ')<br />';
         $this->manage_comments('remove', $commentArray);
     }
     $this->manage_search($function, $plug_vars['folder']);
     $this->manage_notify($function, $plug_vars['folder']);
     $eplug_addons = $this->getAddons($plug['plugin_path']);
     $p_installed = e107::getPref('plug_installed', array());
     // load preference;
     if ($function == 'install' || $function == 'upgrade') {
         $sql->db_Update('plugin', "plugin_installflag = 1, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}', plugin_category ='" . $this->manage_category($plug_vars['category']) . "', plugin_releaseUrl= '" . varset($plug_vars['@attributes']['releaseUrl']) . "' WHERE plugin_id = " . $id);
         $p_installed[$plug['plugin_path']] = $plug_vars['@attributes']['version'];
         e107::getConfig('core')->setPref('plug_installed', $p_installed);
         //e107::getConfig('core')->save(); - save triggered below
     }
     if ($function == 'uninstall') {
         $sql->db_Update('plugin', "plugin_installflag = 0, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}', plugin_category ='" . $this->manage_category($plug_vars['category']) . "', plugin_releaseUrl= '" . varset($plug_vars['@attributes']['releaseUrl']) . "' WHERE plugin_id = " . $id);
         unset($p_installed[$plug['plugin_path']]);
         e107::getConfig('core')->setPref('plug_installed', $p_installed);
     }
     $this->rebuildUrlConfig();
     e107::getConfig('core')->save();
     /*	if($function == 'install')
     		 {
     		 if(isset($plug_vars['management']['installDone'][0]))
     		 {
     		 $mes->add($plug_vars['management']['installDone'][0], E_MESSAGE_SUCCESS);
     		 }
     		 }*/
     // Run custom {plugin}_setup install/upgrade etc. for INSERT, ALTER etc. etc. etc.
     // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
     if (!$this->execute_function($path, $function, 'post')) {
         if ($function == 'install') {
             $text = "Installation Complete.";
             if ($this->plugConfigFile) {
                 $text .= "&nbsp;<a href='" . $this->plugConfigFile . "'>[" . LAN_CONFIGURE . "]</a>";
             }
             $mes->add($text, E_MESSAGE_SUCCESS);
         }
     }
 }