예제 #1
0
 /**
  * Installs SQL schematic
  *
  * @return void
  */
 public function install_sql()
 {
     /* Lets grab that SQL! */
     $SQL = array();
     $count = 0;
     $output = '';
     $message = array();
     $sourceFile = '';
     $warnings = 0;
     /* Reset Errors */
     $this->_resetErrors();
     /* SQL */
     $file = IPSLib::getAppDir($this->_currentApp) . '/setup/versions/upg_' . $this->_uipLong . '/' . $this->_dbDriver . '_updates.php';
     /* Get file */
     if (is_file($file)) {
         require $file;
         /*noLibHook*/
         if (is_array($SQL) and count($SQL) > 0) {
             /* Loop */
             foreach ($SQL as $q) {
                 /* Set DB driver to return any errors */
                 $this->DB->return_die = 1;
                 $this->DB->allow_sub_select = 1;
                 $this->DB->error = '';
                 $q = str_replace("<%time%>", time(), $q);
                 $q = IPSSetUp::addPrefixToQuery($q, $this->registry->dbFunctions()->getPrefix());
                 if ($this->settings['mysql_tbl_type']) {
                     if (preg_match("/^create table(.+?)/i", $q)) {
                         $q = preg_replace("/^(.+?)\\);\$/is", "\\1) ENGINE={$this->settings['mysql_tbl_type']};", $q);
                     }
                 }
                 if (IPSSetUp::getSavedData('man')) {
                     $q = trim($q);
                     /* Ensure the last character is a semi-colon */
                     if (substr($q, -1) != ';') {
                         $q .= ';';
                     }
                     $output .= $q . "\n\n";
                 } else {
                     $this->DB->query($q);
                     if ($this->DB->error) {
                         /* Log but do not fail on certain error logs */
                         $msg = $this->DB->error;
                         if (preg_match("#table.*already exists#i", $msg) or preg_match("#Duplicate column name#i", $msg) or preg_match("#Duplicate entry.*for#i", $msg)) {
                             $warnings++;
                             IPSSetUp::addLogMessage("SQL Error: " . $q . "\n" . $msg, $this->_uipLong, $this->_currentApp);
                         } else {
                             $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error);
                         }
                     } else {
                         $count++;
                     }
                 }
             }
             $message[] = $count . " запросов выполнено ({$warnings} не критичных ошибок)";
         }
     } else {
         /* No SQL */
         //$this->registry->output->addMessage("Нет SQL запросов для выполнения.");
         $this->install_appclass();
         return;
     }
     /* Got queries to show? */
     if (IPSSetUp::getSavedData('man') and $output) {
         /* Create source file */
         if ($this->_dbDriver == 'mysql') {
             $sourceFile = IPSSetUp::createSqlSourceFile($output, $this->_uipLong);
         }
         $this->registry->output->setTitle("Обновление: База Данных");
         $this->registry->output->setNextAction('upgrade&do=appclass');
         $this->registry->output->addContent($this->registry->output->template()->upgrade_manual_queries($output, $sourceFile));
         $this->registry->output->sendOutput();
     } else {
         //-----------------------------------------
         // Next...
         //-----------------------------------------
         $output = (is_array($message) and count($message)) ? $message : array(0 => "Обновление Базы Данных завершено");
         $this->_finishStep($output, "Обновление: База Данных", 'upgrade&do=appclass');
     }
 }
