2 namespace wcf\data\package
;
3 use wcf\data\AbstractDatabaseObjectAction
;
4 use wcf\system\exception\SystemException
;
5 use wcf\system\request\LinkHandler
;
7 use wcf\util\HTTPRequest
;
11 * Executes package-related actions.
13 * @author Alexander Ebert
14 * @copyright 2001-2014 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage data.package
18 * @category Community Framework
20 class PackageAction
extends AbstractDatabaseObjectAction
{
22 * @see \wcf\data\AbstractDatabaseObjectAction::$className
24 protected $className = 'wcf\data\package\PackageEditor';
27 * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsCreate
29 protected $permissionsCreate = array('admin.system.package.canInstallPackage');
32 * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsDelete
34 protected $permissionsDelete = array('admin.system.package.canUninstallPackage');
37 * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate
39 protected $permissionsUpdate = array('admin.system.package.canUpdatePackage');
41 public function validateSearchForPurchasedItems() {
42 // TODO: validate permissions
44 $this->readString('password', true);
45 $this->readString('username', true);
47 if (empty($this->parameters
['username'])) {
48 // check if user has already provided credentials
49 $sql = "SELECT loginUsername, loginPassword
50 FROM wcf".WCF_N
."_package_update_server
52 $statement = WCF
::getDB()->prepareStatement($sql, 1);
53 $statement->execute(array('http://store.woltlab.com/typhoon/'));
54 $row = $statement->fetchArray();
55 if (!empty($row['loginUsername']) && !empty($row['loginPassword'])) {
56 $this->parameters
['password'] = $row['loginPassword'];
57 $this->parameters
['username'] = $row['loginUsername'];
62 public function searchForPurchasedItems() {
63 if (empty($this->parameters
['username']) ||
empty($this->parameters
['password'])) {
65 'template' => $this->renderAuthorizationDialog(false)
69 $request = new HTTPRequest('https://www.woltlab.com/api/1.0/customer/purchases/list.json', array(
72 'username' => $this->parameters
['username'],
73 'password' => $this->parameters
['password'],
74 'wcfVersion' => WCF_VERSION
78 $reply = $request->getReply();
79 $response = JSON
::decode($reply['body']);
81 $code = (isset($response['status'])) ?
$response['status'] : 500;
84 if (empty($response['products'])) {
86 'noResults' => WCF
::getLanguage()->get('wcf.acp.pluginstore.purchasedItems.noResults')
90 WCF
::getSession()->register('__pluginStoreProducts', $response['products']);
91 WCF
::getSession()->register('__pluginStoreWcfMajorReleases', $response['wcfMajorReleases']);
94 'redirectURL' => LinkHandler
::getInstance()->getLink('PluginStorePurchasedItems')
99 // authentication error
102 'template' => $this->renderAuthorizationDialog(true)
106 // any other kind of errors
108 throw new SystemException(WCF
::getLanguage()->getDynamicVariable('wcf.acp.pluginstore.api.error', array('status' => $code)));
113 protected function renderAuthorizationDialog($rejected) {
114 WCF
::getTPL()->assign(array(
115 'rejected' => $rejected
118 return WCF
::getTPL()->fetch('pluginStoreAuthorization');