From ac70af510d325a30c485690db93b85d18c382692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 30 Jun 2015 00:25:55 +0200 Subject: [PATCH] Remove use of deprecated API class --- appinfo/app.php | 43 ++++++++++++------------ lib/app.php | 2 +- lib/controller.php | 16 ++------- lib/controller/addressbookcontroller.php | 15 ++++----- lib/controller/settingscontroller.php | 3 +- lib/dispatcher.php | 7 ++-- 6 files changed, 35 insertions(+), 51 deletions(-) diff --git a/appinfo/app.php b/appinfo/app.php index 6468e797..7b2495e2 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -9,9 +9,6 @@ namespace OCA\Contacts; -use \OC\AppFramework\Core\API; - -//require_once __DIR__ . '/../lib/controller/pagecontroller.php'; \Sabre\VObject\Component\VCard::$componentMap['VCARD'] = '\OCA\Contacts\VObject\VCard'; \Sabre\VObject\Component\VCard::$propertyMap['CATEGORIES'] = '\OCA\Contacts\VObject\GroupProperty'; @@ -24,18 +21,16 @@ use \OC\AppFramework\Core\API; ) ); -$api = new API('contacts'); - -$api->connectHook('OC_User', 'post_createUser', '\OCA\Contacts\Hooks', 'userCreated'); -$api->connectHook('OC_User', 'post_deleteUser', '\OCA\Contacts\Hooks', 'userDeleted'); -$api->connectHook('OCA\Contacts', 'pre_deleteAddressBook', '\OCA\Contacts\Hooks', 'addressBookDeletion'); -$api->connectHook('OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion'); -$api->connectHook('OCA\Contacts', 'post_createContact', 'OCA\Contacts\Hooks', 'contactAdded'); -$api->connectHook('OCA\Contacts', 'post_updateContact', '\OCA\Contacts\Hooks', 'contactUpdated'); -$api->connectHook('OCA\Contacts', 'scanCategories', '\OCA\Contacts\Hooks', 'scanCategories'); -$api->connectHook('OCA\Contacts', 'indexProperties', '\OCA\Contacts\Hooks', 'indexProperties'); -$api->connectHook('OC_Calendar', 'getEvents', 'OCA\Contacts\Hooks', 'getBirthdayEvents'); -$api->connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalenderSources'); +\OCP\Util::connectHook('OC_User', 'post_createUser', '\OCA\Contacts\Hooks', 'userCreated'); +\OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Contacts\Hooks', 'userDeleted'); +\OCP\Util::connectHook('OCA\Contacts', 'pre_deleteAddressBook', '\OCA\Contacts\Hooks', 'addressBookDeletion'); +\OCP\Util::connectHook('OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion'); +\OCP\Util::connectHook('OCA\Contacts', 'post_createContact', 'OCA\Contacts\Hooks', 'contactAdded'); +\OCP\Util::connectHook('OCA\Contacts', 'post_updateContact', '\OCA\Contacts\Hooks', 'contactUpdated'); +\OCP\Util::connectHook('OCA\Contacts', 'scanCategories', '\OCA\Contacts\Hooks', 'scanCategories'); +\OCP\Util::connectHook('OCA\Contacts', 'indexProperties', '\OCA\Contacts\Hooks', 'indexProperties'); +\OCP\Util::connectHook('OC_Calendar', 'getEvents', 'OCA\Contacts\Hooks', 'getBirthdayEvents'); +\OCP\Util::connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalenderSources'); \OCP\Util::addscript('contacts', 'loader'); \OCP\Util::addscript('contacts', 'admin'); @@ -47,12 +42,16 @@ $api->connectHook('OC_Calendar', 'getSources', 'OCA\Contacts\Hooks', 'getCalende \OCP\App::registerAdmin('contacts', 'admin'); if (\OCP\User::isLoggedIn()) { - $app = new App($api->getUserId()); - $addressBooks = $app->getAddressBooksForUser(); - foreach ($addressBooks as $addressBook) { - if ($addressBook->isActive()) { - \OCP\Contacts::registerAddressBook($addressBook->getSearchProvider()); - } - } + $cm = \OC::$server->getContactsManager(); + $cm->register(function() use ($cm) { + $userId = \OC::$server->getUserSession()->getUser()->getUID(); + $app = new App($userId); + $addressBooks = $app->getAddressBooksForUser(); + foreach ($addressBooks as $addressBook) { + if ($addressBook->isActive()) { + $cm->registerAddressBook($addressBook->getSearchProvider()); + } + } + }); } diff --git a/lib/app.php b/lib/app.php index 71981bde..00ee14b4 100644 --- a/lib/app.php +++ b/lib/app.php @@ -38,7 +38,7 @@ class App { /** * @brief language object for calendar app * - * @var OC_L10N + * @var \OCP\IL10N */ public static $l10n; diff --git a/lib/controller.php b/lib/controller.php index 8810e2c1..6bc595f9 100644 --- a/lib/controller.php +++ b/lib/controller.php @@ -11,26 +11,14 @@ namespace OCA\Contacts; -use OCP\AppFramework\IAppContainer, - OCP\AppFramework\Controller as BaseController, - OCP\IRequest, - OCA\Contacts\App; +use OCP\AppFramework\Controller as BaseController; +use OCP\IRequest; /** * Base Controller class for Contacts App */ class Controller extends BaseController { - /** - * @var Api - */ - protected $api; - - /** - * @var IRequest - */ - protected $request; - /** * @var App */ diff --git a/lib/controller/addressbookcontroller.php b/lib/controller/addressbookcontroller.php index 6ee276c2..83c8c659 100644 --- a/lib/controller/addressbookcontroller.php +++ b/lib/controller/addressbookcontroller.php @@ -14,7 +14,6 @@ use OCA\Contacts\App, OCA\Contacts\Utils\JSONSerializer, OCA\Contacts\Controller, OCP\AppFramework\Http, - OCP\AppFramework\IApi, OCP\IRequest; /** @@ -22,14 +21,12 @@ use OCA\Contacts\App, */ class AddressBookController extends Controller { - /** - * @var \OCP\AppFramework\IApi - */ - protected $api; + /** @var string */ + protected $userId; - public function __construct($appName, IRequest $request, App $app, IApi $api) { + public function __construct($appName, IRequest $request, App $app, $userId) { parent::__construct($appName, $request, $app); - $this->api = $api; + $this->userId = $userId; } /** @@ -55,7 +52,7 @@ class AddressBookController extends Controller { // To avoid invalid cache deletion time is saved /*$lastModified = max( $lastModified, - \OCP\Config::getUserValue($this->api->getUserId(), 'contacts', 'last_address_book_deleted', 0) + \OCP\Config::getUserValue($this->userId, 'contacts', 'last_address_book_deleted', 0) );*/ $response = new JSONResponse(array( @@ -222,7 +219,7 @@ class AddressBookController extends Controller { ), 500); } - \OCP\Config::setUserValue($this->api->getUserId(), 'contacts', 'last_address_book_deleted', time()); + \OCP\Config::setUserValue($this->userId, 'contacts', 'last_address_book_deleted', time()); return $response; } diff --git a/lib/controller/settingscontroller.php b/lib/controller/settingscontroller.php index 8dd2f367..ac73d96a 100644 --- a/lib/controller/settingscontroller.php +++ b/lib/controller/settingscontroller.php @@ -12,8 +12,7 @@ namespace OCA\Contacts\Controller; use OCA\Contacts\App, OCA\Contacts\JSONResponse, - OCP\AppFramework\Controller, - OCA\AppFramework\Core\API; + OCP\AppFramework\Controller; /** diff --git a/lib/dispatcher.php b/lib/dispatcher.php index bcbe70a8..09d069f7 100644 --- a/lib/dispatcher.php +++ b/lib/dispatcher.php @@ -57,7 +57,8 @@ class Dispatcher extends MainApp { parent::__construct($this->appName, $params); $this->container = $this->getContainer(); $this->server = $this->container->getServer(); - $this->app = new App($this->container->query('API')->getUserId()); + $userId = \OC::$server->getUserSession()->getUser()->getUID(); + $this->app = new App($userId); $this->registerServices(); $this->container->registerMiddleware('HttpMiddleware'); } @@ -76,8 +77,8 @@ class Dispatcher extends MainApp { }); $this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) { $request = $container->query('Request'); - $api = $container->query('API'); - return new AddressBookController($appName, $request, $app, $api); + $userId = \OC::$server->getUserSession()->getUser()->getUID(); + return new AddressBookController($appName, $request, $app, $userId); }); $this->container->registerService('BackendController', function(IAppContainer $container) use($app, $appName) { $request = $container->query('Request');