/** * Creates a field type definition from the structure of the table in the DB * * Generate and save a cache file in the e_CACHE_DB directory, * Also update $this->dbFieldDefs[$tableName] - FALSE if error, data if found * * @param string $tableName - name of table sought * * @return boolean TRUE on success, FALSE on not found (some errors intentionally ignored) */ protected function makeTableDef($tableName) { require_once e_HANDLER . 'db_table_admin_class.php'; $dbAdm = new db_table_admin(); $baseStruct = $dbAdm->get_current_table($tableName); $fieldDefs = $dbAdm->parse_field_defs($baseStruct[0][2]); // Required definitions $outDefs = array(); foreach ($fieldDefs as $k => $v) { switch ($v['type']) { case 'field': if (vartrue($v['autoinc'])) { //break; Probably include autoinc fields in array } $baseType = preg_replace('#\\(\\d+?\\)#', '', $v['fieldtype']); // Should strip any length switch ($baseType) { case 'int': case 'shortint': case 'tinyint': $outDefs['_FIELD_TYPES'][$v['name']] = 'int'; break; case 'char': case 'text': case 'varchar': $outDefs['_FIELD_TYPES'][$v['name']] = 'escape'; //XXX toDB() causes serious BC issues. break; } // if($v['name']) if (isset($v['nulltype']) && !isset($v['default'])) { $outDefs['_NOTNULL'][$v['name']] = ''; } break; case 'pkey': case 'ukey': case 'key': case 'ftkey': break; // Do nothing with keys for now // Do nothing with keys for now default: echo "Unexpected field type: {$k} => {$v['type']}<br />"; } } $array = e107::getArrayStorage(); $this->dbFieldDefs[$tableName] = $outDefs; $toSave = $array->WriteArray($outDefs, FALSE); // 2nd parameter to TRUE if needs to be written to DB if (FALSE === file_put_contents(e_CACHE_DB . $tableName . '.php', $toSave)) { // Could do something with error - but mustn't return FALSE - would trigger auto-generated structure $mes = e107::getMessage(); $mes->addDebug("Error writing file: " . e_CACHE_DB . $tableName . '.php'); //Fix for during v1.x -> 2.x upgrade. // echo "Error writing file: ".e_CACHE_DB.$tableName.'.php'.'<br />'; } }
* Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * 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]); }
function step2() { $e107 = e107::getInstance(); if (!isset($_POST['create_tables'])) { $text = "\n\t\tThis step will create the new forum_thread, forum_post, and forum_attach tables. It will also create a forum_new table that will become the 'real' forum table once the data from the current table is migrated.\n\t\t<br /><br />\n\t\t<form method='post'>\n\t\t<input class='button' type='submit' name='create_tables' value='Proceed with table creation' />\n\t\t</form>\n\t\t"; $e107->ns->tablerender('Step 2: Forum table creation', $text); return; } require_once e_HANDLER . 'db_table_admin_class.php'; $db = new db_table_admin(); $tabList = array('forum' => 'forum_new', 'forum_thread' => '', 'forum_post' => '', 'forum_track' => ''); $ret = ''; $failed = false; $text = ''; foreach ($tabList as $name => $rename) { $text .= 'Creating table ' . ($rename ? $rename : $name) . ' -> '; $result = $db->createTable(e_PLUGIN . 'forum/forum_sql.php', $name, true, $rename); if ($result) { $text .= 'Success <br />'; } else { $text .= 'Failed <br />'; $failed = true; } } if ($failed) { $text .= "\n\t\t<br /><br />\n\t\tCreation of table(s) failed. You can not continue until these are create successfully!\n\t\t"; } else { $text .= "\n\t\t\t<br /><br />\n\t\t\t<form method='post'>\n\t\t\t<input class='button' type='submit' name='nextStep[3]' value='Proceed to step 3' />\n\t\t\t</form>\n\t\t\t"; } $e107->ns->tablerender('Step 2: Forum table creation', $text); }
function step2() { $mes = e107::getMessage(); $ns = e107::getRender(); if (!isset($_POST['create_tables'])) { $text = "\n\t\tThis step will create the new forum_thread, forum_post, and forum_attach tables. It will also create a forum_new table that will become the 'real' forum table once the data from the current table is migrated.\n\t\t<br /><br />\n\t\t<form method='post'>\n\t\t<input class='btn btn-success' data-loading-text='Please wait...' type='submit' name='create_tables' value='Proceed with table creation' />\n\t\t</form>\n\t\t"; $ns->tablerender('Step 2: Forum table creation', $text); return; } // FIXME - use db_verify. ?? require_once e_HANDLER . 'db_table_admin_class.php'; $db = new db_table_admin(); $tabList = array('forum' => 'forum_new', 'forum_thread' => '', 'forum_post' => '', 'forum_track' => ''); // $ret = ''; $failed = false; $text = ''; foreach ($tabList as $name => $rename) { $message = 'Creating table ' . ($rename ? $rename : $name); $result = $db->createTable(e_PLUGIN . 'forum/forum_sql.php', $name, true, $rename); if ($result === true) { $mes->addSuccess($message); // $text .= 'Success <br />'; } elseif ($result !== true) { // $text .= 'Failed <br />'; $mes->addError($message); $failed = true; } } if ($failed) { $mes->addError("Creation of table(s) failed. You can not continue until these are created successfully!"); } else { $text = "<form method='post' action='" . e_SELF . "?step=3'>\n\t\t\t<input class='btn btn-success' type='submit' name='nextStep[3]' value='Proceed to step 3' />\n\t\t\t</form>"; } $ns->tablerender('Step 2: Forum table creation', $mes->render() . $text); }
/** * 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 .= " <a href='" . $this->plugConfigFile . "'>[" . LAN_CONFIGURE . "]</a>"; } $mes->add($text, E_MESSAGE_SUCCESS); } } }