mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Align controllers to owncloud/core#8017
This commit is contained in:
parent
a1e16fec23
commit
70438c997d
@ -36,10 +36,8 @@ class Controller extends BaseController {
|
|||||||
*/
|
*/
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
public function __construct(IAppContainer $container, App $app) {
|
public function __construct($appName, IRequest $request, App $app) {
|
||||||
$this->api = $container->query('API');
|
parent::__construct($appName, $request);
|
||||||
$this->request = $container->query('Request');
|
|
||||||
$this->server = $container->getServer();
|
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,13 +14,21 @@ use OCA\Contacts\App,
|
|||||||
OCA\Contacts\ImageResponse,
|
OCA\Contacts\ImageResponse,
|
||||||
OCA\Contacts\Utils\Properties,
|
OCA\Contacts\Utils\Properties,
|
||||||
OCA\Contacts\Utils\TemporaryPhoto,
|
OCA\Contacts\Utils\TemporaryPhoto,
|
||||||
OCA\Contacts\Controller;
|
OCA\Contacts\Controller,
|
||||||
|
OCP\IRequest,
|
||||||
|
OCP\ICache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller class For Contacts
|
* Controller class For Contacts
|
||||||
*/
|
*/
|
||||||
class ContactPhotoController extends Controller {
|
class ContactPhotoController extends Controller {
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, App $app, ICache $cache) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
$this->app = $app;
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
@ -34,7 +42,7 @@ class ContactPhotoController extends Controller {
|
|||||||
$contact = $addressBook->getChild($params['contactId']);
|
$contact = $addressBook->getChild($params['contactId']);
|
||||||
|
|
||||||
$tempPhoto = TemporaryPhoto::create(
|
$tempPhoto = TemporaryPhoto::create(
|
||||||
$this->server,
|
$this->cache,
|
||||||
TemporaryPhoto::PHOTO_CURRENT,
|
TemporaryPhoto::PHOTO_CURRENT,
|
||||||
$contact
|
$contact
|
||||||
);
|
);
|
||||||
|
@ -13,37 +13,44 @@ namespace OCA\Contacts\Controller;
|
|||||||
use OCA\Contacts\App,
|
use OCA\Contacts\App,
|
||||||
OCA\Contacts\JSONResponse,
|
OCA\Contacts\JSONResponse,
|
||||||
OCA\Contacts\Controller,
|
OCA\Contacts\Controller,
|
||||||
OCP\AppFramework\Http;
|
OCP\AppFramework\Http,
|
||||||
|
OCP\ITags,
|
||||||
|
OCP\IRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller class for groups/categories
|
* Controller class for groups/categories
|
||||||
*/
|
*/
|
||||||
class GroupController extends Controller {
|
class GroupController extends Controller {
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, App $app, ITags $tags) {
|
||||||
|
parent::__construct($appName, $request, $app);
|
||||||
|
$this->app = $app;
|
||||||
|
$this->tagMgr = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function getGroups() {
|
public function getGroups() {
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
$tags = $this->tagMgr->getTags();
|
||||||
$tags = $tagMgr->getTags();
|
|
||||||
|
|
||||||
foreach ($tags as &$tag) {
|
foreach ($tags as &$tag) {
|
||||||
try {
|
try {
|
||||||
$ids = $tagMgr->getIdsForTag($tag['name']);
|
$ids = $this->tagMgr->getIdsForTag($tag['name']);
|
||||||
$tag['contacts'] = $ids;
|
$tag['contacts'] = $ids;
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->api->log(__METHOD__ . ' ' . $e->getMessage());
|
$this->api->log(__METHOD__ . ' ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$favorites = $tagMgr->getFavorites();
|
$favorites = $this->tagMgr->getFavorites();
|
||||||
|
|
||||||
$groups = array(
|
$groups = array(
|
||||||
'categories' => $tags,
|
'categories' => $tags,
|
||||||
'favorites' => $favorites,
|
'favorites' => $favorites,
|
||||||
'shared' => \OCP\Share::getItemsSharedWith('addressbook', \OCA\Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS),
|
'shared' => \OCP\Share::getItemsSharedWith('addressbook', \OCA\Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS),
|
||||||
'lastgroup' => \OCP\Config::getUserValue($this->api->getUserId(), 'contacts', 'lastgroup', 'all'),
|
'lastgroup' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'lastgroup', 'all'),
|
||||||
'sortorder' => \OCP\Config::getUserValue($this->api->getUserId(), 'contacts', 'groupsort', ''),
|
'sortorder' => \OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'groupsort', ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new JSONResponse($groups);
|
return new JSONResponse($groups);
|
||||||
@ -61,8 +68,7 @@ class GroupController extends Controller {
|
|||||||
$response->bailOut(App::$l10n->t('No group name given.'));
|
$response->bailOut(App::$l10n->t('No group name given.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
$id = $this->tagMgr->add($name);
|
||||||
$id = $tagMgr->add($name);
|
|
||||||
|
|
||||||
if ($id === false) {
|
if ($id === false) {
|
||||||
$response->bailOut(App::$l10n->t('Error adding group.'));
|
$response->bailOut(App::$l10n->t('Error adding group.'));
|
||||||
@ -85,10 +91,8 @@ class GroupController extends Controller {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$ids = $tagMgr->getIdsForTag($name);
|
$ids = $this->tagMgr->getIdsForTag($name);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$response->setErrorMessage($e->getMessage());
|
$response->setErrorMessage($e->getMessage());
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
|
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
|
||||||
@ -124,7 +128,7 @@ class GroupController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$tagMgr->delete($name);
|
$this->tagMgr->delete($name);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$response->setErrorMessage($e->getMessage());
|
$response->setErrorMessage($e->getMessage());
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
|
\OCP\Util::writeLog('contacts', __METHOD__.', ' . $e->getMessage(), \OCP\Util::ERROR);
|
||||||
@ -152,14 +156,12 @@ class GroupController extends Controller {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
if (!$this->tagMgr->rename($from, $to)) {
|
||||||
|
|
||||||
if (!$tagMgr->rename($from, $to)) {
|
|
||||||
$response->bailOut(App::$l10n->t('Error renaming group.'));
|
$response->bailOut(App::$l10n->t('Error renaming group.'));
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = $tagMgr->getIdsForTag($to);
|
$ids = $this->tagMgr->getIdsForTag($to);
|
||||||
|
|
||||||
if ($ids !== false) {
|
if ($ids !== false) {
|
||||||
|
|
||||||
@ -225,7 +227,6 @@ class GroupController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$backend = $this->app->getBackend('local');
|
$backend = $this->app->getBackend('local');
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
|
||||||
|
|
||||||
foreach ($ids as $contactId) {
|
foreach ($ids as $contactId) {
|
||||||
|
|
||||||
@ -244,7 +245,7 @@ class GroupController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
||||||
$tagMgr->tagAs($contactId, $categoryId);
|
$this->tagMgr->tagAs($contactId, $categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
@ -283,7 +284,6 @@ class GroupController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$backend = $this->app->getBackend('local');
|
$backend = $this->app->getBackend('local');
|
||||||
$tagMgr = $this->server->getTagManager()->load('contact');
|
|
||||||
|
|
||||||
foreach ($ids as $contactId) {
|
foreach ($ids as $contactId) {
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ class GroupController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
$response->debug('contactId: ' . $contactId . ', categoryId: ' . $categoryId);
|
||||||
$tagMgr->unTag($contactId, $categoryId);
|
$this->tagMgr->unTag($contactId, $categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -15,13 +15,20 @@ use OCA\Contacts\App,
|
|||||||
OCA\Contacts\Controller,
|
OCA\Contacts\Controller,
|
||||||
Sabre\VObject,
|
Sabre\VObject,
|
||||||
OCA\Contacts\VObject\VCard as MyVCard,
|
OCA\Contacts\VObject\VCard as MyVCard,
|
||||||
OCA\Contacts\ImportManager;
|
OCA\Contacts\ImportManager,
|
||||||
|
OCP\IRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller importing contacts
|
* Controller importing contacts
|
||||||
*/
|
*/
|
||||||
class ImportController extends Controller {
|
class ImportController extends Controller {
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, App $app, ICache $cache) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
$this->app = $app;
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
@ -150,7 +157,7 @@ class ImportController extends Controller {
|
|||||||
$request = $this->request;
|
$request = $this->request;
|
||||||
$response = new JSONResponse();
|
$response = new JSONResponse();
|
||||||
$params = $this->request->urlParams;
|
$params = $this->request->urlParams;
|
||||||
$app = new App($this->api->getUserId());
|
$app = new App(\OCP\User::getUser());
|
||||||
$addressBookId = $params['addressBookId'];
|
$addressBookId = $params['addressBookId'];
|
||||||
$format = $params['importType'];
|
$format = $params['importType'];
|
||||||
|
|
||||||
@ -186,16 +193,16 @@ class ImportController extends Controller {
|
|||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
|
||||||
$writeProgress = function($pct, $total) use ($progresskey) {
|
$writeProgress = function($pct, $total) use ($progresskey) {
|
||||||
\OC_Cache::set($progresskey, $pct, 300);
|
$this->cache->set($progresskey, $pct, 300);
|
||||||
\OC_Cache::set($progresskey.'_total', $total, 300);
|
$this->cache->set($progresskey.'_total', $total, 300);
|
||||||
};
|
};
|
||||||
|
|
||||||
$cleanup = function() use ($view, $filename, $progresskey, $response) {
|
$cleanup = function() use ($view, $filename, $progresskey, $response) {
|
||||||
if(!$view->unlink('/imports/' . $filename)) {
|
if(!$view->unlink('/imports/' . $filename)) {
|
||||||
$response->debug('Unable to unlink /imports/' . $filename);
|
$response->debug('Unable to unlink /imports/' . $filename);
|
||||||
}
|
}
|
||||||
\OC_Cache::remove($progresskey);
|
$this->cache->remove($progresskey);
|
||||||
\OC_Cache::remove($progresskey.'_total');
|
$this->cache->remove($progresskey.'_total');
|
||||||
};
|
};
|
||||||
|
|
||||||
$importManager = new ImportManager();
|
$importManager = new ImportManager();
|
||||||
@ -301,8 +308,8 @@ class ImportController extends Controller {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("progresskey: ".\OC_Cache::get($progresskey)." total: ".\OC_Cache::get($progresskey.'_total') );
|
error_log("progresskey: ".$this->cache->get($progresskey)." total: ".$this->cache->get($progresskey.'_total') );
|
||||||
$response->setParams(array('progress' => \OC_Cache::get($progresskey), 'total' => \OC_Cache::get($progresskey.'_total') ));
|
$response->setParams(array('progress' => $this->cache->get($progresskey), 'total' => $this->cache->get($progresskey.'_total') ));
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
namespace OCA\Contacts\Controller;
|
namespace OCA\Contacts\Controller;
|
||||||
|
|
||||||
use OCA\Contacts\App,
|
use OCA\Contacts\App,
|
||||||
OCA\Contacts\Controller,
|
OCP\AppFramework\Controller,
|
||||||
OCA\Contacts\Utils\Properties,
|
OCA\Contacts\Utils\Properties,
|
||||||
OCP\AppFramework\Http\TemplateResponse;
|
OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ class PageController extends Controller {
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
\OC::$server->getNavigationManager()->setActiveEntry('contacts');
|
\OC::$server->getNavigationManager()->setActiveEntry($this->appName);
|
||||||
|
|
||||||
$imppTypes = Properties::getTypesForProperty('IMPP');
|
$imppTypes = Properties::getTypesForProperty('IMPP');
|
||||||
$adrTypes = Properties::getTypesForProperty('ADR');
|
$adrTypes = Properties::getTypesForProperty('ADR');
|
||||||
@ -58,7 +58,7 @@ class PageController extends Controller {
|
|||||||
\OCP\Util::addStyle('3rdparty/Jcrop', 'jquery.Jcrop');
|
\OCP\Util::addStyle('3rdparty/Jcrop', 'jquery.Jcrop');
|
||||||
\OCP\Util::addStyle('contacts', 'contacts');
|
\OCP\Util::addStyle('contacts', 'contacts');
|
||||||
|
|
||||||
$response = new TemplateResponse('contacts', 'contacts');
|
$response = new TemplateResponse($this->appName, 'contacts');
|
||||||
$response->setParams(array(
|
$response->setParams(array(
|
||||||
'uploadMaxFilesize' => $maxUploadFilesize,
|
'uploadMaxFilesize' => $maxUploadFilesize,
|
||||||
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
|
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
|
||||||
|
@ -12,7 +12,7 @@ namespace OCA\Contacts\Controller;
|
|||||||
|
|
||||||
use OCA\Contacts\App,
|
use OCA\Contacts\App,
|
||||||
OCA\Contacts\JSONResponse,
|
OCA\Contacts\JSONResponse,
|
||||||
OCA\Contacts\Controller,
|
OCP\AppFramework\Controller,
|
||||||
OCA\AppFramework\Core\API;
|
OCA\AppFramework\Core\API;
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class SettingsController extends Controller {
|
|||||||
$response->bailOut(App::$l10n->t('No value is given.'));
|
$response->bailOut(App::$l10n->t('No value is given.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(\OCP\Config::setUserValue($this->api->getUserId(), 'contacts', $key, $value)) {
|
if(\OCP\Config::setUserValue(\OCP\User::getUser(), 'contacts', $key, $value)) {
|
||||||
$response->setParams(array(
|
$response->setParams(array(
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value)
|
'value' => $value)
|
||||||
|
@ -30,44 +30,75 @@ use OCP\AppFramework\App as MainApp,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Dispatcher extends MainApp {
|
class Dispatcher extends MainApp {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var App
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OCA\Contacts\App
|
||||||
*/
|
*/
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OCP\IServerContainer
|
||||||
|
*/
|
||||||
|
protected $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OCP\AppFramework\IAppContainer
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
public function __construct($params) {
|
public function __construct($params) {
|
||||||
parent::__construct('contacts', $params);
|
$this->appName = 'contacts';
|
||||||
|
parent::__construct($this->appName, $params);
|
||||||
$this->container = $this->getContainer();
|
$this->container = $this->getContainer();
|
||||||
$this->container->registerMiddleware(new HttpMiddleware());
|
$this->container->registerMiddleware(new HttpMiddleware());
|
||||||
|
$this->server = $this->container->getServer();
|
||||||
$this->app = new App($this->container->query('API')->getUserId());
|
$this->app = new App($this->container->query('API')->getUserId());
|
||||||
$this->registerServices();
|
$this->registerServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerServices() {
|
public function registerServices() {
|
||||||
|
$appName = $this->appName;
|
||||||
$app = $this->app;
|
$app = $this->app;
|
||||||
$this->container->registerService('PageController', function(IAppContainer $container) use($app) {
|
|
||||||
return new PageController($container, $app);
|
$this->container->registerService('PageController', function(IAppContainer $container) use($app, $appName) {
|
||||||
|
$request = $container->query('Request');
|
||||||
|
return new PageController($appName, $request);
|
||||||
});
|
});
|
||||||
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new AddressBookController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
return new AddressBookController($appName, $request, $app);
|
||||||
});
|
});
|
||||||
$this->container->registerService('GroupController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('GroupController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new GroupController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
$tags = $this->server->getTagManager()->load('contact');
|
||||||
|
return new GroupController($this->appName, $request, $app, $tags);
|
||||||
});
|
});
|
||||||
$this->container->registerService('ContactController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('ContactController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new ContactController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
return new ContactController($this->appName, $request, $app);
|
||||||
});
|
});
|
||||||
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new ContactPhotoController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
$cache = $this->server->getCache();
|
||||||
|
return new ContactPhotoController($this->appName, $request, $app, $cache);
|
||||||
});
|
});
|
||||||
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new SettingsController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
return new SettingsController($this->appName, $request, $app);
|
||||||
});
|
});
|
||||||
$this->container->registerService('ImportController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('ImportController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new ImportController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
$cache = $this->server->getCache();
|
||||||
|
return new ImportController($this->appName, $request, $app, $cache);
|
||||||
});
|
});
|
||||||
$this->container->registerService('ExportController', function(IAppContainer $container) use($app) {
|
$this->container->registerService('ExportController', function(IAppContainer $container) use($app, $appName) {
|
||||||
return new ExportController($container, $app);
|
$request = $container->query('Request');
|
||||||
|
return new ExportController($this->appName, $request, $app);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
namespace OCA\Contacts\Utils;
|
namespace OCA\Contacts\Utils;
|
||||||
|
|
||||||
|
use OCP\ICache,
|
||||||
|
OCP\Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used for getting a temporary contact photo for cropping.
|
* This class is used for getting a temporary contact photo for cropping.
|
||||||
*
|
*
|
||||||
@ -82,8 +85,8 @@ class TemporaryPhoto {
|
|||||||
* Always call parents ctor:
|
* Always call parents ctor:
|
||||||
* parent::__construct($server);
|
* parent::__construct($server);
|
||||||
*/
|
*/
|
||||||
public function __construct(\OCP\IServerContainer $server, $key = null) {
|
public function __construct(ICache $cache, $key = null) {
|
||||||
$this->server = $server;
|
$this->cache = $cache;
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
if (!is_null($key)) {
|
if (!is_null($key)) {
|
||||||
$this->processImage();
|
$this->processImage();
|
||||||
@ -97,9 +100,9 @@ class TemporaryPhoto {
|
|||||||
* @param int|null $type One of the pre-defined types.
|
* @param int|null $type One of the pre-defined types.
|
||||||
* @param mixed|null $data Whatever data is needed to load the photo.
|
* @param mixed|null $data Whatever data is needed to load the photo.
|
||||||
*/
|
*/
|
||||||
public static function create(\OCP\IServerContainer $server, $type = null, $data = null) {
|
public static function create(ICache $cache, $type = null, $data = null) {
|
||||||
if (isset(self::$classMap[$type])) {
|
if (isset(self::$classMap[$type])) {
|
||||||
return new self::$classMap[$type]($server, $data);
|
return new self::$classMap[$type]($cache, $data);
|
||||||
} else {
|
} else {
|
||||||
return new self($data, $data);
|
return new self($data, $data);
|
||||||
}
|
}
|
||||||
@ -111,7 +114,7 @@ class TemporaryPhoto {
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
*/
|
*/
|
||||||
public function remove($key) {
|
public function remove($key) {
|
||||||
return $this->server->getCache()->remove($key);
|
return $this->cache->remove($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,8 +124,8 @@ class TemporaryPhoto {
|
|||||||
* instance of \OCP\Image.
|
* instance of \OCP\Image.
|
||||||
*/
|
*/
|
||||||
protected function processImage() {
|
protected function processImage() {
|
||||||
$this->image = new \OCP\Image();
|
$this->image = new Image();
|
||||||
$this->image->loadFromData($this->server->getCache()->get($this->key));
|
$this->image->loadFromData($this->cache->get($this->key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,7 +134,7 @@ class TemporaryPhoto {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isValid() {
|
public function isValid() {
|
||||||
return (($this->image instanceof \OCP\Image) && $this->image->valid());
|
return (($this->image instanceof Image) && $this->image->valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,14 +167,14 @@ class TemporaryPhoto {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->image instanceof \OCP\Image) {
|
if (!$this->image instanceof Image) {
|
||||||
$this->processImage();
|
$this->processImage();
|
||||||
}
|
}
|
||||||
$this->normalizePhoto();
|
$this->normalizePhoto();
|
||||||
|
|
||||||
$data = $this->image->data();
|
$data = $this->image->data();
|
||||||
$this->key = uniqid('photo-');
|
$this->key = uniqid('photo-');
|
||||||
$this->server->getCache()->set($this->key, $data, 600);
|
$this->cache->set($this->key, $data, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
namespace OCA\Contacts\Utils\TemporaryPhoto;
|
namespace OCA\Contacts\Utils\TemporaryPhoto;
|
||||||
|
|
||||||
use OCA\Contacts\Contact as ContactObject,
|
use OCA\Contacts\Contact as ContactObject,
|
||||||
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto;
|
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
|
||||||
|
OCP\ICache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class loads the PHOTO or LOGO property from a contact.
|
* This class loads the PHOTO or LOGO property from a contact.
|
||||||
@ -37,7 +38,7 @@ class Contact extends BaseTemporaryPhoto {
|
|||||||
*/
|
*/
|
||||||
protected $contact;
|
protected $contact;
|
||||||
|
|
||||||
public function __construct(\OCP\IServerContainer $server, $contact) {
|
public function __construct(ICache $cache, $contact) {
|
||||||
if (!$contact instanceof ContactObject) {
|
if (!$contact instanceof ContactObject) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
__METHOD__
|
__METHOD__
|
||||||
@ -45,7 +46,7 @@ class Contact extends BaseTemporaryPhoto {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($server);
|
parent::__construct($cache);
|
||||||
$this->contact = $contact;
|
$this->contact = $contact;
|
||||||
$this->processImage();
|
$this->processImage();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@ namespace OCA\Contacts\Utils\TemporaryPhoto;
|
|||||||
|
|
||||||
use OCA\Contacts\Contact as ContactObject,
|
use OCA\Contacts\Contact as ContactObject,
|
||||||
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
|
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
|
||||||
OCP\AppFramework\Http;
|
OCP\AppFramework\Http,
|
||||||
|
OCP\ICache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class loads an image from the virtual file system.
|
* This class loads an image from the virtual file system.
|
||||||
@ -38,7 +39,7 @@ class FileSystem extends BaseTemporaryPhoto {
|
|||||||
*/
|
*/
|
||||||
protected $path;
|
protected $path;
|
||||||
|
|
||||||
public function __construct(\OCP\IServerContainer $server, $path) {
|
public function __construct(ICache $cache, $path) {
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__.' path: ' . $path, \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('contacts', __METHOD__.' path: ' . $path, \OCP\Util::DEBUG);
|
||||||
if (!is_string($path)) {
|
if (!is_string($path)) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
@ -46,7 +47,7 @@ class FileSystem extends BaseTemporaryPhoto {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($server);
|
parent::__construct($cache);
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->processImage();
|
$this->processImage();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ use OCA\Contacts\Contact as ContactObject,
|
|||||||
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
|
OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
|
||||||
OCP\IRequest,
|
OCP\IRequest,
|
||||||
OCP\AppFramework\Http,
|
OCP\AppFramework\Http,
|
||||||
OCP\Image;
|
OCP\Image,
|
||||||
|
OCP\ICache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class loads an image from the virtual file system.
|
* This class loads an image from the virtual file system.
|
||||||
@ -40,7 +41,7 @@ class Uploaded extends BaseTemporaryPhoto {
|
|||||||
*/
|
*/
|
||||||
protected $input;
|
protected $input;
|
||||||
|
|
||||||
public function __construct(\OCP\IServerContainer $server, IRequest $request) {
|
public function __construct(ICache $cache, IRequest $request) {
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
|
||||||
if (!$request instanceOf IRequest) {
|
if (!$request instanceOf IRequest) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
@ -48,7 +49,7 @@ class Uploaded extends BaseTemporaryPhoto {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($server);
|
parent::__construct($cache);
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->processImage();
|
$this->processImage();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user