mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Remove use of deprecated API class
This commit is contained in:
parent
513b1d6875
commit
ac70af510d
@ -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());
|
||||
$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()) {
|
||||
\OCP\Contacts::registerAddressBook($addressBook->getSearchProvider());
|
||||
$cm->registerAddressBook($addressBook->getSearchProvider());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class App {
|
||||
/**
|
||||
* @brief language object for calendar app
|
||||
*
|
||||
* @var OC_L10N
|
||||
* @var \OCP\IL10N
|
||||
*/
|
||||
public static $l10n;
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user