From: Alexander Ebert Date: Sat, 19 Jan 2013 16:47:35 +0000 (+0100) Subject: Package search now runs via AJAX X-Git-Tag: 2.0.0_Beta_1~553 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=25c2c38284c234439111ad28bccc79152a3faca3;p=GitHub%2FWoltLab%2FWCF.git Package search now runs via AJAX Renamed UpdateServer* -> PackageUpdateServer* --- diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 1a8f1ba5c4..918faa9cf0 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -68,31 +68,17 @@ 1 - - - wcf.acp.menu.link.package.update - admin.system.package.canInstallPackage,admin.system.package.canUpdatePackage - 2 - - wcf.acp.menu.link.package - 3 + 2 - + wcf.acp.menu.link.package.server admin.system.package.canEditServer 1 - - - - wcf.acp.menu.link.package.server - admin.system.package.canEditServer - 2 - diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 260f843482..496646946b 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -599,6 +599,283 @@ WCF.ACP.Package.Uninstallation = WCF.ACP.Package.Installation.extend({ } }); +/** + * Manages package search. + */ +WCF.ACP.Package.Search = Class.extend({ + /** + * search button + * @var jQuery + */ + _button: null, + + /** + * list of cached pages + * @var object + */ + _cache: { }, + + /** + * search container + * @var jQuery + */ + _container: null, + + /** + * package input field + * @var jQuery + */ + _package: null, + + /** + * package description input field + * @var jQuery + */ + _packageDescription: null, + + /** + * package name input field + * @var jQuery + */ + _packageName: null, + + /** + * package search result container + * @var jQuery + */ + _packageSearchResultContainer: null, + + /** + * package search result list + * @var jQuery + */ + _packageSearchResultList: null, + + /** + * number of pages + * @var integer + */ + _pageCount: 0, + + /** + * current page + * @var integer + */ + _pageNo: 1, + + /** + * action proxy + * @var WCF.Action:proxy + */ + _proxy: null, + + /** + * search id + * @var integer + */ + _searchID: 0, + + /** + * Initializes the WCF.ACP.Package.Seach class. + */ + init: function() { + this._button = null; + this._cache = { }; + this._container = $('#packageSearch'); + this._package = null; + this._packageName = null; + this._packageSearchResultContainer = $('#packageSearchResultContainer'); + this._packageSearchResultList = $('#packageSearchResultList'); + this._pageCount = 0; + this._pageNo = 1; + this._searchDescription = null; + this._searchID = 0; + + this._proxy = new WCF.Action.Proxy({ + success: $.proxy(this._success, this) + }); + + this._initElements(); + }, + + /** + * Initializes search elements. + */ + _initElements: function() { + this._button = this._container.find('.formSubmit > button.jsButtonPackageSearch').disable().click($.proxy(this._search, this)); + + this._package = $('#package').keyup($.proxy(this._keyUp, this)); + this._packageDescription = $('#packageDescription').keyup($.proxy(this._keyUp, this)); + this._packageName = $('#packageName').keyup($.proxy(this._keyUp, this)); + }, + + /** + * Handles the 'keyup' event. + */ + _keyUp: function(event) { + if (this._package.val() === '' && this._packageDescription.val() === '' && this._packageName.val() === '') { + this._button.disable(); + } + else { + this._button.enable(); + + // submit on [Enter] + if (event.which === 13) { + this._button.trigger('click'); + } + } + }, + + /** + * Performs a new search. + */ + _search: function() { + var $values = this._getSearchValues(); + if (!this._validate($values)) { + return false; + } + + $values.pageNo = this._pageNo; + this._proxy.setOption('data', { + actionName: 'search', + className: 'wcf\\data\\package\\update\\PackageUpdateAction', + parameters: $values + }); + this._proxy.sendRequest(); + }, + + /** + * Returns search values. + * + * @return object + */ + _getSearchValues: function() { + return { + 'package': $.trim(this._package.val()), + packageDescription: $.trim(this._packageDescription.val()), + packageName: $.trim(this._packageName.val()) + }; + }, + + /** + * Validates search values. + * + * @param object values + * @return boolean + */ + _validate: function(values) { + if (values['package'] === '' && values['packageDescription'] === '' && values['packageName'] === '') { + return false; + } + + return true; + }, + + /** + * Handles successful AJAX requests. + * + * @param object data + * @param string textStatus + * @param jQuery jqXHR + */ + _success: function(data, textStatus, jqXHR) { + switch (data.actionName) { + case 'getResultList': + this._insertTemplate(data.returnValues.template); + break; + + case 'search': + this._pageCount = data.returnValues.pageCount; + this._searchID = data.returnValues.searchID; + + this._insertTemplate(data.returnValues.template, (data.returnValues.count === undefined ? undefined : data.returnValues.count)); + this._setupPagination(); + break; + } + }, + + /** + * Inserts search result list template. + * + * @param string template + * @param integer count + */ + _insertTemplate: function(template, count) { + this._packageSearchResultContainer.show(); + + this._packageSearchResultList.html(template); + if (count === undefined) { + this._content[this._pageNo] = template; + } + + // update badge count + if (count !== undefined) { + this._content = { 1: template }; + this._packageSearchResultContainer.find('> header > hgroup > h1 > .badge').html(count); + } + }, + + /** + * Setups pagination for current search. + */ + _setupPagination: function() { + // remove previous instances + this._content = { 1: this._packageSearchResultList.html() }; + this._packageSearchResultContainer.find('.pageNavigation').wcfPages('destroy').remove(); + + if (this._pageCount > 1) { + var $topNavigation = $('
').insertBefore(this._packageSearchResultList).wcfPages({ + activePage: this._pageNo, + maxPage: this._pageCount + }).bind('wcfpagesswitched', $.proxy(this._showPage, this)); + + var $bottomNavigation = $('
').insertAfter(this._packageSearchResultList).wcfPages({ + activePage: this._pageNo, + maxPage: this._pageCount + }).bind('wcfpagesswitched', $.proxy(this._showPage, this)); + } + }, + + /** + * Displays requested pages or loads it. + * + * @param object event + * @param object data + */ + _showPage: function(event, data) { + if (data && data.activePage) { + this._pageNo = data.activePage; + } + + // validate page no + if (this._pageNo < 1 || this._pageNo > this._pageCount) { + console.debug("[WCF.ACP.Package.Search] Cannot access page " + this._pageNo + " of " + this._pageCount); + return; + } + + // load content + if (this._content[this._pageNo] === undefined) { + this._proxy.setOption('data', { + actionName: 'getResultList', + className: 'wcf\\data\\package\\update\\PackageUpdateAction', + parameters: { + pageNo: this._pageNo, + searchID: this._searchID + } + }); + this._proxy.sendRequest(); + } + else { + WCF.DOMNodeInsertedHandler.enable(); + + // show cached content + this._packageSearchResultList.html(this._content[this._pageNo]); + + WCF.DOMNodeInsertedHandler.disable(); + } + } +}); + /** * Handles option selection. */ diff --git a/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl new file mode 100644 index 0000000000..b2e60df99f --- /dev/null +++ b/wcfsetup/install/files/acp/templates/packageSearchResultList.tpl @@ -0,0 +1,45 @@ +{hascontent} +
+ + + + + + + + + + {event name='headColumns'} + + + + + {content} + {foreach from=$packageUpdates item=$package} + + + + + + + + + {event name='columns'} + + {/foreach} + {/content} + +
{lang}wcf.acp.package.name{/lang}{lang}wcf.acp.package.author{/lang}{lang}wcf.acp.package.version{/lang}{lang}wcf.acp.package.license{/lang}{lang}wcf.acp.package.packageDate{/lang}
+ + + {event name='buttons'} +

{$package->packageName}

{if $package->authorURL}{$package->author}{else}{$package->author}{/if}

+ {$package->getAccessibleVersion()->packageVersion} + {if $package->getAccessibleVersion()->packageUpdateVersionID != $package->getLatestVersion()->packageUpdateVersionID} + + {/if} +

{if $package->getAccessibleVersion()->licenseURL}{$package->getAccessibleVersion()->license}{else}{$package->getAccessibleVersion()->license}{/if}

{@$package->getAccessibleVersion()->packageDate|time}

+
+{hascontentelse} +

{lang}wcf.acp.package.search.error.noMatches{/lang}

+{/hascontent} \ No newline at end of file diff --git a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl index e59a633ae1..4559b798e3 100644 --- a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl +++ b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl @@ -5,6 +5,16 @@ {/if} {include file='header'} + +

{lang}{@$pageTitle}{/lang}

@@ -25,55 +35,100 @@
-
-
+
+ + +
- {lang}wcf.acp.package.source{/lang} + {lang}wcf.acp.package.search.conditions{/lang} - -
-
- - {if $errorField == 'uploadPackage'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {elseif $errorType == 'phpRequirements'} - {* todo: use language variable (-> else) *} -
{$phpRequirements|print_r}
- {else} - {lang}wcf.acp.package.error.{@$errorType}{/lang} - {/if} -
- {/if} - {lang}wcf.acp.package.source.upload.description{/lang} -
+
+
+
- - -
+
+
+
+
+
+
- - {if $errorField == 'downloadPackage'} - - {lang}wcf.acp.package.error.{@$errorType}{/lang} - - {/if} - {lang}wcf.acp.package.source.download.description{/lang} + + {lang}wcf.acp.package.search.package.description{/lang}
- - {event name='sourceFields'}
- {event name='fieldsets'} +
+ +
+ +
-
- - - {if $packageID != 0}{/if} +
+ +
+ {lang}wcf.acp.package.source{/lang} + + +
+
+ + {if $errorField == 'uploadPackage'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {elseif $errorType == 'phpRequirements'} + {* todo: use language variable (-> else) *} +
{$phpRequirements|print_r}
+ {else} + {lang}wcf.acp.package.error.{@$errorType}{/lang} + {/if} +
+ {/if} + {lang}wcf.acp.package.source.upload.description{/lang} +
+ + + +
+
+ + {if $errorField == 'downloadPackage'} + + {lang}wcf.acp.package.error.{@$errorType}{/lang} + + {/if} + {lang}wcf.acp.package.source.download.description{/lang} +
+ + + {event name='sourceFields'} +
+ + {event name='fieldsets'} + +
+ + + {if $packageID != 0}{/if} +
+
- +
{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl b/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl deleted file mode 100644 index 5c37b2c7ad..0000000000 --- a/wcfsetup/install/files/acp/templates/packageUpdateSearch.tpl +++ /dev/null @@ -1,122 +0,0 @@ -{include file='header' pageTitle='wcf.acp.packageUpdate.search'} - - - -
-
-

{lang}wcf.acp.packageUpdate.search{/lang}

-
-
- -{if $errorField} -

{lang}wcf.acp.packageUpdate.noneAvailable{/lang}

-{/if} - -{if $updateServers|count} -
-
-
- {lang}wcf.acp.packageUpdate.search.server{/lang} - -
-
-
- -
-
- -
-
- {foreach from=$updateServers item=updateServer} -
- -
- {/foreach} -
- - {event name='serverFields'} -
- -
- {lang}wcf.acp.packageUpdate.search.conditions{/lang} - -
-
-
- -
-
- -
-
- -
-
-
- -
-
- -
-
{lang}wcf.acp.packageUpdate.search.type{/lang}
-
- -
-
- -
-
- -
-
- - {event name='conditionFields'} -
- - {event name='fieldsets'} -
- -
- -
-
-{else} -

{lang}wcf.acp.updateServer.view.noneAvailable{/lang}

-{/if} - -{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl b/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl deleted file mode 100644 index 84d1d21418..0000000000 --- a/wcfsetup/install/files/acp/templates/packageUpdateSearchResult.tpl +++ /dev/null @@ -1,125 +0,0 @@ -{include file='header' pageTitle='wcf.acp.packageUpdate.search'} - -
-
-

{lang}wcf.acp.packageUpdate.search{/lang}

-
-
- -
- {pages print=true assign=pagesLinks controller="PackageUpdateSearchResult" id=$searchID link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} - - {hascontent} - - {/hascontent} -
- -
- {foreach from=$packages item=package} -
-
-
-

- {if $package[isApplication] == 1} - - {elseif $package[plugin] != ''} - - {else} - - {/if} - {$package[packageName]} -

-
- -
-
-
-
- - -
-
- - {if $package[author] != ''} -
-
-
- {if $package[authorURL]}{$package[author]}{else}{$package[author]}{/if} -
-
- {/if} - - {if $package[packageDescription]} -
-
{lang}wcf.acp.package.description{/lang}
-
{$package[packageDescription]}
-
- {/if} - -
- {lang}wcf.acp.packageUpdate.options{/lang} - -
-
-
- - {* update *} - {foreach from=$package[updatableInstances] item=updatableInstance} -
-
- {/foreach} -
-
-
-
-
-
- {/foreach} - -
- - -
-
- -
- {@$pagesLinks} - - {hascontent} - - {/hascontent} -
- -{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl new file mode 100644 index 0000000000..bbe5a72a87 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/packageUpdateServerAdd.tpl @@ -0,0 +1,79 @@ +{include file='header' pageTitle='wcf.acp.updateServer.'|concat:$action} + +
+
+

{lang}wcf.acp.updateServer.{$action}{/lang}

+
+
+ +{if $errorField} +

{lang}wcf.global.form.error{/lang}

+{/if} + +{if $packageUpdateServer|isset && $packageUpdateServer->errorMessage} +

{lang}wcf.acp.updateServer.lastErrorMessage{/lang}
{$packageUpdateServer->errorMessage}

+{/if} + +{if $success|isset} +

{lang}wcf.global.form.{$action}.success{/lang}

+{/if} + +
+ +
+ +
+
+
+ {lang}wcf.acp.updateServer.data{/lang} + + +
+
+ + {if $errorField == 'serverURL'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.updateServer.serverURL.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ + +
+
+
+ + {lang}wcf.acp.updateServer.loginUsername.description{/lang} +
+
+ +
+
+
+ +

{lang}wcf.acp.updateServer.loginPassword.description{/lang}

+
+
+ + {event name='dataFields'} +
+ + {event name='fieldsets'} +
+ +
+ +
+
+ +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl b/wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl new file mode 100644 index 0000000000..b1926931c6 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/packageUpdateServerList.tpl @@ -0,0 +1,96 @@ +{include file='header' pageTitle='wcf.acp.updateServer.list'} + + + +
+
+

{lang}wcf.acp.updateServer.list{/lang}

+
+
+ +{if $deletedPackageUpdateServerID} +

{lang}wcf.acp.updateServer.delete.success{/lang}

+{/if} + +
+ {pages print=true assign=pagesLinks controller="PackageUpdateServerList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} + + +
+ +{hascontent} +
+
+

{lang}wcf.acp.updateServer.list{/lang} {#$items}

+
+ + + + + + + + + + + + {event name='columnHeads'} + + + + + {content} + {foreach from=$objects item=updateServer} + + + + + + + + + + {event name='columns'} + + {/foreach} + {/content} + +
{lang}wcf.global.objectID{/lang}{if $sortField == 'packageUpdateServerID'} {/if}{lang}wcf.acp.updateServer.serverURL{/lang}{if $sortField == 'serverURL'} {/if}{lang}wcf.acp.updateServer.packages{/lang}{if $sortField == 'packages'} {/if}{lang}wcf.acp.updateServer.status{/lang}{if $sortField == 'status'} {/if}{lang}wcf.acp.updateServer.errorMessage{/lang}{if $sortField == 'errorMessage'} {/if}{lang}wcf.acp.updateServer.lastUpdateTime{/lang}{if $sortField == 'lastUpdateTime'} {/if}
+ + + + + {event name='itemButtons'} +

{@$updateServer->packageUpdateServerID}

{$updateServer->serverURL}

{#$updateServer->packages}

{@$updateServer->status}

{@$updateServer->errorMessage|truncate:"30"}

{if $updateServer->lastUpdateTime}{@$updateServer->lastUpdateTime|time}{/if}

+ +
+ +
+ {@$pagesLinks} + + +
+{hascontentelse} +

{lang}wcf.acp.updateServer.list.noneAvailable{/lang}

+{/hascontent} + +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/updateServerAdd.tpl b/wcfsetup/install/files/acp/templates/updateServerAdd.tpl deleted file mode 100644 index ab4d4285a5..0000000000 --- a/wcfsetup/install/files/acp/templates/updateServerAdd.tpl +++ /dev/null @@ -1,79 +0,0 @@ -{include file='header' pageTitle='wcf.acp.updateServer.'|concat:$action} - -
-
-

{lang}wcf.acp.updateServer.{$action}{/lang}

-
-
- -{if $errorField} -

{lang}wcf.global.form.error{/lang}

-{/if} - -{if $packageUpdateServer|isset && $packageUpdateServer->errorMessage} -

{lang}wcf.acp.updateServer.lastErrorMessage{/lang}
{$packageUpdateServer->errorMessage}

-{/if} - -{if $success|isset} -

{lang}wcf.global.form.{$action}.success{/lang}

-{/if} - -
- -
- -
-
-
- {lang}wcf.acp.updateServer.data{/lang} - - -
-
- - {if $errorField == 'serverURL'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.updateServer.serverURL.error.{@$errorType}{/lang} - {/if} - - {/if} -
- - -
-
-
- - {lang}wcf.acp.updateServer.loginUsername.description{/lang} -
-
- -
-
-
- -

{lang}wcf.acp.updateServer.loginPassword.description{/lang}

-
-
- - {event name='dataFields'} -
- - {event name='fieldsets'} -
- -
- -
-
- -{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/updateServerList.tpl b/wcfsetup/install/files/acp/templates/updateServerList.tpl deleted file mode 100644 index b62ffd7fe1..0000000000 --- a/wcfsetup/install/files/acp/templates/updateServerList.tpl +++ /dev/null @@ -1,96 +0,0 @@ -{include file='header' pageTitle='wcf.acp.updateServer.list'} - - - -
-
-

{lang}wcf.acp.updateServer.list{/lang}

-
-
- -{if $deletedPackageUpdateServerID} -

{lang}wcf.acp.updateServer.delete.success{/lang}

-{/if} - -
- {pages print=true assign=pagesLinks controller="UpdateServerList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} - - -
- -{hascontent} -
-
-

{lang}wcf.acp.updateServer.list{/lang} {#$items}

-
- - - - - - - - - - - - {event name='columnHeads'} - - - - - {content} - {foreach from=$objects item=updateServer} - - - - - - - - - - {event name='columns'} - - {/foreach} - {/content} - -
{lang}wcf.global.objectID{/lang}{if $sortField == 'packageUpdateServerID'} {/if}{lang}wcf.acp.updateServer.serverURL{/lang}{if $sortField == 'serverURL'} {/if}{lang}wcf.acp.updateServer.packages{/lang}{if $sortField == 'packages'} {/if}{lang}wcf.acp.updateServer.status{/lang}{if $sortField == 'status'} {/if}{lang}wcf.acp.updateServer.errorMessage{/lang}{if $sortField == 'errorMessage'} {/if}{lang}wcf.acp.updateServer.lastUpdateTime{/lang}{if $sortField == 'lastUpdateTime'} {/if}
- - - - - {event name='itemButtons'} -

{@$updateServer->packageUpdateServerID}

{$updateServer->serverURL}

{#$updateServer->packages}

{@$updateServer->status}

{@$updateServer->errorMessage|truncate:"30"}

{if $updateServer->lastUpdateTime}{@$updateServer->lastUpdateTime|time}{/if}

- -
- -
- {@$pagesLinks} - - -
-{hascontentelse} -

{lang}wcf.acp.updateServer.list.noneAvailable{/lang}

-{/hascontent} - -{include file='footer'} diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 34f1ee58c0..edd0637024 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -5316,8 +5316,8 @@ WCF.System.PageNavigation = { var self = this; elements.each(function(index, element) { var $element = $(element); - console.debug($element.data()); var $elementID = $element.wcfIdentify(); + if (self._elements[$elementID] === undefined) { self._elements[$elementID] = $element; $element.find('li.jumpTo').data('elementID', $elementID).click($.proxy(self._click, self)); diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php deleted file mode 100644 index 35cc9d1113..0000000000 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php +++ /dev/null @@ -1,279 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.form - * @category Community Framework - */ -class PackageUpdateSearchForm extends AbstractForm { - /** - * @see wcf\page\AbstractPage::$activeMenuItem - */ - public $activeMenuItem = 'wcf.acp.menu.link.package.database'; - - /** - * @see wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('admin.system.package.canUpdatePackage', 'admin.system.package.canInstallPackage'); - - /** - * list of package update server ids which are searched - * @var array - */ - public $packageUpdateServerIDs = array(); - - /** - * searched package name - * @var string - */ - public $packageName = ''; - - /** - * searched package author - * @var string - */ - public $author = ''; - - /** - * indicates if package description is searched - * @var integer - */ - public $searchDescription = 0; - - /** - * indicates if plugins for already installed packages are searched - * @var integer - */ - public $plugin = 1; - - /** - * indicates if applications are searched - * @var integer - */ - public $isApplication = 1; - - /** - * indicates if packages that aren't plugins or applications are searched - * @var integer - */ - public $other = 0; - - /** - * list of available update servers - * @var array - */ - public $updateServers = array(); - - /** - * ids of package updates - * @var string - */ - public $packageUpdateIDs = ''; - - /** - * @see wcf\form\IForm::readFormParameters() - */ - public function readFormParameters() { - parent::readFormParameters(); - - $this->plugin = $this->isApplication = 0; - if (isset($_POST['packageUpdateServerIDs']) && is_array($_POST['packageUpdateServerIDs'])) $this->packageUpdateServerIDs = ArrayUtil::toIntegerArray($_POST['packageUpdateServerIDs']); - if (isset($_POST['packageName'])) $this->packageName = StringUtil::trim($_POST['packageName']); - if (isset($_POST['author'])) $this->author = StringUtil::trim($_POST['author']); - if (isset($_POST['searchDescription'])) $this->searchDescription = intval($_POST['searchDescription']); - if (isset($_POST['plugin'])) $this->plugin = intval($_POST['plugin']); - if (isset($_POST['isApplication'])) $this->isApplication = intval($_POST['isApplication']); - if (isset($_POST['other'])) $this->other = intval($_POST['other']); - } - - /** - * @see wcf\form\IForm::validate() - */ - public function validate() { - parent::validate(); - - // refresh package database - PackageUpdateDispatcher::getInstance()->refreshPackageDatabase($this->packageUpdateServerIDs); - - // build conditions - $conditions = new PreparedStatementConditionBuilder(); - - // update servers - if (!empty($this->packageUpdateServerIDs)) { - $conditions->add("packageUpdateServerID IN (?)", array($this->packageUpdateServerIDs)); - } - - // name - if (!empty($this->packageName)) { - $condition = "packageName LIKE ?"; - $parameters = array('%'.$this->packageName.'%'); - - if ($this->searchDescription) { - $condition .= " OR packageDescription LIKE ?"; - $parameters[] = '%'.$this->packageName.'%'; - } - - $conditions->add('('.$condition.')', $parameters); - } - - // author - if (!empty($this->author)) $conditions->add("author LIKE ?", array($this->author)); - - // package type - if (($this->plugin == 0 || $this->isApplication == 0 || $this->other == 0) && ($this->plugin == 1 || $this->isApplication == 1 || $this->other == 1)) { - if ($this->isApplication == 1) { - $condition = 'isApplication = 1'; - if ($this->plugin == 1) { - $condition .= " OR plugin IN (SELECT package FROM wcf".WCF_N."_package)"; - } - else if ($this->other == 1) { - $condition .= " OR plugin = ''"; - } - - $conditions->add('('.$condition.')'); - } - else if ($this->plugin == 1) { - $condition = "plugin IN (SELECT package FROM wcf".WCF_N."_package)"; - if ($this->other == 1) { - $condition .= " OR isApplication = 0"; - } - - $conditions->add('('.$condition.')'); - } - else if ($this->other) { - $conditions->add("(isApplication = 0 AND plugin = '')"); - } - } - - // search package database - $packages = array(); - $packageUpdateIDs = array(); - $sql = "SELECT package, packageUpdateID - FROM wcf".WCF_N."_package_update - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql, 1000); - $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $packageUpdateIDs[] = $row['packageUpdateID']; - - if (!isset($packages[$row['package']])) $packages[$row['package']] = array(); - $packages[$row['package']][$row['packageUpdateID']] = array(); - } - - if (empty($packageUpdateIDs)) { - throw new UserInputException('packageName'); - } - - // remove duplicates - $condition = ''; - $statementParameters = array(); - foreach ($packageUpdateIDs as $packageUpdateID) { - if (!empty($condition)) $condition .= ','; - $condition .= '?'; - $statementParameters[] = $packageUpdateID; - } - - $sql = "SELECT puv.packageVersion, pu.package, pu.packageUpdateID - FROM wcf".WCF_N."_package_update_version puv - LEFT JOIN wcf".WCF_N."_package_update pu - ON (pu.packageUpdateID = puv.packageUpdateID) - WHERE puv.packageUpdateID IN (".$condition.")"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($statementParameters); - while ($row = $statement->fetchArray()) { - $packages[$row['package']][$row['packageUpdateID']][] = $row['packageVersion']; - } - - foreach ($packages as $packageUpdates) { - if (count($packageUpdates) > 1) { - foreach ($packageUpdates as $packageUpdateID => $versions) { - usort($versions, array('wcf\data\package\Package', 'compareVersion')); - $packageUpdates[$packageUpdateID] = array_pop($versions); - } - - uasort($packageUpdates, array('wcf\data\package\Package', 'compareVersion')); - } - - $keys = array_keys($packageUpdates); - if (!empty($this->packageUpdateIDs)) $this->packageUpdateIDs .= ','; - $this->packageUpdateIDs .= array_pop($keys); - } - } - - /** - * @see wcf\form\IForm::save() - */ - public function save() { - parent::save(); - - // save search - $search = SearchEditor::create(array( - 'userID' => WCF::getUser()->userID, - 'searchData' => $this->packageUpdateServerIDs, - 'searchTime' => TIME_NOW, - 'searchType' => 'packages' - )); - - $this->saved(); - - // forward - $url = LinkHandler::getInstance()->getLink('PackageUpdateSearchResult', array('id' => $search->searchID)); - HeaderUtil::redirect($url); - exit; - } - - /** - * @see wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - $this->updateServers = PackageUpdateServer::getActiveUpdateServers(); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'updateServers' => $this->updateServers, - 'packageName' => $this->packageName, - 'searchDescription' => $this->searchDescription, - 'author' => $this->author, - 'isApplication' => $this->isApplication, - 'plugin' => $this->plugin, - 'other' => $this->other, - 'packageUpdateServerIDs' => $this->packageUpdateServerIDs - )); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function show() { - // check master password - WCFACP::checkMasterPassword(); - - parent::show(); - } -} diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php new file mode 100755 index 0000000000..2eb0f468a2 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerAddForm.class.php @@ -0,0 +1,121 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class PackageUpdateServerAddForm extends AbstractForm { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.package.server'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.system.package.canEditServer'); + + /** + * server url + * @var string + */ + public $serverURL = ''; + + /** + * server login username + * @var string + */ + public $loginUsername = ''; + + /** + * server login password + * @var string + */ + public $loginPassword = ''; + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['serverURL'])) $this->serverURL = StringUtil::trim($_POST['serverURL']); + if (isset($_POST['loginUsername'])) $this->loginUsername = $_POST['loginUsername']; + if (isset($_POST['loginPassword'])) $this->loginPassword = $_POST['loginPassword']; + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + parent::validate(); + + if (empty($this->serverURL)) { + throw new UserInputException('serverURL'); + } + + if (!PackageUpdateServer::isValidServerURL($this->serverURL)) { + throw new UserInputException('serverURL', 'notValid'); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + // save server + $this->objectAction = new PackageUpdateServerAction(array(), 'create', array('data' => array( + 'serverURL' => $this->serverURL, + 'loginUsername' => $this->loginUsername, + 'loginPassword' => $this->loginPassword + ))); + $this->objectAction->executeAction(); + $this->saved(); + + // reset values + $this->serverURL = $this->loginUsername = $this->loginPassword = ''; + + // show success message + WCF::getTPL()->assign('success', true); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'serverURL' => $this->serverURL, + 'loginUsername' => $this->loginUsername, + 'loginPassword' => $this->loginPassword, + 'action' => 'add' + )); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function show() { + // check master password + WCFACP::checkMasterPassword(); + + parent::show(); + } +} diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php new file mode 100755 index 0000000000..508d6c1c11 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateServerEditForm.class.php @@ -0,0 +1,94 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class PackageUpdateServerEditForm extends PackageUpdateServerAddForm { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.package.server'; + + /** + * update server id + * @var integer + */ + public $packageUpdateServerID = 0; + + /** + * active package update server + * @var wcf\data\package\update\server\PackageUpdateServer + */ + public $updateServer = null; + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->packageUpdateServerID = intval($_REQUEST['id']); + $this->updateServer = new PackageUpdateServer($this->packageUpdateServerID); + if (!$this->updateServer->packageUpdateServerID) { + throw new IllegalLinkException(); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + AbstractForm::save(); + + // save server + $this->objectAction = new PackageUpdateServerAction(array($this->packageUpdateServerID), 'update', array('data' => array( + 'serverURL' => $this->serverURL, + 'loginUsername' => $this->loginUsername, + 'loginPassword' => $this->loginPassword + ))); + $this->objectAction->executeAction(); + $this->saved(); + + // show success message + WCF::getTPL()->assign('success', true); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + if (empty($_POST)) { + $this->serverURL = $this->updateServer->serverURL; + $this->loginUsername = $this->updateServer->loginUsername; + $this->loginPassword = $this->updateServer->loginPassword; + } + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'packageUpdateServerID' => $this->packageUpdateServerID, + 'packageUpdateServer' => $this->updateServer, + 'action' => 'edit' + )); + } +} diff --git a/wcfsetup/install/files/lib/acp/form/UpdateServerAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UpdateServerAddForm.class.php deleted file mode 100755 index 5fc82c528b..0000000000 --- a/wcfsetup/install/files/lib/acp/form/UpdateServerAddForm.class.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.form - * @category Community Framework - */ -class UpdateServerAddForm extends AbstractForm { - /** - * @see wcf\page\AbstractPage::$activeMenuItem - */ - public $activeMenuItem = 'wcf.acp.menu.link.package.server.add'; - - /** - * @see wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('admin.system.package.canEditServer'); - - /** - * server url - * @var string - */ - public $serverURL = ''; - - /** - * server login username - * @var string - */ - public $loginUsername = ''; - - /** - * server login password - * @var string - */ - public $loginPassword = ''; - - /** - * @see wcf\form\IForm::readFormParameters() - */ - public function readFormParameters() { - parent::readFormParameters(); - - if (isset($_POST['serverURL'])) $this->serverURL = StringUtil::trim($_POST['serverURL']); - if (isset($_POST['loginUsername'])) $this->loginUsername = $_POST['loginUsername']; - if (isset($_POST['loginPassword'])) $this->loginPassword = $_POST['loginPassword']; - } - - /** - * @see wcf\form\IForm::validate() - */ - public function validate() { - parent::validate(); - - if (empty($this->serverURL)) { - throw new UserInputException('serverURL'); - } - - if (!PackageUpdateServer::isValidServerURL($this->serverURL)) { - throw new UserInputException('serverURL', 'notValid'); - } - } - - /** - * @see wcf\form\IForm::save() - */ - public function save() { - parent::save(); - - // save server - $this->objectAction = new PackageUpdateServerAction(array(), 'create', array('data' => array( - 'serverURL' => $this->serverURL, - 'loginUsername' => $this->loginUsername, - 'loginPassword' => $this->loginPassword - ))); - $this->objectAction->executeAction(); - $this->saved(); - - // reset values - $this->serverURL = $this->loginUsername = $this->loginPassword = ''; - - // show success message - WCF::getTPL()->assign('success', true); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'serverURL' => $this->serverURL, - 'loginUsername' => $this->loginUsername, - 'loginPassword' => $this->loginPassword, - 'action' => 'add' - )); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function show() { - // check master password - WCFACP::checkMasterPassword(); - - parent::show(); - } -} diff --git a/wcfsetup/install/files/lib/acp/form/UpdateServerEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UpdateServerEditForm.class.php deleted file mode 100755 index c506b7c059..0000000000 --- a/wcfsetup/install/files/lib/acp/form/UpdateServerEditForm.class.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.form - * @category Community Framework - */ -class UpdateServerEditForm extends UpdateServerAddForm { - /** - * @see wcf\page\AbstractPage::$activeMenuItem - */ - public $activeMenuItem = 'wcf.acp.menu.link.package.server'; - - /** - * update server id - * @var integer - */ - public $packageUpdateServerID = 0; - - /** - * active package update server - * @var wcf\data\package\update\server\PackageUpdateServer - */ - public $updateServer = null; - - /** - * @see wcf\page\IPage::readParameters() - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['id'])) $this->packageUpdateServerID = intval($_REQUEST['id']); - $this->updateServer = new PackageUpdateServer($this->packageUpdateServerID); - if (!$this->updateServer->packageUpdateServerID) { - throw new IllegalLinkException(); - } - } - - /** - * @see wcf\form\IForm::save() - */ - public function save() { - AbstractForm::save(); - - // save server - $this->objectAction = new PackageUpdateServerAction(array($this->packageUpdateServerID), 'update', array('data' => array( - 'serverURL' => $this->serverURL, - 'loginUsername' => $this->loginUsername, - 'loginPassword' => $this->loginPassword - ))); - $this->objectAction->executeAction(); - $this->saved(); - - // show success message - WCF::getTPL()->assign('success', true); - } - - /** - * @see wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - if (empty($_POST)) { - $this->serverURL = $this->updateServer->serverURL; - $this->loginUsername = $this->updateServer->loginUsername; - $this->loginPassword = $this->updateServer->loginPassword; - } - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'packageUpdateServerID' => $this->packageUpdateServerID, - 'packageUpdateServer' => $this->updateServer, - 'action' => 'edit' - )); - } -} diff --git a/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php deleted file mode 100755 index a028d41c8d..0000000000 --- a/wcfsetup/install/files/lib/acp/page/PackageUpdateSearchResultPage.class.php +++ /dev/null @@ -1,173 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.page - * @category Community Framework - */ -class PackageUpdateSearchResultPage extends SortablePage { - /** - * @see wcf\page\AbstractPage::$activeMenuItem - */ - public $activeMenuItem = 'wcf.acp.menu.link.package.database'; - - /** - * @see wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('admin.system.package.canUpdatePackage', 'admin.system.package.canInstallPackage'); - - /** - * @see wcf\page\SortablePage::$defaultSortField - */ - public $defaultSortField = 'packageName'; - - /** - * @see wcf\page\SortablePage::$validSortFields - */ - public $validSortFields = array('package', 'packageName', 'author'); - - /** - * id of the package update search - * @var integer - */ - public $searchID = 0; - - /** - * search object - * @var wcf\data\search\Search - */ - public $search = null; - - /** - * list with data of package updates - * @var array - */ - public $packages = array(); - - /** - * @see wcf\page\IPage::readParameters() - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['searchID'])) $this->searchID = intval($_REQUEST['searchID']); - - // get search data - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("searchID = ?", array($this->searchID)); - $conditions->add("userID = ?", array(WCF::getUser()->userID)); - $conditions->add("searchType = ?", array('packages')); - - $sql = "SELECT * - FROM wcf".WCF_N."_search - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - - $this->search = new Search(null, $statement->fetchArray()); - if (empty($this->search->searchID)) { - throw new IllegalLinkException(); - } - } - - /** - * @see wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - // read packages - $this->readPackages(); - } - - /** - * @see wcf\page\MultipleLinkPage::countItems() - */ - public function countItems() { - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageUpdateID IN (?)", array(explode(',', $this->search->searchData))); - - $sql = "SELECT COUNT(*) AS count - FROM wcf".WCF_N."_package_update - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - $row = $statement->fetchArray(); - - return $row['count']; - } - - /** - * Gets a list of packages. - */ - protected function readPackages() { - if ($this->items) { - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageUpdateID IN (?)", array(explode(',', $this->search->searchData))); - - $sql = "SELECT * - FROM wcf".WCF_N."_package_update - ".$conditions." - ORDER BY ".$this->sortField." ".$this->sortOrder; - $statement = WCF::getDB()->prepareStatement($sql, $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage); - $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - // default values - $row['updatableInstances'] = array(); - $row['packageVersions'] = array(); - $row['packageVersion'] = '1.0.0'; - $row['instances'] = 0; - - // get package versions - $sql = "SELECT packageVersion - FROM wcf".WCF_N."_package_update_version - WHERE packageUpdateID IN ( - SELECT packageUpdateID - FROM wcf".WCF_N."_package_update - WHERE package = ? - )"; - $statement2 = WCF::getDB()->prepareStatement($sql); - $statement2->execute(array($row['package'])); - while ($row2 = $statement2->fetchArray()) { - $row['packageVersions'][] = $row2['packageVersion']; - } - - if (!empty($row['packageVersions'])) { - // remove duplicates - $row['packageVersions'] = array_unique($row['packageVersions']); - // sort versions - usort($row['packageVersions'], array('wcf\data\package\Package', 'compareVersion')); - // take lastest version - $row['packageVersion'] = end($row['packageVersions']); - } - - $this->packages[] = $row; - } - } - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'searchID' => $this->searchID, - 'packages' => $this->packages, - 'selectedPackages' => array() - )); - } -} diff --git a/wcfsetup/install/files/lib/acp/page/PackageUpdateServerListPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageUpdateServerListPage.class.php new file mode 100755 index 0000000000..4cc6d4fc90 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/page/PackageUpdateServerListPage.class.php @@ -0,0 +1,76 @@ + + * @package com.woltlab.wcf + * @subpackage acp.page + * @category Community Framework + */ +class PackageUpdateServerListPage extends SortablePage { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.package.server.list'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.system.package.canEditServer'); + + /** + * @see wcf\page\SortablePage::$defaultSortField + */ + public $defaultSortField = 'serverURL'; + + /** + * @see wcf\page\SortablePage::$validSortFields + */ + public $validSortFields = array('packageUpdateServerID', 'serverURL', 'status', 'errorMessage', 'lastUpdateTime', 'packages'); + + /** + * @see wcf\page\MultipleLinkPage::$objectListClassName + */ + public $objectListClassName = 'wcf\data\package\update\server\PackageUpdateServerList'; + + /** + * id of a package update server that has just been deleted + * @var integer + */ + public $deletedPackageUpdateServerID = 0; + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['deletedPackageUpdateServerID'])) $this->deletedPackageUpdateServerID = intval($_REQUEST['deletedPackageUpdateServerID']); + } + + /** + * @see wcf\page\MultipleLinkPage::readObjects() + */ + public function readObjects() { + $this->sqlOrderBy = ($this->sortField != 'packages' ? 'package_update_server.' : '') . $this->sortField.' '.$this->sortOrder; + + parent::readObjects(); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'deletedPackageUpdateServerID' => $this->deletedPackageUpdateServerID + )); + } +} diff --git a/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php b/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php deleted file mode 100755 index b1dbf8eceb..0000000000 --- a/wcfsetup/install/files/lib/acp/page/UpdateServerListPage.class.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.page - * @category Community Framework - */ -class UpdateServerListPage extends SortablePage { - /** - * @see wcf\page\AbstractPage::$activeMenuItem - */ - public $activeMenuItem = 'wcf.acp.menu.link.package.server.list'; - - /** - * @see wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('admin.system.package.canEditServer'); - - /** - * @see wcf\page\SortablePage::$defaultSortField - */ - public $defaultSortField = 'serverURL'; - - /** - * @see wcf\page\SortablePage::$validSortFields - */ - public $validSortFields = array('packageUpdateServerID', 'serverURL', 'status', 'errorMessage', 'lastUpdateTime', 'packages'); - - /** - * @see wcf\page\MultipleLinkPage::$objectListClassName - */ - public $objectListClassName = 'wcf\data\package\update\server\PackageUpdateServerList'; - - /** - * id of a package update server that has just been deleted - * @var integer - */ - public $deletedPackageUpdateServerID = 0; - - /** - * @see wcf\page\IPage::readParameters() - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['deletedPackageUpdateServerID'])) $this->deletedPackageUpdateServerID = intval($_REQUEST['deletedPackageUpdateServerID']); - } - - /** - * @see wcf\page\MultipleLinkPage::readObjects() - */ - public function readObjects() { - $this->sqlOrderBy = ($this->sortField != 'packages' ? 'package_update_server.' : '') . $this->sortField.' '.$this->sortOrder; - - parent::readObjects(); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'deletedPackageUpdateServerID' => $this->deletedPackageUpdateServerID - )); - } -} diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 447bbe1d51..17d7e30bb0 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -12,7 +12,7 @@ use wcf\util\StringUtil; * Represents a package. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data.package diff --git a/wcfsetup/install/files/lib/data/package/PackageAction.class.php b/wcfsetup/install/files/lib/data/package/PackageAction.class.php index 8edd8b4866..4603f02a22 100644 --- a/wcfsetup/install/files/lib/data/package/PackageAction.class.php +++ b/wcfsetup/install/files/lib/data/package/PackageAction.class.php @@ -9,7 +9,7 @@ use wcf\system\WCF; * Executes package-related actions. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data.package diff --git a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php index 85d47c8cd5..de81ac3bc2 100644 --- a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php +++ b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php @@ -1,12 +1,19 @@ * @package com.woltlab.wcf * @subpackage data.package.update @@ -17,4 +24,235 @@ class PackageUpdateAction extends AbstractDatabaseObjectAction { * @see wcf\data\AbstractDatabaseObjectAction::$className */ protected $className = 'wcf\data\package\update\PackageUpdateEditor'; + + /** + * search object + * @var wcf\data\search\Search + */ + protected $search = null; + + /** + * Validates parameters to search for installable packages. + */ + public function validateSearch() { + WCF::getSession()->checkPermissions(array('admin.system.package.canInstallPackage')); + + $this->readString('package', true); + $this->readString('packageDescription', true); + $this->readString('packageName', true); + $this->readBoolean('searchDescription', true); + + if (empty($this->parameters['package']) && empty($this->parameters['packageDescription']) && empty($this->parameters['packageName'])) { + throw new PermissionDeniedException(); + } + } + + /** + * Returns a result list of a search for installable packages. + * + * @return array + */ + public function search() { + $conditions = new PreparedStatementConditionBuilder(); + if (!empty($this->parameters['package'])) { + $conditions->add("package_update.package LIKE ?", array('%'.$this->parameters['package'].'%')); + } + if (!empty($this->parameters['packageDescription'])) { + $conditions->add("package_update.packageDescription LIKE ?", array('%'.$this->parameters['packageDescription'].'%')); + } + if (!empty($this->parameters['packageName'])) { + $conditions->add("package_update.packageName LIKE ?", array('%'.$this->parameters['packageName'].'%')); + } + + // find matching packages + $sql = "SELECT package_update.packageUpdateID + FROM wcf".WCF_N."_package_update package_update + ".$conditions." + ORDER BY package_update.packageName ASC"; + $statement = WCF::getDB()->prepareStatement($sql, 1000); + $statement->execute($conditions->getParameters()); + $packageUpdateIDs = array(); + while ($row = $statement->fetchArray()) { + $packageUpdateIDs[] = $row['packageUpdateID']; + } + + // no matches found + if (empty($packageUpdateIDs)) { + WCF::getTPL()->assign(array( + 'packageUpdates' => array() + )); + + return array( + 'count' => 0, + 'pageCount' => 0, + 'searchID' => 0, + 'template' => WCF::getTPL()->fetch('packageSearchResultList') + ); + } + + // filter by version + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("puv.packageUpdateID IN (?)", array($packageUpdateIDs)); + $sql = "SELECT pu.package, puv.packageUpdateVersionID, puv.packageUpdateID, puv.packageVersion, puv.isAccessible + FROM wcf".WCF_N."_package_update_version puv + LEFT JOIN wcf".WCF_N."_package_update pu + ON (pu.packageUpdateID = puv.packageUpdateID) + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + $packageVersions = array(); + while ($row = $statement->fetchArray()) { + $package = $row['package']; + if (!isset($packageVersions[$package])) { + $packageVersions[$package] = array(); + } + + $packageUpdateID = $row['packageUpdateID']; + if (!isset($packageVersions[$package][$packageUpdateID])) { + $packageVersions[$package][$packageUpdateID] = array( + 'accessible' => array(), + 'existing' => array() + ); + } + + if ($row['isAccessible']) { + $packageVersions[$package][$packageUpdateID]['accessible'][$row['packageUpdateVersionID']] = $row['packageVersion']; + } + $packageVersions[$package][$packageUpdateID]['existing'][$row['packageUpdateVersionID']] = $row['packageVersion']; + } + + // determine highest versions + $packageUpdates = array(); + foreach ($packageVersions as $package => $versionData) { + $accessible = $existing = $versions = array(); + + foreach ($versionData as $packageUpdateID => $versionTypes) { + // ignore unaccessible packages + if (empty($versionTypes['accessible'])) { + continue; + } + + uasort($versionTypes['accessible'], array('wcf\data\package\Package', 'compareVersion')); + uasort($versionTypes['existing'], array('wcf\data\package\Package', 'compareVersion')); + + $accessibleVersion = array_slice($versionTypes['accessible'], -1, 1, true); + $existingVersion = array_slice($versionTypes['existing'], -1, 1, true); + + $ak = key($accessibleVersion); + $av = current($accessibleVersion); + $ek = key($existingVersion); + $ev = current($existingVersion); + + $accessible[$av] = $ak; + $existing[$ev] = $ek; + $versions[$ak] = $packageUpdateID; + $versions[$ek] = $packageUpdateID; + } + + uksort($accessible, array('wcf\data\package\Package', 'compareVersion')); + uksort($existing, array('wcf\data\package\Package', 'compareVersion')); + + $accessible = array_pop($accessible); + $existing = array_pop($existing); + $packageUpdates[$versions[$accessible]] = array( + 'accessible' => $accessible, + 'existing' => $existing + ); + } + + $search = SearchEditor::create(array( + 'userID' => WCF::getUser()->userID, + 'searchData' => serialize($packageUpdates), + 'searchTime' => TIME_NOW, + 'searchType' => 'acpPackageSearch' + )); + + // forward call to build the actual result list + $updateAction = new PackageUpdateAction(array(), 'getResultList', array( + 'pageNo' => 1, + 'search' => $search + )); + + $returnValues = $updateAction->executeAction(); + return $returnValues['returnValues']; + } + + /** + * Validates parameters to return a result list for a previous search. + */ + public function validateGetResultList() { + WCF::getSession()->checkPermissions(array('admin.system.package.canInstallPackage')); + + $this->readInteger('pageNo'); + $this->readInteger('searchID'); + + $this->search = new Search($this->parameters['searchID']); + if (!$this->search->searchID || $this->search->userID != WCF::getUser()->userID) { + throw new UserInputException('searchID'); + } + } + + /** + * Returns a result list for a previous search. + * + * @return array + */ + public function getResultList() { + if ($this->search === null && isset($this->parameters['search']) && $this->parameters['search'] instanceof Search) { + $this->search = $this->parameters['search']; + } + $updateData = unserialize($this->search->searchData); + + // get package updates + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("packageUpdateID IN (?)", array(array_keys($updateData))); + + $sql = "SELECT packageUpdateID, packageName, packageDescription, author, authorURL + FROM wcf".WCF_N."_package_update + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql, 20, ($this->parameters['pageNo'] - 1) * 20); + $statement->execute($conditions->getParameters()); + $packageUpdates = $packageVersionIDs = array(); + while ($packageUpdate = $statement->fetchObject('wcf\data\package\update\PackageUpdate')) { + $packageUpdates[$packageUpdate->packageUpdateID] = new ViewablePackageUpdate($packageUpdate); + + // collect package version ids + $versionIDs = $updateData[$packageUpdate->packageUpdateID]; + $packageVersionIDs[] = $versionIDs['accessible']; + $packageVersionIDs[] = $versionIDs['existing']; + } + + // read update versions + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("packageUpdateVersionID IN (?)", array($packageVersionIDs)); + + $sql = "SELECT packageUpdateVersionID, packageVersion, packageDate, license, licenseURL + FROM wcf".WCF_N."_package_update_version + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + $updateVersions = array(); + while ($updateVersion = $statement->fetchObject('wcf\data\package\update\version\PackageUpdateVersion')) { + $updateVersions[$updateVersion->packageUpdateVersionID] = $updateVersion; + } + + // assign versions + foreach ($packageUpdates as $packageUpdateID => $packageUpdate) { + $versionIDs = $updateData[$packageUpdate->packageUpdateID]; + $packageUpdate->setAccessibleVersion($updateVersions[$versionIDs['accessible']]); + $packageUpdate->setLatestVersion($updateVersions[$versionIDs['existing']]); + } + + WCF::getTPL()->assign(array( + 'packageUpdates' => $packageUpdates + )); + + $count = count($updateData); + return array( + 'count' => $count, + 'pageCount' => ceil($count / 20), + 'searchID' => $this->search->searchID, + 'template' => WCF::getTPL()->fetch('packageSearchResultList') + ); + } } diff --git a/wcfsetup/install/files/lib/data/package/update/PackageUpdateList.class.php b/wcfsetup/install/files/lib/data/package/update/PackageUpdateList.class.php index a59cdd5362..0c71510fb5 100644 --- a/wcfsetup/install/files/lib/data/package/update/PackageUpdateList.class.php +++ b/wcfsetup/install/files/lib/data/package/update/PackageUpdateList.class.php @@ -1,12 +1,13 @@ * @package com.woltlab.wcf * @subpackage data.package.update @@ -17,4 +18,15 @@ class PackageUpdateList extends DatabaseObjectList { * @see wcf\data\DatabaseObjectList::$className */ public $className = 'wcf\data\package\update\PackageUpdate'; + + /** + * @see wcf\data\DatabaseObjectList::__construct() + */ + public function __construct($useSqlOr = false) { + parent::__construct(); + + if ($useSqlOr) { + $this->conditionBuilder = new PreparedStatementConditionBuilder(true, 'OR'); + } + } } diff --git a/wcfsetup/install/files/lib/data/package/update/ViewablePackageUpdate.class.php b/wcfsetup/install/files/lib/data/package/update/ViewablePackageUpdate.class.php new file mode 100644 index 0000000000..57d9617eb0 --- /dev/null +++ b/wcfsetup/install/files/lib/data/package/update/ViewablePackageUpdate.class.php @@ -0,0 +1,69 @@ + + * @package com.woltlab.wcf + * @subpackage data.package.update + * @category Community Framework + */ +class ViewablePackageUpdate extends DatabaseObjectDecorator { + /** + * @see wcf\data\DatabaseObjectDecorator::$baseClass + */ + protected static $baseClass = 'wcf\data\package\update\PackageUpdate'; + + /** + * latest accessible package update version object + * @var wcf\data\package\update\version\PackageUpdateVersion + */ + protected $accessibleVersion = null; + + /** + * latest package update version object + * @var wcf\data\package\update\version\PackageUpdateVersion + */ + protected $latestVersion = null; + + /** + * Sets latest accessible package update version object. + * + * @param wcf\data\package\update\version\PackageUpdateVersion $latestVersion + */ + public function setAccessibleVersion(PackageUpdateVersion $latestVersion) { + $this->accessibleVersion = $latestVersion; + } + + /** + * Sets latest package update version object. + * + * @param wcf\data\package\update\version\PackageUpdateVersion $latestVersion + */ + public function setLatestVersion(PackageUpdateVersion $latestVersion) { + $this->latestVersion = $latestVersion; + } + + /** + * Returns latest accessible package update version object. + * + * @return wcf\data\package\update\version\PackageUpdateVersion + */ + public function getAccessibleVersion() { + return $this->accessibleVersion; + } + + /** + * Returns latest package update version object. + * + * @return wcf\data\package\update\version\PackageUpdateVersion + */ + public function getLatestVersion() { + return $this->latestVersion; + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 1f8dae9a65..7f9f82a736 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -247,9 +247,7 @@ - - @@ -414,6 +412,7 @@ + @@ -442,6 +441,7 @@ + @@ -449,6 +449,13 @@ + + + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 400f9a6983..be610e212b 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -176,9 +176,7 @@ - -