/** * Main class entry point * * @access public * @param object ipsRegistry reference */ public function doExecute(ipsRegistry $registry) { /* Require the right driver file */ require_once IPS_ROOT_PATH . 'applications/core/modules_admin/sql/' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '.php'; $dbdriver = new admin_core_sql_toolbox_module(); $dbdriver->makeRegistryShortcuts($registry); $dbdriver->doExecute($registry); }
/** * Main class entry point * * @param object ipsRegistry reference */ public function doExecute(ipsRegistry $registry) { /* Require the right driver file */ $classToLoad = IPSLib::loadActionOverloader(IPS_ROOT_PATH . 'applications/core/modules_admin/sql/' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '.php', 'admin_core_sql_toolbox_module'); /*noLibHook*/ $dbdriver = new $classToLoad(); $dbdriver->makeRegistryShortcuts($registry); $dbdriver->doExecute($registry); }
<?php /* +-------------------------------------------------------------------------- | IP.Board v3.4.5 | ======================================== | by Matthew Mecham | (c) 2001 - 2009 Invision Power Services | http://www.invisionpower.com | ======================================== | Web: http://www.invisionboard.com | Email: matt@invisionpower.com | Licence Info: http://www.invisionboard.com/?license +--------------------------------------------------------------------------- */ $PRE = trim(ipsRegistry::dbFunctions()->getPrefix()); $DB = ipsRegistry::DB(); $TABLE = 'dnames_change'; $SQL[] = "ALTER TABLE dnames_change CHANGE dname_ip_address dname_ip_address VARCHAR( 46 ) NOT NULL;";
/** * Creates Tables, Runs Inserts, and Indexes * * @return @e void */ public function sqlBasics() { /* INIT */ $vars = $this->getVars(); $output = array(); $errors = array(); $skipped = 0; $count = 0; /* Any "extra" configs required for this driver? */ if (is_file(IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php')) { require_once IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php'; /*noLibHook*/ $extra_install = new install_extra($this->registry); } //----------------------------------------- // Tables //----------------------------------------- $this->DB->return_die = 1; if (is_file($this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_tables.php')) { $TABLE = array(); include $this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_tables.php'; /*noLibHook*/ if (is_array($TABLE) and count($TABLE)) { foreach ($TABLE as $q) { //----------------------------------------- // Is this a create? //----------------------------------------- preg_match("/CREATE TABLE\\s+(\\S+)(\\s)?\\(/", str_ireplace('if not exists', '', $q), $match); if ($match[1] and $vars['dupe_tables'] == 'drop') { $this->DB->dropTable(str_replace($this->settings['sql_tbl_prefix'], '', $match[1])); } else { if ($match[1]) { if ($this->DB->getTableSchematic($match[1])) { $skipped++; continue; } } } //----------------------------------------- // Is this an alter? //----------------------------------------- preg_match("/ALTER\\s+TABLE\\s+(\\S+)\\s+ADD\\s+(\\S+)\\s+/i", $q, $match); if ($match[1] and $match[2] and $vars['dupe_tables'] == 'drop') { $this->DB->dropField(str_replace($this->settings['sql_tbl_prefix'], '', $match[1]), $match[2]); } else { if ($match[1] and $match[2]) { if ($this->DB->checkForField($match[2], $match[1])) { $skipped++; continue; } } } if ($extra_install and method_exists($extra_install, 'process_query_create')) { $q = $extra_install->process_query_create($q); } $this->DB->error = ''; $this->DB->query($q); if ($this->DB->error) { $errors[] = $q . "<br /><br />" . $this->DB->error; } else { $count++; } } } $output[] = sprintf($this->lang->words['redir__sql_tables'], $count, $skipped); } //--------------------------------------------- // Create the fulltext index... //--------------------------------------------- if ($this->DB->checkFulltextSupport()) { if (is_file($this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_fulltext.php')) { $INDEX = array(); include $this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_fulltext.php'; /*noLibHook*/ $count = 0; foreach ($INDEX as $q) { //--------------------------------------------- // Pass to handler //--------------------------------------------- if ($extra_install and method_exists($extra_install, 'process_query_index')) { $q = $extra_install->process_query_index($q); } //--------------------------------------------- // Pass query //--------------------------------------------- $this->DB->error = ''; $this->DB->query($q); if ($this->DB->error) { $errors[] = $q . "<br /><br />" . $this->DB->error; } else { $count++; } } $output[] = sprintf($this->lang->words['redir__sql_indexes'], $count); } } /* INSERTS */ if (is_file($this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_inserts.php')) { $INSERT = array(); $count = 0; /* Get the SQL File */ include $this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ipsRegistry::dbFunctions()->getDriverType()) . '_inserts.php'; /*noLibHook*/ foreach ($INSERT as $q) { /* Extra Handler */ if ($extra_install and method_exists($extra_install, 'process_query_insert')) { $q = $extra_install->process_query_insert($q); } $q = str_replace("<%time%>", time(), $q); $this->DB->error = ''; $this->DB->query($q); if ($this->DB->error) { $errors[] = $q . "<br /><br />" . $this->DB->error; } else { $count++; } } $output[] = sprintf($this->lang->words['redir__sql_inserts'], $count); } /* If we did no queries, show something here */ if (!count($output)) { $output[] = sprintf($this->lang->words['redir__sql_run'], 0); } /* Show Redirect... */ $this->showRedirectScreen($vars['app_directory'], $output, $errors, $this->getNextURL('sql_steps', $vars)); }
function step_21() { #$SQL[] = "alter table ".ipsRegistry::dbFunctions()->getPrefix()."posts drop index topic_id;"; $SQL[] = "alter table " . ipsRegistry::dbFunctions()->getPrefix() . "posts drop index author_id;"; #$SQL[] = "alter table ".ipsRegistry::dbFunctions()->getPrefix()."posts add index topic_id (topic_id, queued, pid);"; $SQL[] = "alter table " . ipsRegistry::dbFunctions()->getPrefix() . "posts add index author_id( author_id, topic_id);"; $SQL[] = "ALTER TABLE " . ipsRegistry::dbFunctions()->getPrefix() . "posts DROP INDEX forum_id, ADD INDEX(post_date);"; $this->error = array(); $this->sqlcount = 0; $output = ""; $this->DB->return_die = 1; foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; if (IPSSetUp::getSavedData('man')) { $output .= preg_replace("/\\sibf_(\\S+?)([\\s\\.,]|\$)/", " " . $this->DB->obj['sql_tbl_prefix'] . "\\1\\2", preg_replace("/\\s{1,}/", " ", $query)) . "\n\n"; } else { $this->DB->query($query); if ($this->DB->error) { $this->registry->output->addError($query . "<br /><br />" . $this->DB->error); } else { $this->sqlcount++; } } } $this->registry->output->addMessage("Optimization completed"); $this->request['workact'] = 'step_22'; if (IPSSetUp::getSavedData('man') and $output) { $this->_output = $this->registry->output->template()->upgrade_manual_queries($output); } unset($this->request['workact']); unset($this->request['st']); }
/* +-------------------------------------------------------------------------- | IP.Board v3.4.6 | ======================================== | by Matthew Mecham | (c) 2001 - 2004 Invision Power Services | http://www.invisionpower.com | ======================================== | Web: http://www.invisionboard.com | Email: matt@invisionpower.com | Licence Info: http://www.invisionboard.com/?license +--------------------------------------------------------------------------- */ # Member table updates # We use backticks on the second table to stop IPSSetUp::addPrefixToQuery() from stripping the prefix $SQL[] = "UPDATE members m, `" . trim(ipsRegistry::dbFunctions()->getPrefix()) . "members_converge` c SET m.members_pass_hash=c.converge_pass_hash WHERE c.converge_id=m.member_id;"; $SQL[] = "UPDATE members m, `" . trim(ipsRegistry::dbFunctions()->getPrefix()) . "members_converge` c SET m.members_pass_salt=c.converge_pass_salt WHERE c.converge_id=m.member_id;"; # Blank email addresses $SQL[] = "UPDATE members SET email=CONCAT( member_id, '-', UNIX_TIMESTAMP(), '@fakeemail.com' ) WHERE email='';"; # If we upgraded from 2.1.0ish then we may not have anything in profile_portal so... $count = ipsRegistry::DB()->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'profile_portal')); if (!$count['count']) { ipsRegistry::DB()->allow_sub_select = 1; $SQL[] = "INSERT INTO profile_portal (pp_member_id,notes,links,bio,ta_size,signature,avatar_location,avatar_size,avatar_type) SELECT id,notes,links,bio,ta_size,signature,avatar_location,avatar_size,avatar_type FROM `" . trim(ipsRegistry::dbFunctions()->getPrefix()) . "member_extra`"; } else { $SQL[] = "UPDATE profile_portal p, `" . trim(ipsRegistry::dbFunctions()->getPrefix()) . "member_extra` e SET p.notes=e.notes, p.links=e.links, p.bio=e.bio, p.ta_size=e.ta_size, p.signature=e.signature, p.avatar_location=e.avatar_location, p.avatar_size=e.avatar_size, p.avatar_type=e.avatar_type WHERE p.pp_member_id=e.id;"; } $SQL[] = "UPDATE profile_portal SET pp_setting_count_friends=5 WHERE pp_setting_count_friends=0;"; $SQL[] = "UPDATE profile_portal SET pp_setting_count_comments=10 WHERE pp_setting_count_comments=0;"; $SQL[] = "UPDATE profile_portal SET pp_setting_count_visitors=5 WHERE pp_setting_count_visitors=0;";
/** * Load cache(s) * * @param array Array of caches to load: array( 'group_cache', 'forum_cache' ) * @return mixed Loaded Cache * @access private * @author MattMecham */ private static function _loadCaches($caches = array()) { if (!is_array($caches) or !count($caches)) { return NULL; } //----------------------------------------- // Finalize //----------------------------------------- $cachelist = "'" . implode("','", $caches) . "'"; //-------------------------------- // Eaccelerator... //-------------------------------- if (is_object(self::$cacheLib)) { $temp_cache = array(); $new_cache_array = array(); foreach ($caches as $key) { $temp_cache[$key] = self::$cacheLib->getFromCache($key); if (!$temp_cache[$key]) { $new_cache_array[] = $key; } else { if (is_string($temp_cache[$key]) and strstr($temp_cache[$key], "a:") !== false) { self::instance()->data_store[$key] = unserialize($temp_cache[$key]); } else { if ($temp_cache[$key] == "EMPTY") { self::instance()->data_store[$key] = NULL; } else { self::instance()->data_store[$key] = $temp_cache[$key]; } } } } $cachearray = $new_cache_array; unset($new_cache_array, $temp_cache); } //-------------------------------- // Get from DB... //-------------------------------- if ($cachelist) { /* This is here for veeeeeery old 1.0.1 upgrades */ if (!ipsRegistry::DB()->checkForTable('cache_store')) { ipsRegistry::DB()->query("create table " . ipsRegistry::dbFunctions()->getPrefix() . "cache_store (\r\n\t\t\t\t\t\t cs_key varchar(255) NOT NULL default '',\r\n\t\t\t\t\t\t cs_value text NULL,\r\n\t\t\t\t\t\t cs_extra varchar(255) NOT NULL default '',\r\n\t\t\t\t\t\t PRIMARY KEY(cs_key)\r\n\t\t\t\t\t\t);"); } ipsRegistry::DB()->build(array('select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( {$cachelist} )")); ipsRegistry::DB()->execute(); $_seenKeys = array(); while ($r = ipsRegistry::DB()->fetch()) { $_seenKeys[$r['cs_key']] = $r['cs_key']; self::instance()->debugInfo[$r['cs_key']] = array('size' => IPSLib::strlenToBytes(strlen($r['cs_value']))); if ($r['cs_array'] or substr($r['cs_value'], 0, 2) == "a:") { self::instance()->data_store[$r['cs_key']] = unserialize($r['cs_value']); if (!is_array(self::instance()->data_store[$r['cs_key']])) { self::instance()->data_store[$r['cs_key']] = array(); } } else { self::instance()->data_store[$r['cs_key']] = $r['cs_value'] ? $r['cs_value'] : NULL; } if (is_object(self::$cacheLib)) { if (!$r['cs_value']) { $r['cs_value'] = "EMPTY"; } self::$cacheLib->putInCache($r['cs_key'], $r['cs_value']); } } } //----------------------------------------- // Make sure each key is in data_store otherwise // repeated calls will keep trying to load it //----------------------------------------- foreach ($caches as $_cache) { if (!in_array($_cache, $_seenKeys)) { self::instance()->data_store[$_cache] = NULL; } } }
/** * Remove an application * * @return @e void [Outputs to screen] */ public function applicationRemove() { //-------------------------------------------- // INIT //-------------------------------------------- $app_id = intval($this->request['app_id']); //----------------------------------------- // Got an application? //----------------------------------------- $application = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_applications', 'where' => 'app_id=' . $app_id)); if (!$application['app_id']) { $this->registry->output->global_message = $this->lang->words['a_noid']; $this->applicationsOverview(); return; } //----------------------------------------- // Protected? //----------------------------------------- if (!IN_DEV and $application['app_protected']) { $this->registry->output->global_message = $this->lang->words['a_protectapp']; $this->applicationsOverview(); return; } //----------------------------------------- // Remove Settings //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'core_sys_settings_titles', 'where' => "conf_title_app='{$application['app_directory']}'")); $this->DB->execute(); $conf_title_id = array(); while ($r = $this->DB->fetch()) { $conf_title_id[] = $r['conf_title_id']; } if (count($conf_title_id)) { $this->DB->delete('core_sys_conf_settings', 'conf_group IN(' . implode(',', $conf_title_id) . ')'); } $this->DB->delete('core_sys_settings_titles', "conf_title_app='{$application['app_directory']}'"); $settingsFile = IPSLib::getAppDir($application['app_directory']) . '/xml/' . $application['app_directory'] . '_settings.xml'; if (is_file($settingsFile)) { require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML(IPS_DOC_CHAR_SET); $xml->load($settingsFile); $keys = array(); foreach ($xml->fetchElements('setting') as $setting) { $entry = $xml->fetchElementsFromRecord($setting); if ($entry['conf_is_title']) { continue; } $keys[] = "'{$entry['conf_key']}'"; } if (!empty($keys)) { $this->DB->delete('core_sys_conf_settings', 'conf_key IN(' . implode(',', $keys) . ')'); } } //----------------------------------------- // Remove Application Caches //----------------------------------------- $_file = IPSLib::getAppDir($application['app_directory']) . '/extensions/coreVariables.php'; if (is_file($_file)) { $CACHE = array(); require $_file; /*noLibHook*/ if (is_array($CACHE) and count($CACHE)) { foreach ($CACHE as $key => $data) { $this->DB->delete('cache_store', "cs_key='{$key}'"); } } } //----------------------------------------- // Remove tables //----------------------------------------- $_file = IPSLib::getAppDir($application['app_directory']) . '/setup/versions/install/sql/' . $application['app_directory'] . '_' . ipsRegistry::dbFunctions()->getDriverType() . '_tables.php'; if (is_file($_file)) { $TABLE = array(); require $_file; /*noLibHook*/ foreach ($TABLE as $q) { //----------------------------------------- // Capture create tables first //----------------------------------------- preg_match("/CREATE TABLE (\\S+)(\\s)?\\(/", $q, $match); if ($match[1]) { $_table = preg_replace('#^' . ipsRegistry::dbFunctions()->getPrefix() . "(\\S+)#", "\\1", $match[1]); $this->DB->dropTable($_table); } else { //----------------------------------------- // Then capture alter tables //----------------------------------------- preg_match("/ALTER TABLE (\\S+)\\sADD\\s(\\S+)\\s/i", $q, $match); if ($match[1] and $match[2]) { $_table = preg_replace('#^' . ipsRegistry::dbFunctions()->getPrefix() . "(\\S+)#", "\\1", $match[1]); $_field = $match[2]; /* check for field */ if ($this->DB->checkForField($_field, $_table)) { $this->DB->dropField($_table, $_field); } } } } } //----------------------------------------- // Check for uninstall sql //----------------------------------------- /* Any "extra" configs required for this driver? */ if (is_file(IPS_ROOT_PATH . 'setup/sql/' . $this->settings['sql_driver'] . '_install.php')) { require_once IPS_ROOT_PATH . 'setup/sql/' . $this->settings['sql_driver'] . '_install.php'; /*noLibHook*/ $extra_install = new install_extra($this->registry); } $_file = IPSLib::getAppDir($application['app_directory']) . '/setup/versions/install/sql/' . $application['app_directory'] . '_' . ipsRegistry::dbFunctions()->getDriverType() . '_uninstall.php'; if (is_file($_file)) { $QUERY = array(); require $_file; /*noLibHook*/ if (is_array($QUERY) and count($QUERY)) { foreach ($QUERY as $q) { if ($extra_install and method_exists($extra_install, 'process_query_create')) { $q = $extra_install->process_query_create($q); } $this->DB->query($q); } } } //----------------------------------------- // Remove Misc Stuff //----------------------------------------- $this->DB->delete('core_sys_lang_words', "word_app='{$application['app_directory']}'"); $this->DB->delete('task_manager', "task_application='{$application['app_directory']}'"); $this->DB->delete('permission_index', "app='{$application['app_directory']}'"); $this->DB->delete('reputation_index', "app='{$application['app_directory']}'"); $this->DB->delete('reputation_cache', "app='{$application['app_directory']}'"); $this->DB->delete('core_tags', "tag_meta_app='{$application['app_directory']}'"); $this->DB->delete('faq', "app='{$application['app_directory']}'"); $this->DB->delete('custom_bbcode', "bbcode_app='{$application['app_directory']}'"); $this->DB->delete('upgrade_history', "upgrade_app='{$application['app_directory']}'"); $this->DB->delete('core_like_cache', "like_cache_app='{$application['app_directory']}'"); $this->DB->delete('core_like', "like_app='{$application['app_directory']}'"); $this->DB->delete('core_item_markers', "item_app='{$application['app_directory']}'"); //----------------------------------------- // Report center.. //----------------------------------------- $plugin = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'rc_classes', 'where' => "app='{$application['app_directory']}'")); if ($plugin['com_id']) { $this->DB->build(array('select' => '*', 'from' => 'rc_reports_index', 'where' => 'rc_class=' . $plugin['com_id'])); $outer = $this->DB->execute(); while ($r = $this->DB->fetch($outer)) { $this->DB->delete('rc_reports', "rid=" . $r['id']); $this->DB->delete('rc_comments', "rid=" . $r['id']); } $this->DB->delete('rc_reports_index', 'rc_class=' . $plugin['com_id']); $this->DB->delete('rc_classes', 'com_id=' . $plugin['com_id']); } //----------------------------------------- // Attachments //----------------------------------------- $_plugins = array(); try { foreach (new DirectoryIterator(IPSLib::getAppDir($application['app_directory']) . '/extensions/attachments/') as $file) { if (!$file->isDot() && $file->isFile()) { if (preg_match("/^plugin_(.+?)\\.php\$/", $file->getFileName(), $matches)) { $_plugins[] = $matches[1]; } } } if (count($_plugins)) { foreach ($_plugins as $_plugin) { $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module='{$_plugin}'")); $outer = $this->DB->execute(); while ($r = $this->DB->fetch($outer)) { if (is_file($this->settings['upload_dir'] . "/" . $r['attach_location'])) { @unlink($this->settings['upload_dir'] . "/" . $r['attach_location']); } } $this->DB->delete('attachments', "attach_rel_module='{$_plugin}'"); } } } catch (Exception $e) { } //----------------------------------------- // Get all hook files //----------------------------------------- if (is_dir(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks')) { $files = scandir(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks'); $hooks = array(); require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML(IPS_DOC_CHAR_SET); if (count($files) and is_array($files)) { foreach ($files as $_hookFile) { if ($_hookFile != '.' and $_hookFile != '..' and preg_match("/(\\.xml)\$/", $_hookFile)) { $xml->loadXML(file_get_contents(IPSLib::getAppDir($application['app_directory']) . '/xml/hooks/' . $_hookFile)); foreach ($xml->fetchElements('config') as $data) { $config = $xml->fetchElementsFromRecord($data); if (!count($config)) { continue; } else { $hooks[] = $config['hook_key']; } } } } } if (count($hooks)) { foreach ($hooks as $hook) { $hook = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_hooks', 'where' => "hook_key='" . $hook . "'")); if (!$hook['hook_id']) { continue; } $this->DB->delete('core_hooks', "hook_id={$hook['hook_id']}"); /* Get associated files */ $this->DB->build(array('select' => 'hook_file_stored', 'from' => 'core_hooks_files', 'where' => 'hook_hook_id=' . $hook['hook_id'])); $this->DB->execute(); while ($r = $this->DB->fetch()) { @unlink(IPS_HOOKS_PATH . $r['hook_file_stored']); } /* Delete hook file entries */ $this->DB->delete('core_hooks_files', "hook_hook_id={$hook['hook_id']}"); } $this->cache->rebuildCache('hooks', 'global'); } } //----------------------------------------- // Remove Files //----------------------------------------- /* Languages */ try { foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'cache/lang_cache/') as $dir) { if (!$dir->isDot() && intval($dir->getFileName())) { foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'cache/lang_cache/' . $dir->getFileName() . '/') as $file) { if (!$file->isDot()) { if (preg_match("/^({$application['app_directory']}_)/", $file->getFileName())) { unlink($file->getPathName()); } } } } } } catch (Exception $e) { } /* Remove Skins */ if (is_file(IPSLib::getAppDir($application['app_directory']) . '/xml/information.xml')) { require_once IPS_KERNEL_PATH . 'classXML.php'; /*noLibHook*/ $xml = new classXML($this->settings['gb_char_set']); $xml->load(IPSLib::getAppDir($application['app_directory']) . '/xml/information.xml'); if (is_object($xml->fetchElements('template'))) { foreach ($xml->fetchElements('template') as $template) { $name = $xml->fetchItem($template); $match = $xml->fetchAttribute($template, 'match'); if ($name) { $templateGroups[$name] = $match; } } } if (is_array($templateGroups) and count($templateGroups)) { /* Loop through skin directories */ try { foreach (new DirectoryIterator(IPS_CACHE_PATH . 'cache/skin_cache/') as $dir) { if (preg_match("/^(cacheid_)/", $dir->getFileName())) { foreach (new DirectoryIterator(IPS_CACHE_PATH . 'cache/skin_cache/' . $dir->getFileName() . '/') as $file) { if (!$file->isDot()) { foreach ($templateGroups as $name => $match) { if ($match == 'contains') { if (stristr($file->getFileName(), $name)) { unlink($file->getPathName()); } } else { if ($file->getFileName() == $name . '.php') { unlink($file->getPathName()); } } } } } } } } catch (Exception $e) { } /* Delete from database */ foreach ($templateGroups as $name => $match) { if ($match == 'contains') { $this->DB->delete('skin_templates', "template_group LIKE '%{$name}%'"); $this->DB->delete('skin_templates_previous', "p_template_group LIKE '%{$name}%'"); $this->DB->delete('skin_cache', "cache_type='phptemplate' AND cache_value_1 LIKE '%{$name}%'"); } else { $this->DB->delete('skin_templates', "template_group='{$name}'"); $this->DB->delete('skin_templates_previous', "p_template_group='{$name}'"); $this->DB->delete('skin_cache', "cache_type='phptemplate' AND cache_value_1='{$name}'"); } } } } /* CSS files */ $css_files = array(); $this->DB->build(array('select' => '*', 'from' => 'skin_css', 'where' => "css_app='" . $application['app_directory'] . "'")); $this->DB->execute(); while ($r = $this->DB->fetch()) { $css_files[$r['css_group']] = $r['css_group']; } if (count($css_files)) { $this->DB->delete('skin_css', "css_app='" . $application['app_directory'] . "'"); $this->DB->delete('skin_cache', "cache_type='css' AND cache_value_1 IN('" . implode("','", $css_files) . "')"); try { foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/') as $dir) { if (preg_match("/^(css_)/", $dir->getFileName())) { foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_css/' . $dir->getFileName() . '/') as $file) { if (!$file->isDot()) { foreach ($css_files as $css_file) { if ($file->getFileName() == $css_file . '.css') { unlink($file->getPathName()); } } } } } } } catch (Exception $e) { } } //----------------------------------------- // Remove Modules //----------------------------------------- $this->DB->delete('core_sys_module', "sys_module_application='{$application['app_directory']}'"); //----------------------------------------- // Remove Application //----------------------------------------- $this->DB->delete('core_applications', 'app_id=' . $app_id); //----------------------------------------- // Recache //----------------------------------------- $this->moduleRecacheAll(1); $this->cache->rebuildCache('settings', 'global'); $this->cache->rebuildCache('notifications', 'global'); /* Delete from upgrade */ $this->DB->delete('upgrade_history', "upgrade_app='{$application['app_directory']}'"); //----------------------------------------- // FURL templates //----------------------------------------- try { IPSLib::cacheFurlTemplates(); IPSLib::cacheGlobalCaches(); } catch (Exception $e) { } //----------------------------------------- // Sphinx involved? //----------------------------------------- if ($this->settings['search_method'] == 'sphinx') { $this->registry->output->global_message .= sprintf($this->lang->words['rebuild_sphinx'], $this->settings['_base_url']); } //----------------------------------------- // Done... //----------------------------------------- $this->registry->output->global_message = $this->lang->words['a_appremoved']; $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=applications_overview'); }
/** * Restore posts * @param array $where */ public function restoreRecentPost($where) { $date = IPS_UNIX_TIME_NOW - 86400; $PRE = trim(ipsRegistry::dbFunctions()->getPrefix()); $query = array(); $remap = array('post_id' => 'pid', 'post_topic_id' => 'topic_id', 'post_author_id' => 'post_author_id'); foreach (array('post_id', 'post_topic_id', 'post_forum_id', 'post_author_id') as $k) { if (!empty($where[$k])) { $query[] = is_array($where[$k]) ? $remap[$k] . ' IN (' . implode(',', $where[$k]) . ')' : $remap[$k] . '=' . intval($where[$k]); } } if (count($query)) { $this->DB->loadCacheFile(IPSLib::getAppDir('forums') . '/sql/' . ips_DBRegistry::getDriverType() . '_topics_queries.php', 'topics_sql_queries'); $this->DB->buildFromCache('restoreRecentPost', array('query' => $query, 'date' => $date), 'topics_sql_queries'); $this->DB->allow_sub_select = true; $this->DB->execute(); } }
/** * Run this task * * @return @e void */ public function runTask() { /* Not needed for mssql as per #23105 bug */ if (ipsRegistry::dbFunctions()->getDriverType() != 'mysql') { $this->class->unlockTask($this->task); return; } /* Get tables and optimize */ $tables = $this->charlesTables; $_tables = array(); if (is_array($tables) and count($tables)) { /* InnoDB is a no-no! :o */ $this->DB->query("SHOW TABLE STATUS"); while ($tbl = $this->DB->fetch()) { if (!empty($tbl['Name']) && in_array(preg_replace('#^' . ipsRegistry::$settings['sql_tbl_prefix'] . '(.+?)#', "\\1", $tbl['Name']), $tables) && strtolower($tbl['Engine']) != 'innodb') { $_tables[] = $tbl['Name']; } } /* Was everything a no-no? :( */ if (count($_tables)) { $PRE = ipsRegistry::dbFunctions()->getPrefix(); foreach ($_tables as $_table) { $this->DB->query("OPTIMIZE TABLE {$PRE}{$_table}"); $this->DB->query("ANALYZE TABLE {$PRE}{$_table}"); } } } /* Log to log table - modify but dont delete */ $this->registry->getClass('class_localization')->loadLanguageFile(array('public_global'), 'core'); $this->class->appendTaskLog($this->task, sprintf($this->lang->words['task__optimizedtables'], count($_tables))); /* Unlock Task: DO NOT MODIFY! */ $this->class->unlockTask($this->task); }
/** * Convert an image * * @access public * @param integer Foreign ID number * @param array Data to insert to table * @param string Path to where images are stores * @param boolean If true, loads file data from database, rather than move file * @return boolean Success or fail **/ public function convertImage($id, $info, $path, $db = false, $parent = false) { // First remap for gallery 5 foreach ($info as $k => $v) { if (isset($this->_imageRemap[$k])) { $info[$this->_imageRemap[$k]] = $v; unset($info[$k]); } else { $info[$k] = $v; } } unset($info['image_id']); // Check we have a path //if (!$this->settings['gallery_images_path']) //{ // $this->logError($id, 'Your IP.Gallery uploads path has not been configured'); // return false; //} if (!file_exists($this->settings['gallery_images_path'] . '/gallery')) { if (!mkdir($this->settings['gallery_images_path'] . '/gallery', 0777)) { $this->error('"gallery" folder does not exist in the uploads directory.'); return false; } } if (!is_writable($this->settings['gallery_images_path'])) { $this->error('"gallery" folder is not writable.'); return false; } //----------------------------------------- // Make sure we have everything we need //----------------------------------------- if (!$id) { $this->logError($id, 'No ID number provided'); return false; } // Need image path if was not stored in database if (!$path and !$db) { $this->logError($id, 'No path provided'); return false; } // Be sure to have member id if (!$info['image_member_id']) { $this->logError($id, 'No member ID provided'); return false; } // Need to store in either category or album if (!$info['image_album_id']) { $this->logError($id, 'No album ID provided'); return false; } // Check if a masked name was provided. If not, just use the filename. $info['image_masked_file_name'] = $info['image_masked_file_name'] ? $info['image_masked_file_name'] : $info['image_file_name']; if (!$db and !$info['image_masked_file_name']) { $this->logError($id, 'No filename provided'); return false; } // Make sure image data was provided if stored in database. if ($db && !$info['image_data']) { $this->logError($id, 'No file data provided'); return false; } if (isset($info['image_directory']) && $info['image_directory'] != '') { $oldPath = $path; $path = $path . '/' . trim($info['image_directory'], '/'); } // Check the file actually exists if (!$db && !file_exists($path . '/' . $info['image_masked_file_name'])) { if (!file_exists($oldPath . '/' . $info['image_masked_file_name'])) { $this->logError($id, 'Could not locate file ' . $path . '/' . $info['image_masked_file_name']); return false; } $path = $oldPath; } $albumID = $this->getLink($info['image_album_id'], 'gallery_albums', true); if ($albumID) { if (isset($info['image_category_id'])) { $categoryID = $this->getLink($info['image_category_id'], 'gallery_categories', true); $info['image_category_id'] = $categoryID; } else { $info['image_category_id'] = ipsRegistry::$settings['gallery_members_album']; } $info['image_album_id'] = $albumID; } else { $info['image_category_id'] = $this->getLink($info['image_album_id'], 'gallery_categories'); $info['image_album_id'] = 0; } //----------------------------------------- // Set up array //----------------------------------------- $imageArray = array('image_member_id' => $this->getLink($info['image_member_id'], 'members', false, $this->useLocalLink), 'image_album_id' => $info['image_album_id'], 'image_category_id' => $info['image_category_id'], 'image_caption' => $info['image_caption'] ? $info['image_caption'] : 'No caption', 'image_description' => $info['image_description'], 'image_directory' => '', 'image_file_name' => $info['image_file_name'], 'image_approved' => $info['image_approved'], 'image_thumbnail' => 0, 'image_views' => intval($info['image_views']), 'image_comments' => intval($info['image_comments']), 'image_date' => intval($info['image_date']), 'image_ratings_total' => intval($info['image_ratings_total']), 'image_ratings_count' => intval($info['image_ratings_count']), 'image_caption_seo' => IPSText::makeSeoTitle($info['image_caption']), 'image_notes' => $info['image_notes'], 'image_rating' => intval($info['image_ratings_total']) > 0 ? intval($info['image_ratings_total']) / intval($info['image_ratings_count']) : 0, 'image_privacy' => $info['image_privacy']); if (!isset($info['image_file_size'])) { $imageArray['image_file_size'] = @filesize($path . '/' . $info['image_masked_file_name']); } else { $imageArray['image_file_size'] = $info['image_file_size']; } // Fields still required = array( 'file_name', 'file_type', 'masked_file_name', 'medium_file_name'); // Fields optional = array( 'file_size', 'pinned', 'media', 'credit_info', 'metadata', 'media_thumb'); $_file = IPSLib::getAppDir('gallery') . '/app_class_gallery.php'; $_name = 'app_class_gallery'; $galleryLibObject = null; if (file_exists($_file)) { $classToLoad = IPSLib::loadLibrary($_file, $_name); $galleryLibObject = new $classToLoad($this->registry); } require_once IPS_KERNEL_PATH . 'classUpload.php'; $upload = new classUpload(); $dir = $this->registry->gallery->helper('upload')->createDirectoryName($imageArray['image_album_id'], $imageArray['image_category_id']); if (!is_dir($this->settings['gallery_images_path'] . DIRECTORY_SEPARATOR . $dir)) { $this->error('Could not create directory to store images, please check <b>permissions (0777)</b> and <b>ownership</b> on "' . $this->settings['gallery_images_path'] . '/gallery/"'); } $ext = $upload->_getFileExtension($info['image_file_name']); $container = $imageArray['image_category_id']; if ($imageArray['image_album_id']) { $container = $imageArray['image_album_id']; } $new_name = "gallery_{$info['image_member_id']}_" . $container . "_" . time() . '_' . $id . '.' . $ext; $imageArray['image_masked_file_name'] = $new_name; $new_file = $this->settings['gallery_images_path'] . '/' . $dir . '/' . $new_name; // stop image_directory being category_ and album_ if (($imageArray['image_album_id'] != 0 || isset($imageArray['image_album_id']) || !empty($imageArray['image_album_id'])) && ($imageArray['image_category_id'] != 0 || isset($imageArray['image_category_id']) || !empty($imageArray['image_category_id']))) { // Set directory $imageArray['image_directory'] = $imageArray['image_album_id'] ? 'gallery/album_' . $imageArray['image_album_id'] : 'gallery/category_' . $imageArray['image_category_id']; } else { $imageArray['image_directory'] = ''; } if ($imageArray['image_directory'] == 'gallery/category_' || $imageArray['image_directory'] == 'gallery/album_') { $imageArray['image_directory'] = ''; } // Create the file from the db if that's the case if ($db) { $this->createFile($new_name, $info['image_data'], $info['image_file_size'], $this->settings['gallery_images_path'] . '/' . substr($dir, 0, -1)); } else { // Copy the file to its end IP.Gallery location if (!@copy($path . '/' . $info['image_masked_file_name'], $new_file)) { $e = error_get_last(); $this->logError($id, 'Could not move file - attempted to move ' . $path . '/' . $info['image_masked_file_name'] . ' to ' . $new_file . '<br />' . $e['message'] . '<br /><br />'); return false; } } @chmod($new_file, 0777); if (method_exists($upload, 'check_xss_infile')) { $upload->saved_upload_name = $new_file; $upload->check_xss_infile(); if ($upload->error_no == 5) { $this->logError($id, 'Invalid XSS file: ' . $info['image_file_name'] . '<br /><br />'); return false; } } //------------------------------------------------------------- // Exif/IPTC support? //------------------------------------------------------------- $meta_data = array(); if ($this->settings['gallery_exif']) { $meta_data = array_merge($meta_data, $this->registry->gallery->helper('image')->extractExif($new_file)); } if ($this->settings['gallery_iptc']) { $meta_data = array_merge($meta_data, $this->registry->gallery->helper('image')->extractIptc($new_file)); } $imageArray['image_metadata'] = serialize($meta_data); //------------------------------------------------------------- // Pass to library //------------------------------------------------------------- $media = 0; $imageArray['image_media'] = $this->_isImage($ext) ? 0 : 1; $imageArray['image_medium_file_name'] = 'med_' . $new_name; $imageArray['image_file_type'] = $this->registry->gallery->helper('image')->getImageType($new_file); // Go $this->DB->insert('gallery_images', $imageArray); $inserted_id = $this->DB->getInsertId(); // Permissions $prefix = ipsRegistry::dbFunctions()->getPrefix(); $this->DB->query("UPDATE {$prefix}gallery_images i, {$prefix}permission_index p SET i.image_parent_permission=p.perm_view WHERE p.app='gallery' AND p.perm_type='categories' AND p.perm_type_id=i.image_category_id"); //----------------------------------------- // Add link //----------------------------------------- $this->addLink($inserted_id, $id, 'gallery_images'); return true; }
public static function updateThree($gender) { $DB = ipsRegistry::DB(); $PRE = ipsRegistry::dbFunctions()->getPrefix(); return "UPDATE {$PRE}profile_portal pp, {$PRE}pfields_content pfc SET pfc.field_{$gender['pf_id']}='m' WHERE pp.pp_gender='male' AND pp.pp_member_id=pfc.member_id"; }
/** * Class entry point * * @param object Registry reference * @return @e void [Outputs to screen] */ public function doExecute(ipsRegistry $registry) { //----------------------------------------- // Get supported applications //----------------------------------------- $supportedApps = array(); foreach (IPSLib::getEnabledApplications() as $app) { $file = IPSLib::getAppDir($app['app_directory']) . '/extensions/reputation.php'; if (is_file($file)) { require_once $file; /*maybeLibHook*/ if (class_exists('reputation_' . $app['app_directory'])) { $supportedApps[$app['app_directory']] = $app; } } } //----------------------------------------- // Get results //----------------------------------------- /* What is it we're getting? */ $app = (is_string($this->request['app_tab']) && !empty($this->request['app_tab']) and isset($supportedApps[$this->request['app_tab']])) ? $this->request['app_tab'] : 'forums'; /* Load our extension class */ $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir($app) . '/extensions/reputation.php', 'reputation_' . $app, $app); $reputationClass = new $classToLoad(); /* Get our query */ $_query = $reputationClass->fetch('most'); $PRE = trim(ipsRegistry::dbFunctions()->getPrefix()); /* Got something? */ if ($_query['inner']) { /* Build inner join */ $this->DB->build($_query['inner']); $inner = $this->DB->fetchSqlString(); $this->DB->flushQuery(); $this->DB->allow_sub_select = 1; $this->DB->query('SELECT * FROM ' . $PRE . "reputation_totals WHERE rt_app_type=MD5( CONCAT( '" . $app . "', ';', '" . $_query['type'] . "' ) ) AND rt_type_id IN (" . $inner . ") AND rt_total > 0 GROUP BY rt_key ORDER BY rt_total DESC LIMIT 0," . self::NUMBER_TO_SHOW); $this->DB->execute(); $typeIds = array(); $results = array(); $index = array(); while ($row = $this->DB->fetch()) { $typeIds[$row['rt_total'] . '.' . $row['rt_type_id']] = $row['rt_type_id']; $index[$row['rt_type_id']] = $row['rt_total'] . '.' . $row['rt_type_id']; } if (count($typeIds)) { $this->DB->build(array('select' => 'r.*', 'from' => array('reputation_index' => 'r'), 'where' => "r.app='" . $app . "' AND r.type='" . $_query['type'] . "' AND r.type_id IN (" . implode(',', array_values($typeIds)) . ")", 'group' => 'r.app, r.type, r.type_id', 'add_join' => $_query['joins'])); $e = $this->DB->execute(); while ($row = $this->DB->fetch($e)) { $results[$index[$row['type_id']]] = $reputationClass->process($row); } krsort($results); } } //----------------------------------------- // Output //----------------------------------------- /* Process Results */ $processedResults = count($results) ? $reputationClass->display($results) : ''; $this->lang->loadLanguageFile(array('public_profile'), 'members'); /* Setup page */ $langBit = ipsRegistry::$settings['reputation_point_types'] == 'like' ? 'most_rep_likes' : 'most_rep_rep'; $this->registry->output->setTitle($this->lang->words[$langBit] . ' - ' . IPSLib::getAppTitle($app)); $this->registry->output->addNavigation($this->lang->words[$langBit], NULL); /* Display processed results */ $this->registry->output->addContent($this->registry->getClass('output')->getTemplate('profile')->reputationPage($langBit, $app, $supportedApps, $processedResults)); $this->registry->output->sendOutput(); }