From 8897dda9abcda72052ce82a6f81399ef218e61a9 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 26 Aug 2015 19:09:34 +0300 Subject: [PATCH] Remove deprected API usage. Step 1 --- appinfo/app.php | 4 +-- appinfo/application.php | 4 +-- appinfo/routes.php | 51 ++++++++++++---------------- appinfo/update.php | 14 ++++---- controller/documentcontroller.php | 18 ++++++++++ index.php | 55 ------------------------------- lib/helper.php | 5 +-- templates/documents.php | 8 +++++ 8 files changed, 62 insertions(+), 97 deletions(-) delete mode 100644 index.php diff --git a/appinfo/app.php b/appinfo/app.php index 82a380ed..4155214e 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -36,8 +36,8 @@ $navigationEntry = function () use ($c) { return [ 'id' => 'documents_index', 'order' => 2, - 'href' => \OCP\Util::linkTo('documents/', 'index.php'), - 'icon' => \OCP\Util::imagePath('documents', 'documents.svg'), + 'href' => $c->query('ServerContainer')->getURLGenerator()->linkToRoute('documents.document.index'), + 'icon' => $c->query('ServerContainer')->getURLGenerator()->imagePath('documents', 'documents.svg'), 'name' => $c->query('L10N')->t('Documents') ]; }; diff --git a/appinfo/application.php b/appinfo/application.php index f44fd803..d270daf0 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -73,8 +73,8 @@ class Application extends App { $container->registerService('L10N', function($c) { return $c->query('ServerContainer')->getL10N($c->query('AppName')); }); - $container->registerService('UserId', function() { - return \OCP\User::getUser(); + $container->registerService('UserId', function($c) { + return $c->query('ServerContainer')->getUserSession()->getUser()->getUID(); }); } } diff --git a/appinfo/routes.php b/appinfo/routes.php index 016c1864..c765fea6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -12,37 +12,28 @@ namespace OCA\Documents; $application = new \OCA\Documents\AppInfo\Application(); -$application->registerRoutes($this, array( - 'routes' => array( +$application->registerRoutes($this, [ + 'routes' => [ //users - array('name' => 'user#rename', 'url' => 'ajax/user/rename', 'verb' => 'POST'), - array('name' => 'user#disconnectUser', 'url' => 'ajax/user/disconnect', 'verb' => 'POST'), - array('name' => 'user#disconnectGuest', 'url' => 'ajax/user/disconnectGuest', 'verb' => 'POST'), + ['name' => 'user#rename', 'url' => 'ajax/user/rename', 'verb' => 'POST'], + ['name' => 'user#disconnectUser', 'url' => 'ajax/user/disconnect', 'verb' => 'POST'], + ['name' => 'user#disconnectGuest', 'url' => 'ajax/user/disconnectGuest', 'verb' => 'POST'], //session - array('name' => 'session#joinAsUser', 'url' => 'ajax/session/joinasuser/{fileId}', 'verb' => 'POST'), - array('name' => 'session#joinAsGuest', 'url' => 'ajax/session/joinasguest/{token}', 'verb' => 'POST'), - array('name' => 'session#save', 'url' => 'ajax/session/save', 'verb' => 'POST'), - array('name' => 'session#poll', 'url' => 'ajax/otpoll.php', 'verb' => 'POST'), + ['name' => 'session#joinAsUser', 'url' => 'ajax/session/joinasuser/{fileId}', 'verb' => 'POST'], + ['name' => 'session#joinAsGuest', 'url' => 'ajax/session/joinasguest/{token}', 'verb' => 'POST'], + ['name' => 'session#save', 'url' => 'ajax/session/save', 'verb' => 'POST'], + ['name' => 'session#poll', 'url' => 'ajax/otpoll.php', 'verb' => 'POST'], //documents - array('name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'), - array('name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => 'GET'), - array('name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'), - array('name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'), - array('name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'), + ['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'], + ['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'], + ['name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => 'GET'], + ['name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'], + ['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'], + ['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'], //settings - array('name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'), - array('name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'), - array('name' => 'settings#setConverter', 'url' => 'ajax/admin.php', 'verb' => 'POST'), - array('name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'), - ) -)); - -/** - * Document routes - */ - -/** @var $this \OC\Route\Router */ - -$this->create('documents_index', '') - ->get() - ->actionInclude('documents/index.php'); + ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'], + ['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'], + ['name' => 'settings#setConverter', 'url' => 'ajax/admin.php', 'verb' => 'POST'], + ['name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'], + ] +]); diff --git a/appinfo/update.php b/appinfo/update.php index 9a7e2b03..8406ae51 100644 --- a/appinfo/update.php +++ b/appinfo/update.php @@ -9,16 +9,18 @@ * later. */ -$installedVersion = \OCP\Config::getAppValue('documents', 'installed_version'); +$config = \OC::$server->getConfig(); +$dbConnection = \OC::$server->getDatabaseConnection(); +$installedVersion = $config->getAppValue('documents', 'installed_version'); -$cleanup = \OC_DB::prepare('DELETE FROM `*PREFIX*documents_member` WHERE `last_activity`=0 or `last_activity` is NULL'); +$cleanup = $dbConnection->prepare('DELETE FROM `*PREFIX*documents_member` WHERE `last_activity`=0 or `last_activity` is NULL'); $cleanup->execute(); if (version_compare($installedVersion, '0.7', '<=')) { - \OCP\Config::setAppValue('documents', 'unstable', 'false'); + $config->setAppValue('documents', 'unstable', 'false'); $session = new \OCA\Documents\Db\Session(); - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_session` SET `genesis_url`=? WHERE `es_id`=?'); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_session` SET `genesis_url`=? WHERE `es_id`=?'); foreach ($session->getCollection() as $sessionData){ $sessionData['genesis_url'] = \OCA\Documents\Genesis::DOCUMENTS_DIRNAME . $sessionData['genesis_url']; @@ -30,12 +32,12 @@ if (version_compare($installedVersion, '0.7', '<=')) { } } if (version_compare($installedVersion, '0.8', '<')) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' '); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' '); $query->execute(array()); } if (version_compare($installedVersion, '0.9', '<')) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_op` SET `optype`=? WHERE `seq`=?'); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_op` SET `optype`=? WHERE `seq`=?'); $ops = new \OCA\Documents\Db\Op(); foreach ($ops->getCollection() as $opData){ $opSpec = json_decode($opData['opspec'], true); diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index 62dd9f39..c1137b7d 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -16,6 +16,7 @@ use \OCP\IRequest; use \OCP\IConfig; use \OCP\IL10N; use \OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\TemplateResponse; use \OCA\Documents\Db; use \OCA\Documents\Helper; @@ -41,6 +42,23 @@ class DocumentController extends Controller{ $this->settings = $settings; } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(){ + \OC::$server->getNavigationManager()->setActiveEntry( 'documents_index' ); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); + return new TemplateResponse('documents', 'documents', [ + 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), + 'useUnstable' => $this->settings->getAppValue('documents', 'unstable', 'false'), + 'savePath' => $this->settings->getUserValue($this->uid, 'documents', 'save_path', '/'), + 'uploadMaxFilesize' => $maxUploadFilesize, + 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), + 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), + ]); + } + /** * @NoAdminRequired */ diff --git a/index.php b/index.php deleted file mode 100644 index b9eda8b5..00000000 --- a/index.php +++ /dev/null @@ -1,55 +0,0 @@ -. - * - */ - - -namespace OCA\Documents; - -\OCP\User::checkLoggedIn(); -\OCP\JSON::checkAppEnabled('documents'); -\OCP\App::setActiveNavigationEntry( 'documents_index' ); - -\OCP\Util::addStyle( 'documents', 'style' ); -\OCP\Util::addStyle( 'documents', '3rdparty/webodf/dojo-app' ); - -\OCP\Util::addScript('documents', 'documents'); - -\OCP\Util::addScript('files', 'file-upload'); -\OCP\Util::addScript('files', 'jquery.iframe-transport'); -\OCP\Util::addScript('files', 'jquery.fileupload'); - - -$tmpl = new \OCP\Template('documents', 'documents', 'user'); - -$previewsEnabled = \OC::$server->getConfig()->getSystemValue('enable_previews', true); -$unstable = \OCP\Config::getAppValue('documents', 'unstable', 'false'); -$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); -$savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); - -$tmpl->assign('enable_previews', $previewsEnabled); -$tmpl->assign('useUnstable', $unstable); -$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); -$tmpl->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); -$tmpl->assign('savePath', $savePath); -$tmpl->assign("allowShareWithLink", \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes')); - -$tmpl->printPage(); diff --git a/lib/helper.php b/lib/helper.php index a351672f..e6ffaee5 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -161,9 +161,10 @@ class Helper { } public static function findOpenOffice(){ + $config = \OC::$server->getConfig(); $cmd = ''; - if (is_string(\OC_Config::getValue('preview_libreoffice_path', null))){ - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + if (is_string($config->getSystemValue('preview_libreoffice_path', null))){ + $cmd = $config->getSystemValue('preview_libreoffice_path', null); } $whichLibreOffice = shell_exec('which libreoffice'); diff --git a/templates/documents.php b/templates/documents.php index 07b1bb06..20e0bef4 100644 --- a/templates/documents.php +++ b/templates/documents.php @@ -1,3 +1,11 @@ +