/** 
  * Installs sql tables, columns or indeces. 
  */
 public function install()
 {
     parent::install();
     // extract sql file from archive
     if ($this->sqlStr = $this->readSQL($this->installation)) {
         $standalonePackage = $this->installation->getPackage();
         if ($standalonePackage->getParentPackageID()) {
             // package is a plugin; get parent package
             $standalonePackage = $standalonePackage->getParentPackage();
         }
         if ($standalonePackage->isStandalone() == 1) {
             // package is standalone
             $packageAbbr = $standalonePackage->getAbbreviation();
             $tablePrefix = WCF_N . '_' . $standalonePackage->getInstanceNo() . '_';
             // Replace the variable xyz1_1 with $tablePrefix in the table names.
             $this->sqlStr = str_replace($packageAbbr . '1_1_', $packageAbbr . $tablePrefix, $this->sqlStr);
         }
         // replace wcf1_  with the actual WCF_N value
         $this->sqlStr = str_replace("wcf1_", "wcf" . WCF_N . "_", $this->sqlStr);
         // replace charset configuration
         if (Database::$dbCharsets[CHARSET] != 'utf8') {
             $this->sqlStr = str_replace('DEFAULT CHARSET=utf8', 'DEFAULT CHARSET=' . Database::$dbCharsets[CHARSET], $this->sqlStr);
         }
         // get dontAskAgain value from session
         $handleType = WCF::getSession()->getVar('overrideTablesUserDescission');
         $isSetInSession = false;
         if (empty($handleType)) {
             $handleType = 'askAgain';
         } else {
             $isSetInSession = true;
         }
         // check if user decided to not show him again conflicted tables
         if (isset($_POST['dontAskAgainOverride'])) {
             $handleType = $_POST['dontAskAgainOverride'] ? 'dontAskAgainOverride' : 'askAgain';
         } elseif (isset($_POST['dontAskAgainKeep'])) {
             $handleType = $_POST['dontAskAgainKeep'] ? 'dontAskAgainKeep' : 'askAgain';
         }
         if ($handleType == 'dontAskAgainKeep') {
             $this->keepAll = true;
         }
         // store in session
         if (!$isSetInSession && $handleType != 'askAgain') {
             WCF::getSession()->register('overrideTablesUserDescission', $handleType);
             WCF::getSession()->update();
             Session::resetSessions();
         }
         // check and edit (if a table should not be overwritten) sql string
         $this->checkSQL($this->installation->getPackageID(), $this->installation->getAction());
         // display overrides template
         if ($handleType == 'askAgain' && !isset($_POST['overrideTables']) && count($this->overrideTables) > 0) {
             // rearrange array. store each table just one time
             foreach ($this->overrideTables as $table) {
                 $tmp[$table['tableName']][] = $table['overrideType'];
             }
             $this->overrideTables = array();
             // make an indexed array for the javascript funktion selectAll
             foreach ($tmp as $tableName => $table) {
                 $this->overrideTables[] = array('tableName' => $tableName, 'overrideTypes' => $table);
             }
             WCF::getTPL()->assign('tables', $this->overrideTables);
             WCF::getTPL()->display('packageInstallationCheckOverrideTables');
             exit;
         }
         // execute queries
         QueryParser::sendQueries($this->sqlStr, $this->installation->getPackageID());
     }
 }
Exemplo n.º 2
0
 /**
  * Creates the database structure of the wcf.
  */
 protected function createDB()
 {
     $this->initDB();
     // get content of the sql structure file
     $sql = file_get_contents(TMP_DIR . TMP_FILE_PREFIX . 'mysql.sql');
     // installation number value 'n' (WCF_N) must be reflected in the executed sql queries
     $sql = StringUtil::replace('wcf1_', 'wcf' . WCF_N . '_', $sql);
     // replace charset configuration
     if (Database::$dbCharsets[self::$charset] != 'utf8') {
         $sql = StringUtil::replace('DEFAULT CHARSET=utf8', 'DEFAULT CHARSET=' . Database::$dbCharsets[self::$charset], $sql);
     }
     // execute sql queries
     $tables = QueryParser::sendQueries($sql);
     // log sql queries
     foreach ($tables as $tableName) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_sql_log\n\t\t\t\t\t\t(sqlTable)\n\t\t\t\tVALUES\t\t('" . escapeString($tableName) . "')";
         self::getDB()->sendQuery($sql);
     }
     $this->gotoNextStep('logFiles');
 }
Exemplo n.º 3
0
 /**
  * Recovers this backup to the database.
  */
 public function recover()
 {
     // we wont use ZipFile::getFileSize(), because our algorithm seems to be faster (and not so buggy ?!).
     // reads the isize block of the gzip file; see RFC 1952 (http://tools.ietf.org/html/rfc1952)
     //$filesize = $this->getFile()->getFileSize();
     //$filesize = $this->getZipFile(true)->getFileSize();
     $filesize = 1 << 27;
     // 128 MiB
     var_dump($filesize);
     $sqlStr = $this->getZipFile(true)->read($filesize);
     echo '->' . $sqlStr . '<-';
     require_once WCF_DIR . 'lib/system/database/QueryParser.class.php';
     //var_dump($sqlStr);
     QueryParser::sendQueries($sqlStr);
 }