/** * perform queries from SQL dump file in a batch * * @param string $file file path to an SQL dump file * * @return bool FALSE if failed reading SQL file or TRUE if the file has been read and queries executed */ public function queryFromFile($file) { if (false !== ($fp = fopen($file, 'r'))) { $sql_queries = trim(fread($fp, filesize($file))); icms_db_legacy_mysql_Utility::splitMySqlFile($pieces, $sql_queries); foreach ($pieces as $query) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = icms_db_legacy_mysql_Utility::prefixQuery(trim($query), $this->prefix()); if ($prefixed_query != false) { $this->query($prefixed_query[0]); } } return true; } return false; }
function protector_oninstall_base($module, $mydirname) { // transations on module install global $ret; // TODO :-D // for Cube 2.1 if (defined('XOOPS_CUBE_LEGACY')) { $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_oninstall'); $ret = array(); } else { if (!is_array($ret)) { $ret = array(); } } $db =& icms_db_Factory::instance(); $mid = $module->getVar('mid'); // TABLES (loading mysql.sql) $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql'; $prefix_mod = $db->prefix() . '_' . $mydirname; if (file_exists($sql_file_path)) { $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables..."; $sqlutil = new icms_db_legacy_mysql_Utility(); $sql_query = trim(file_get_contents($sql_file_path)); $sqlutil->splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); if (!$prefixed_query) { $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />"; return false; } if (!$db->query($prefixed_query[0])) { $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />'; //var_dump( $db->error() ) ; return false; } else { if (!in_array($prefixed_query[4], $created_tables)) { $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />'; } } } } // TEMPLATES $tplfile_handler =& new icms_view_template_file_Handler(icms::$xoopsDB); $tpl_path = dirname(__FILE__) . '/templates'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) { $mtime = intval(@filemtime($file_path)); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_source', file_get_contents($file_path), true); $tplfile->setVar('tpl_refid', $mid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $mydirname . '_' . $file); $tplfile->setVar('tpl_desc', '', true); $tplfile->setVar('tpl_module', $mydirname); $tplfile->setVar('tpl_lastmodified', $mtime); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />'; } else { $tplid = $tplfile->getVar('tpl_id'); $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />'; // generate compiled file if (!icms_view_Tpl::template_touch($tplid)) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />'; } } } } closedir($handler); } /* Fixes Bug #619 : parse Error */ if (defined('ICMS_PRELOAD_PATH') && !file_exists(ICMS_PRELOAD_PATH . '/protector.php') && (!defined('PROTECTOR_POSTCHECK_INCLUDED') || !defined('PROTECTOR_PRECHECK_INCLUDED'))) { if (icms_core_Filesystem::copyRecursive(ICMS_TRUST_PATH . '/modules/protector/patches/ImpressCMS1.1/preload_protector.php', ICMS_PRELOAD_PATH . '/protector.php')) { $ret[] = 'Successfully moved protector preload<br />'; } else { $ret[] = icms_core_Message::error("Failed to move protector preload - your site is not protected.", "", FALSE); } } icms_view_Tpl::template_clear_module_cache($mid); return true; }
function xoops_module_install($dirname) { $dirname = trim($dirname); $db =& icms_db_Factory::instance(); $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $module_handler = icms::handler('icms_module'); if ($module_handler->getCount(new icms_db_criteria_Item('dirname', $dirname)) == 0) { $module =& $module_handler->create(); $module->loadInfoAsVar($dirname); $module->registerClassPath(); $module->setVar('weight', 1); $error = false; $errs = array(); $sqlfile =& $module->getInfo('sqlfile'); $msgs = array(); $msgs[] = '<h4 style="text-align:' . _GLOBAL_LEFT . ';margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<b>Version:</b> ' . icms_conv_nr2local($module->getInfo('version')); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author')); } $msgs[] = ''; $errs[] = '<h4 style="text-align:' . _GLOBAL_LEFT . ';margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($sqlfile != false && is_array($sqlfile)) { $sql_file_path = ICMS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $errs[] = "SQL file not found at <b>{$sql_file_path}</b>"; $error = true; } else { $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables..."; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); icms_db_legacy_mysql_Utility::splitSqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = icms_db_legacy_mysql_Utility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<b>{$piece}</b> is not a valid SQL!"; $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error(); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $msgs[] = ' Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.'; $created_tables[] = $prefixed_query[4]; } else { $msgs[] = ' Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.'; } } } else { // the table name is reserved, so halt the installation $errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!"; $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { //echo $ct; $db->query("DROP TABLE " . $db->prefix($ct)); } } } } // if no error, save the module info and blocks info associated with it if ($error == false) { if (!$module_handler->insert($module)) { $errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.'; foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . " " . _MD_AM_ERRORSC . "<br />"; foreach ($errs as $err) { $ret .= " - " . $err . "<br />"; } $ret .= "</p>"; unset($module); unset($created_tables); unset($errs); unset($msgs); return $ret; } else { $newmid = $module->getVar('mid'); unset($created_tables); $msgs[] = 'Module data inserted successfully. Module ID: <b>' . icms_conv_nr2local($newmid) . '</b>'; $tplfile_handler =& icms::handler('icms_view_template_file'); $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = 'Adding templates...'; foreach ($templates as $tpl) { $tplfile =& $tplfile_handler->create(); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file']); $tplfile->setVar('tpl_desc', $tpl['description'], true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = sprintf(' <span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>'); } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = sprintf(' ' . _MD_AM_TEMPLATE_INSERTED, '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newtplid . '</strong>'); // generate compiled file if (!icms_view_Tpl::template_touch($newtplid)) { $msgs[] = sprintf(' <span style="color:#ff0000;">' . _MD_AM_TEMPLATE_COMPILE_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newtplid . '</strong>'); } else { $msgs[] = sprintf(' ' . _MD_AM_TEMPLATE_COMPILED, '<strong>' . $tpl['file'] . '</strong>'); } } unset($tpldata); } } icms_view_Tpl::template_clear_module_cache($newmid); $blocks = $module->getInfo('blocks'); if ($blocks != false) { $msgs[] = 'Adding blocks...'; foreach ($blocks as $blockkey => $block) { // break the loop if missing block config if (!isset($block['file']) || !isset($block['show_func'])) { break; } $options = ''; if (!empty($block['options'])) { $options = trim($block['options']); } $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : ''; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], true); } if (empty($content)) { $content = ''; } else { $template = trim($block['template']); } $block_name = addslashes(trim($block['name'])); $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ('" . (int) $newbid . "', '" . (int) $newmid . "', '" . (int) $blockkey . "', '{$options}', '" . $block_name . "','" . $block_name . "', '', '1', '0', '0', 'M', 'H', '1', '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', '0', '" . time() . "')"; if (!$db->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block <b>' . $block['name'] . '</b> to the database! Database error: <b>' . $db->error() . '</b></span>'; } else { if (empty($newbid)) { $newbid = $db->getInsertId(); } $msgs[] = ' Block <b>' . $block['name'] . '</b> added. Block ID: <b>' . icms_conv_nr2local($newbid) . '</b>'; $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id,page_id) VALUES (' . (int) $newbid . ', 0,1)'; $db->query($sql); if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template']); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_desc', $block['description'], true); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = sprintf(' <span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $block['template'] . '</strong>'); } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = ' Template <b>' . $block['template'] . '</b> added to the database. (ID: <b>' . icms_conv_nr2local($newtplid) . '</b>)'; // generate compiled file if (!icms_view_Tpl::template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $block['template'] . '</b>.</span>'; } else { $msgs[] = ' Template <b>' . $block['template'] . '</b> compiled.</span>'; } } } } unset($content); } unset($blocks); } $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once ICMS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once ICMS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once ICMS_ROOT_PATH . '/include/notification_constants.php'; include_once ICMS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& icms_data_notification_Handler::categoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& icms_data_notification_Handler::categoryEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = 'Adding module config data...'; $config_handler = icms::handler('icms_config'); $order = 0; foreach ($configs as $config) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); $confobj->setConfValueForInput($config['default'], true); //$confobj->setVar('conf_value', $config['default'], true); $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>'; unset($confop); } } $order++; if ($config_handler->insertConfig($confobj) != false) { $msgs[] = ' Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>'; } unset($confobj); } unset($configs); } } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } // retrieve all block ids for this module $icms_block_handler = icms::handler('icms_view_block'); $blocks =& $icms_block_handler->getByModule($newmid, false); $msgs[] = 'Setting group rights...'; $gperm_handler = icms::handler('icms_member_groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>' . icms_conv_nr2local($mygroup) . '</b></span>'; } else { $msgs[] = ' Added admin access right for Group ID <b>' . icms_conv_nr2local($mygroup) . '</b>'; } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>' . icms_conv_nr2local($mygroup) . '</b></span>'; } else { $msgs[] = ' Added user access right for Group ID: <b>' . icms_conv_nr2local($mygroup) . '</b>'; } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . icms_conv_nr2local($blc) . '</b> Group ID: <b>' . icms_conv_nr2local($mygroup) . '</b></span>'; } else { $msgs[] = ' Added block access right. Block ID: <b>' . icms_conv_nr2local($blc) . '</b> Group ID: <b>' . icms_conv_nr2local($mygroup) . '</b>'; } unset($bperm); } } unset($blocks); unset($groups); // add module specific tasks to system autotasks list $atasks = $module->getInfo('autotasks'); $atasks_handler =& icms_getModuleHandler('autotasks', 'system'); if (isset($atasks) && is_array($atasks)) { foreach ($atasks as $taskID => $taskData) { $task =& $atasks_handler->create(); if (isset($taskData['enabled'])) { $task->setVar('sat_enabled', $taskData['enabled']); } if (isset($taskData['repeat'])) { $task->setVar('sat_repeat', $taskData['repeat']); } if (isset($taskData['interval'])) { $task->setVar('sat_interval', $taskData['interval']); } if (isset($taskData['onfinish'])) { $task->setVar('sat_onfinish', $taskData['onfinish']); } $task->setVar('sat_name', $taskData['name']); $task->setVar('sat_code', $taskData['code']); $task->setVar('sat_type', 'addon/' . $module->getInfo('dirname')); $task->setVar('sat_addon_id', (int) $taskID); if (!$atasks_handler->insert($task)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert autotask to db. Name: <b>' . $taskData['name'] . '</b></span>'; } else { $msgs[] = ' Added task to autotasks list. Task Name: <b>' . $taskData['name'] . '</b>'; } } } unset($atasks, $atasks_handler, $task, $taskData, $criteria, $items, $taskID); // execute module specific install script if any $install_script = $module->getInfo('onInstall'); $ModName = $module->getInfo('modname') != '' ? trim($module->getInfo('modname')) : $dirname; if (false != $install_script && trim($install_script) != '') { include_once ICMS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script); $is_IPF = $module->getInfo('object_items'); if (!empty($is_IPF)) { $icmsDatabaseUpdater = icms_db_legacy_Factory::getDatabaseUpdater(); $icmsDatabaseUpdater->moduleUpgrade($module, true); foreach ($icmsDatabaseUpdater->_messages as $msg) { $msgs[] = $msg; } } if (function_exists('xoops_module_install_' . $ModName)) { $func = 'xoops_module_install_' . $ModName; if (!($lastmsg = $func($module))) { $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>'); } else { $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>'); if (is_string($lastmsg)) { $msgs[] = $lastmsg; } } } elseif (function_exists('icms_module_install_' . $ModName)) { $func = 'icms_module_install_' . $ModName; if (!($lastmsg = $func($module))) { $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>'); } else { $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>'); if (is_string($lastmsg)) { $msgs[] = $lastmsg; } } } } $ret = '<p><code>'; foreach ($msgs as $m) { $ret .= $m . '<br />'; } unset($msgs); unset($errs); $ret .= '</code><br />' . sprintf(_MD_AM_OKINS, "<b>" . $module->getVar('name') . "</b>") . '</p>'; unset($module); return $ret; } else { $ret = '<p>'; foreach ($errs as $er) { $ret .= ' ' . $er . '<br />'; } unset($msgs); unset($errs); $ret .= '<br />' . sprintf(_MD_AM_FAILINS, '<b>' . $dirname . '</b>') . ' ' . _MD_AM_ERRORSC . '</p>'; return $ret; } } else { return "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $dirname . "</b>") . " " . _MD_AM_ERRORSC . "<br /> " . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>"; } }
function queryFromFile($sql_file_path) { $tables = array(); if (!file_exists($sql_file_path)) { return false; } $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); icms_db_legacy_mysql_Utility::splitSqlFile($pieces, $sql_query); $this->db->connect(); foreach ($pieces as $piece) { $piece = trim($piece); // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = icms_db_legacy_mysql_Utility::prefixQuery($piece, $this->db->prefix()); if ($prefixed_query != false) { $table = $this->db->prefix($prefixed_query[4]); if ($prefixed_query[1] == 'CREATE TABLE') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['create'][$table])) { $this->s_tables['create'][$table] = 1; } } else { if (!isset($this->f_tables['create'][$table])) { $this->f_tables['create'][$table] = 1; } } } elseif ($prefixed_query[1] == 'INSERT INTO') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['insert'][$table])) { $this->s_tables['insert'][$table] = 1; } else { $this->s_tables['insert'][$table]++; } } else { if (!isset($this->f_tables['insert'][$table])) { $this->f_tables['insert'][$table] = 1; } else { $this->f_tables['insert'][$table]++; } } } elseif ($prefixed_query[1] == 'ALTER TABLE') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['alter'][$table])) { $this->s_tables['alter'][$table] = 1; } } else { if (!isset($this->s_tables['alter'][$table])) { $this->f_tables['alter'][$table] = 1; } } } elseif ($prefixed_query[1] == 'DROP TABLE') { if ($this->db->query('DROP TABLE ' . $table) != false) { if (!isset($this->s_tables['drop'][$table])) { $this->s_tables['drop'][$table] = 1; } } else { if (!isset($this->s_tables['drop'][$table])) { $this->f_tables['drop'][$table] = 1; } } } } } return true; }