예제 #2
0
 /**
  * Sort out bbcode and permissions
  * 
  * @return	@e void
  */
 public function permsAndBbcode()
 {
     /* INIT */
     $options = IPSSetUp::getSavedData('custom_options');
     $rootAdmins = $options['core'][30001]['rootAdmins'];
     /* First off, import default BBCode */
     $apps = array();
     $bbcodeOld = array();
     $bbcodeNew = array();
     /* Load apps */
     $this->DB->build(array('select' => '*', 'from' => 'core_applications'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $apps[$row['app_directory']] = $row;
     }
     /* Load old codes */
     $this->DB->build(array('select' => '*', 'from' => 'custom_bbcode_old'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $bbcodeOld[$row['bbcode_tag']] = $row;
     }
     /* Add 'em */
     foreach ($apps as $dir => $data) {
         if (is_file(IPSLib::getAppDir($dir) . '/xml/' . $dir . '_bbcode.xml')) {
             //-----------------------------------------
             // Continue
             //-----------------------------------------
             $classToLoad = IPSLib::loadActionOverloader(IPS_ROOT_PATH . 'applications/core/modules_admin/posts/bbcode.php', 'admin_core_posts_bbcode');
             $bbcode = new $classToLoad();
             $bbcode->makeRegistryShortcuts($this->registry);
             $bbcode->bbcodeImportDo(file_get_contents(IPSLib::getAppDir($dir) . '/xml/' . $dir . '_bbcode.xml'));
         }
         if (is_file(IPSLib::getAppDir($dir) . '/xml/' . $dir . '_mediatag.xml')) {
             //-----------------------------------------
             // Continue
             //-----------------------------------------
             $classToLoad = IPSLib::loadActionOverloader(IPS_ROOT_PATH . 'applications/core/modules_admin/posts/media.php', 'admin_core_posts_media');
             $bbcode = new $classToLoad();
             $bbcode->makeRegistryShortcuts($this->registry);
             $bbcode->doMediaImport(file_get_contents(IPSLib::getAppDir($dir) . '/xml/' . $dir . '_mediatag.xml'));
         }
     }
     /* Load current code */
     $this->DB->build(array('select' => '*', 'from' => 'custom_bbcode'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $bbcodeCurrent[$row['bbcode_tag']] = $row;
         //-----------------------------------------
         // Need to take into account aliases too!
         //-----------------------------------------
         if ($row['bbcode_aliases']) {
             $aliases = explode(',', $row['bbcode_aliases']);
             if (count($aliases)) {
                 foreach ($aliases as $alias) {
                     $bbcodeCurrent[$alias] = $row;
                 }
             }
         }
     }
     if (count($bbcodeOld)) {
         foreach ($bbcodeOld as $tag => $row) {
             if (!$bbcodeCurrent[$row['bbcode_tag']]) {
                 $bbcodeNew[$row['bbcode_tag']] = $row;
             }
         }
     }
     $this->registry->output->addMessage("BB-коды обновлены....");
     /* Now see if there's anything we need to move back over */
     if (count($bbcodeNew)) {
         foreach ($bbcodeNew as $tag => $data) {
             $bbarray = array('bbcode_title' => $data['bbcode_title'], 'bbcode_desc' => $data['bbcode_desc'], 'bbcode_tag' => $data['bbcode_tag'], 'bbcode_replace' => IPSText::safeslashes($data['bbcode_replace']), 'bbcode_useoption' => $data['bbcode_useoption'], 'bbcode_example' => $data['bbcode_example'], 'bbcode_switch_option' => $data['bbcode_switch_option'], 'bbcode_menu_option_text' => $data['bbcode_menu_option_text'], 'bbcode_menu_content_text' => $data['bbcode_menu_content_text'], 'bbcode_groups' => 'all', 'bbcode_sections' => 'all', 'bbcode_php_plugin' => '', 'bbcode_parse' => 2, 'bbcode_no_parsing' => 0, 'bbcode_optional_option' => 0, 'bbcode_aliases' => '', 'bbcode_image' => '');
             $this->DB->insert('custom_bbcode', $bbarray);
         }
     }
     /* OK, now onto permissions... */
     /* Insert basic perms for profiles and help */
     $this->DB->insert('permission_index', array('app' => 'members', 'perm_type' => 'profile_view', 'perm_type_id' => 1, 'perm_view' => '*', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
     $this->DB->insert('permission_index', array('app' => 'core', 'perm_type' => 'help', 'perm_type_id' => 1, 'perm_view' => '*', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
     /* And now calendars */
     $this->DB->build(array('select' => '*', 'from' => 'cal_calendars'));
     $o = $this->DB->execute();
     while ($row = $this->DB->fetch($o)) {
         if (strstr($row['cal_permissions'], 'a:')) {
             $_perms = unserialize(stripslashes($row['cal_permissions']));
             if (is_array($_perms)) {
                 $_view = $_perms['perm_read'] ? ',' . implode(',', explode(',', $_perms['perm_read'])) . ',' : '';
                 $_start = $_perms['perm_post'] ? ',' . implode(',', explode(',', $_perms['perm_post'])) . ',' : '';
                 $_nomod = $_perms['perm_nomod'] ? ',' . implode(',', explode(',', $_perms['perm_nomod'])) . ',' : '';
                 $this->DB->insert('permission_index', array('app' => 'calendar', 'perm_type' => 'calendar', 'perm_type_id' => $row['cal_id'], 'perm_view' => str_replace(',*,', '*', $_view), 'perm_2' => str_replace(',*,', '*', $_start), 'perm_3' => str_replace(',*,', '*', $_nomod), 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
             } else {
                 $this->DB->insert('permission_index', array('app' => 'calendar', 'perm_type' => 'calendar', 'perm_type_id' => $row['cal_id'], 'perm_view' => '', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
             }
         } else {
             $this->DB->insert('permission_index', array('app' => 'calendar', 'perm_type' => 'calendar', 'perm_type_id' => $row['cal_id'], 'perm_view' => '', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
         }
     }
     /* And now forums */
     $this->DB->build(array('select' => '*', 'from' => 'forums'));
     $o = $this->DB->execute();
     while ($row = $this->DB->fetch($o)) {
         /* Do we need to tidy up the title? */
         if (strstr($row['name'], '&')) {
             $row['name'] = preg_replace("#& #", "&amp; ", $row['name']);
             $this->DB->update('forums', array('name' => $row['name']), 'id=' . $row['id']);
         }
         if (strstr($row['permission_array'], 'a:')) {
             $_perms = unserialize(stripslashes($row['permission_array']));
             if (is_array($_perms)) {
                 $_view = $_perms['show_perms'] ? ',' . implode(',', explode(',', $_perms['show_perms'])) . ',' : '';
                 $_read = $_perms['read_perms'] ? ',' . implode(',', explode(',', $_perms['read_perms'])) . ',' : '';
                 $_reply = $_perms['reply_perms'] ? ',' . implode(',', explode(',', $_perms['reply_perms'])) . ',' : '';
                 $_start = $_perms['start_perms'] ? ',' . implode(',', explode(',', $_perms['start_perms'])) . ',' : '';
                 $_upload = $_perms['upload_perms'] ? ',' . implode(',', explode(',', $_perms['upload_perms'])) . ',' : '';
                 $_download = $_perms['download_perms'] ? ',' . implode(',', explode(',', $_perms['download_perms'])) . ',' : '';
                 $this->DB->insert('permission_index', array('app' => 'forums', 'perm_type' => 'forum', 'perm_type_id' => $row['id'], 'perm_view' => str_replace(',*,', '*', $_view), 'perm_2' => str_replace(',*,', '*', $_read), 'perm_3' => str_replace(',*,', '*', $_reply), 'perm_4' => str_replace(',*,', '*', $_start), 'perm_5' => str_replace(',*,', '*', $_upload), 'perm_6' => str_replace(',*,', '*', $_download), 'perm_7' => ''));
             } else {
                 $this->DB->insert('permission_index', array('app' => 'forums', 'perm_type' => 'forum', 'perm_type_id' => $row['id'], 'perm_view' => '', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
                 IPSSetUp::addLogMessage("Пропущены права доступа для форума ID: " . $row['id'], '30001', 'core');
             }
         } else {
             $this->DB->insert('permission_index', array('app' => 'forums', 'perm_type' => 'forum', 'perm_type_id' => $row['id'], 'perm_view' => '', 'perm_2' => '', 'perm_3' => '', 'perm_4' => '', 'perm_5' => '', 'perm_6' => '', 'perm_7' => ''));
             IPSSetUp::addLogMessage("Пропущены права доступа для форума ID: " . $row['id'], '30001', 'core');
         }
     }
     $this->registry->output->addMessage("Права доступа обновлены....");
     /* Fix up forum moderators */
     $this->DB->build(array('select' => '*', 'from' => 'moderators'));
     $o = $this->DB->execute();
     while ($r = $this->DB->fetch($o)) {
         $this->DB->update('moderators', array('forum_id' => ',' . IPSText::cleanPermString($r['forum_id']) . ','), 'mid=' . $r['mid']);
     }
     $this->registry->output->addMessage("Модераторы форумов обновлены....");
     /* Root admin reset? */
     if ($rootAdmins) {
         /* Find all admin groups */
         $this->DB->build(array('select' => '*', 'from' => 'groups', 'where' => 'g_id != ' . $this->settings['admin_group'] . ' AND g_access_cp=1'));
         $o = $this->DB->execute();
         while ($row = $this->DB->fetch($o)) {
             /* Insert blank perm row */
             $this->DB->insert('admin_permission_rows', array('row_id' => $row['g_id'], 'row_id_type' => 'group', 'row_perm_cache' => serialize(array()), 'row_updated' => time()));
         }
         $this->registry->output->addMessage("Удалены вторичные группы администраторов....");
     }
     /* Report center reset */
     $canReport = array();
     $canView = array();
     $this->DB->build(array('select' => 'g_id, g_view_board, g_access_cp, g_is_supmod', 'from' => 'groups'));
     $o = $this->DB->execute();
     while ($r = $this->DB->fetch($o)) {
         if ($r['g_access_cp'] or $r['g_is_supmod']) {
             $canView[] = $r['g_id'];
         }
         if ($r['g_view_board'] and $r['g_id'] != $this->settings['guest_group']) {
             $canReport[] = $r['g_id'];
         }
     }
     $this->DB->update('rc_classes', array('group_can_report' => ',' . implode(',', $canReport) . ',', 'mod_group_perm' => ',' . implode(',', $canView) . ','));
     /* Next Page */
     $this->request['workact'] = 'skinlang';
 }
 /**
  * Execute selected method
  * [ REPEAT FOR APPS: SQL > VERSION UPGRADER / FINISH ] -> SETTINGS  > TEMPLATES > TASKS > LANGUAGES > PUBLIC LANGUAGES > BBCODE > ACP HELP OTHER [ Email Templates ] > Build Caches
  *
  * @access	public
  * @param	object		Registry object
  * @return	void
  */
 public function doExecute(ipsRegistry $registry)
 {
     /* Set Up */
     IPSSetUp::setSavedData('man', intval($this->request['man']) ? intval($this->request['man']) : IPSSetUp::getSavedData('man'));
     IPSSetUp::setSavedData('appdir', $this->request['appdir'] ? $this->request['appdir'] : IPSSetUp::getSavedData('appdir'));
     IPSSetUp::setSavedData('helpfile', intval($this->request['helpfile']) ? intval($this->request['helpfile']) : IPSSetUp::getSavedData('helpfile'));
     /* Do we have a current application? */
     if (!IPSSetUp::getSavedData('appdir')) {
         $_app = IPSSetUp::fetchNextApplication();
         IPSSetUp::setSavedData('appdir', $_app['key']);
     }
     /* Set current app */
     $this->_currentApp = IPSSetUp::getSavedData('appdir');
     /* Fetch numbers */
     $numbers = IPSSetUp::fetchAppVersionNumbers($this->_currentApp);
     /* Set numbers */
     $this->_currentLong = $numbers['current'][0];
     $this->_currentHuman = $numbers['current'][1];
     $this->_uipLong = $numbers['next'][0];
     $this->_uipHuman = $numbers['next'][1];
     $this->_latestLong = $numbers['latest'][0];
     $this->_latestHuman = $numbers['latest'][1];
     $this->_dbDriver = strtolower($this->settings['sql_driver']);
     if ($this->_currentApp) {
         $this->_appData = IPSSetUp::fetchXmlAppInformation($this->_currentApp);
         if ($this->_currentApp == 'core') {
             $this->_appData['name'] = 'IP.Board';
         }
     }
     /* Fail safe */
     if (!$this->_currentApp) {
         print "No app";
         exit;
     }
     $this->registry->output->setVersionAndApp($this->_uipHuman, $this->_appData);
     /* Switch */
     switch ($this->request['do']) {
         case 'sql':
             $this->_stepCount = 1;
             $this->install_sql();
             break;
         case 'appclass':
             $this->_stepCount = 2;
             $this->install_appclass();
             break;
         case 'checkdb':
             $this->_stepCount = 3;
             $this->install_checkdb();
             break;
         case 'modules':
             $this->_stepCount = 4;
             $this->install_modules();
             break;
         case 'settings':
             $this->_stepCount = 5;
             $this->install_settings();
             break;
         case 'templates':
             $this->_stepCount = 6;
             $this->install_templates();
             break;
         case 'tasks':
             $this->_stepCount = 7;
             $this->install_tasks();
             break;
         case 'languages':
             $this->_stepCount = 8;
             $this->install_languages();
             break;
         case 'clientlanguages':
             $this->_stepCount = 9;
             $this->install_client_languages();
             break;
         case 'bbcode':
             $this->_stepCount = 10;
             $this->install_bbcode();
             break;
         case 'acphelp':
             $this->_stepCount = 11;
             $this->install_acphelp();
             break;
         case 'other':
             $this->_stepCount = 12;
             $this->install_other();
             break;
         case 'caches':
             $this->_stepCount = 13;
             $this->install_caches();
             break;
         case 'templatecache':
             $this->_stepCount = 14;
             $this->install_template_caches();
             break;
         default:
             $this->_splash();
             break;
     }
     /* Log errors for support */
     if (count($this->_errorMsg) > 0) {
         IPSSetUp::addLogMessage(implode("\n", $this->_errorMsg), $this->_uipHuman, $this->_currentApp);
     }
 }