From b4f1ea02acb1f2bbe5077c2fbd16f0043bba87b3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 14 Jan 2013 23:47:02 +0100 Subject: [PATCH] Fixed update server and added memory limit check --- .../files/lib/system/WCFSetup.class.php | 46 ++++++++++++++++++- .../package/PackageUpdateDispatcher.class.php | 12 ++--- wcfsetup/setup/db/install.sql | 4 +- .../template/stepShowSystemRequirements.tpl | 11 +++++ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index f4feeb7c35..e545842070 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -39,7 +39,7 @@ define('ENABLE_BENCHMARK', 0); * Executes the installation of the basic WCF systems. * * @author Marcel Werk - * @copyright 2001-2011 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system @@ -394,6 +394,10 @@ class WCFSetup extends WCF { // mb string $system['mbString']['result'] = extension_loaded('mbstring'); + // memory limit + $system['memoryLimit']['value'] = ini_get('memory_limit'); + $system['memoryLimit']['result'] = $this->compareMemoryLimit(); + WCF::getTPL()->assign(array( 'system' => $system, 'nextStep' => 'searchWcfDir' @@ -401,6 +405,46 @@ class WCFSetup extends WCF { WCF::getTPL()->display('stepShowSystemRequirements'); } + /** + * Returns true, if memory_limit is set to at least 64 MB + * + * @return boolean + */ + protected function compareMemoryLimit() { + $memoryLimit = ini_get('memory_limit'); + + // no limit + if ($memoryLimit == -1) { + return true; + } + + // completely numeric, PHP assumes byte + if (is_numeric($memoryLimit)) { + $memoryLimit = $memoryLimit / 1024; + return ($memoryLimit >= 64); + } + + // PHP supports 'K', 'M' and 'G' shorthand notation + if (preg_match('^~(\d+)([KMG])~$', $memoryLimit, $matches)) { + switch ($matches[2]) { + case 'K': + $memoryLimit = $matches[1] * 1024; + return ($memoryLimit >= 64); + break; + + case 'M': + return ($matches[1] >= 64); + break; + + case 'G': + return ($matches[1] >= 1); + break; + } + } + + return false; + } + /** * Searches the wcf dir. */ diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index bb17c2ce30..dbc26ff7d1 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -121,7 +121,7 @@ class PackageUpdateDispatcher extends SingletonFactory { // loop through tags inside the
tag. $allNewPackages = array(); - $packages = $xpath->query('/ns:section[@name=\'packages\']/ns:package'); + $packages = $xpath->query('/ns:section/ns:package'); foreach ($packages as $package) { if (!Package::isValidPackageName($package->getAttribute('name'))) { throw new SystemException("'".$package->getAttribute('name')."' is not a valid package name."); @@ -350,8 +350,8 @@ class PackageUpdateDispatcher extends SingletonFactory { $versionEditor->update(array( 'filename' => $packageFile, 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0), - 'license' => $versionData['license']['license'], - 'licenseURL' => $versionData['license']['licenseURL'], + 'license' => (isset($versionData['license']['license']) ? $versionData['license']['license'] : ''), + 'licenseURL' => (isset($versionData['license']['license']) ? $versionData['license']['licenseURL'] : ''), 'packageDate' => $versionData['packageDate'], 'updateType' => $versionData['updateType'] )); @@ -360,8 +360,8 @@ class PackageUpdateDispatcher extends SingletonFactory { // create new database entry $version = PackageUpdateVersionEditor::create(array( 'filename' => $packageFile, - 'license' => $versionData['license']['license'], - 'licenseURL' => $versionData['license']['licenseURL'], + 'license' => (isset($versionData['license']['license']) ? $versionData['license']['license'] : ''), + 'licenseURL' => (isset($versionData['license']['license']) ? $versionData['license']['licenseURL'] : ''), 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0), 'packageDate' => $versionData['packageDate'], 'packageUpdateID' => $packageUpdateID, @@ -458,7 +458,7 @@ class PackageUpdateDispatcher extends SingletonFactory { // insert requirements $sql = "INSERT INTO wcf".WCF_N."_package_update_optional (packageUpdateVersionID, package) - VALUES (?, ?, ?)"; + VALUES (?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($requirementInserts as $requirement) { $statement->execute(array( diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 0eeea7ef75..ac4b08c4f0 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -498,7 +498,7 @@ CREATE TABLE wcf1_package_update_version ( filename VARCHAR(255) NOT NULL DEFAULT '', license VARCHAR(255) NOT NULL DEFAULT '', licenseURL VARCHAR(255) NOT NULL DEFAULT '', - accessible TINYINT(1) NOT NULL DEFAULT 1, + isAccessible TINYINT(1) NOT NULL DEFAULT 1, UNIQUE KEY packageUpdateID (packageUpdateID, packageVersion) ); @@ -860,6 +860,8 @@ ALTER TABLE wcf1_package_update_fromversion ADD FOREIGN KEY (packageUpdateVersio ALTER TABLE wcf1_package_update_requirement ADD FOREIGN KEY (packageUpdateVersionID) REFERENCES wcf1_package_update_version (packageUpdateVersionID) ON DELETE CASCADE; +ALTER TABLE wcf1_package_update_optional ADD FOREIGN KEY (packageUpdateVersionID) REFERENCES wcf1_package_update_version (packageUpdateVersionID) ON DELETE CASCADE; + ALTER TABLE wcf1_package_update_version ADD FOREIGN KEY (packageUpdateID) REFERENCES wcf1_package_update (packageUpdateID) ON DELETE CASCADE; ALTER TABLE wcf1_page_menu_item ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; diff --git a/wcfsetup/setup/template/stepShowSystemRequirements.tpl b/wcfsetup/setup/template/stepShowSystemRequirements.tpl index 2577a405bd..1b6d051226 100644 --- a/wcfsetup/setup/template/stepShowSystemRequirements.tpl +++ b/wcfsetup/setup/template/stepShowSystemRequirements.tpl @@ -51,6 +51,17 @@
+
+ {lang}wcf.global.systemRequirements.memoryLimit{/lang} +
+
{lang}wcf.global.systemRequirements.element.recommended{/lang} > 64 M
+
+ {lang}wcf.global.systemRequirements.element.yours{/lang} {$system.memoryLimit.value} + {if !$system.memoryLimit.result}{lang}wcf.global.systemRequirements.memoryLimit.description{/lang}{/if} +
+
+
+
{lang}wcf.global.systemRequirements.uploadMaxFilesize{/lang}
-- 2.20.1