Merge pull request #536 from owncloud/code-checker

Remove deprecated API usage
pull/1/head
VicDeo 9 years ago
commit 1e6160adce

@ -2,10 +2,9 @@
namespace OCA\Documents;
\OCP\Util::addScript('documents', 'admin');
use \OCA\Documents\AppInfo\Application;
$tmpl = new \OCP\Template('documents', 'admin');
$tmpl->assign('converter', Config::getConverter());
$tmpl->assign('converter_url', Config::getConverterUrl());
$app = new Application();
$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->adminIndex();
return $response->render();
return $tmpl->fetchPage();

@ -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')
];
};

@ -55,7 +55,6 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('CoreConfig'),
$c->query('Logger'),
$c->query('L10N'),
$c->query('UserId')
);
@ -73,8 +72,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();
});
}
}

@ -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'],
]
]);

@ -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);

@ -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
*/

@ -236,7 +236,7 @@ class SessionController extends Controller{
if ($this->uid){
$view = new View('/' . $this->uid . '/files');
$dir = \OCP\Config::getUserValue($this->uid, 'documents', 'save_path', '');
$dir = \OC::$server->getConfig()->getUserValue($this->uid, 'documents', 'save_path', '');
$path = Helper::getNewFileName($view, $dir . 'New Document.odt');
} else {
throw $e;

@ -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\Converter;
use OCA\Documents\Config;
@ -23,16 +24,14 @@ use OCA\Documents\Filter;
class SettingsController extends Controller{
private $uid;
private $userId;
private $settings;
private $logger;
private $l10n;
public function __construct($appName, IRequest $request, IConfig $settings, $logger, IL10N $l10n, $uid){
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $userId){
parent::__construct($appName, $request);
$this->uid = $uid;
$this->userId = $userId;
$this->settings = $settings;
$this->logger = $logger;
$this->l10n = $l10n;
}
@ -46,6 +45,45 @@ class SettingsController extends Controller{
);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function personalIndex(){
return new TemplateResponse(
'documents',
'personal',
[ 'save_path' => $this->settings->getUserValue($this->userId, 'documents', 'save_path', '/') ],
'blank'
);
}
/**
* @NoCSRFRequired
*/
public function settingsIndex(){
return new TemplateResponse(
'documents',
'settings',
[ 'unstable' => $this->settings->getAppValue('documents', 'unstable', 'false') ],
'blank'
);
}
/**
* @NoCSRFRequired
*/
public function adminIndex(){
return new TemplateResponse(
'documents',
'admin',
[
'converter' => Config::getConverter(),
'converter_url' => Config::getConverterUrl(),
],
'blank'
);
}
/**
* @NoAdminRequired
@ -60,7 +98,7 @@ class SettingsController extends Controller{
}
if ($status){
$this->settings->setUserValue($this->uid, $this->appName, 'save_path', $savePath);
$this->settings->setUserValue($this->userId, $this->appName, 'save_path', $savePath);
$response = array(
'status' => 'success',
'data' => array('message'=> $this->l10n->t('Directory saved successfully.'))
@ -100,7 +138,10 @@ class SettingsController extends Controller{
$currentConverter = $this->settings->getAppValue($this->appName, 'converter', 'off');
if ($currentConverter == 'external'){
if (!Converter::checkConnection()){
$this->logger->warning('Bad response from Format Filter Server', array('app' => $this->appName));
\OC::$server->getLogger()->warning(
'Bad response from Format Filter Server',
['app' => $this->appName]
);
$response = array(
'status' => 'error',
'data'=>

@ -1,55 +0,0 @@
<?php
/**
* ownCloud - Documents App
*
* @author Frank Karlitschek
* @copyright 2013-2014 Frank Karlitschek karlitschek@kde.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
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();

@ -20,8 +20,8 @@ class Config {
$targetFilter = 'odt:writer8';
$targetExtension = 'odt';
$input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH);
$infile = \OCP\Files::tmpFile();
$outdir = \OCP\Files::tmpFolder();
$infile = \OC::$server->getTempManager()->getTemporaryFile();
$outdir = \OC::$server->getTempManager()->getTemporaryFolder();
$outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension;
$cmd = Helper::findOpenOffice();
@ -66,11 +66,11 @@ class Config {
}
protected static function getAppValue($key, $default){
return \OCP\Config::getAppValue(self::APP_NAME, $key, $default);
return \OC::$server->getConfig()->getAppValue(self::APP_NAME, $key, $default);
}
protected static function setAppValue($key, $value){
return \OCP\Config::setAppValue(self::APP_NAME, $key, $value);
return \OC::$server->getConfig()->setAppValue(self::APP_NAME, $key, $value);
}
}

@ -43,8 +43,8 @@ class Converter {
* @return string
*/
protected static function convertLocal($input, $targetFilter, $targetExtension){
$infile = \OCP\Files::tmpFile();
$outdir = \OCP\Files::tmpFolder();
$infile = \OC::$server->getTempManager()->getTemporaryFile();
$outdir = \OC::$server->getTempManager()->getTemporaryFolder();
$cmd = Helper::findOpenOffice();
$params = ' --headless --convert-to ' . $targetFilter . ' --outdir '
. escapeshellarg($outdir)

@ -43,7 +43,7 @@ abstract class Db {
* @return mixed
*/
public function getLastInsertId(){
return \OCP\DB::insertid($this->tableName);
return \OC::$server->getDatabaseConnection()->lastInsertId($this->tableName);
}
/**

@ -12,6 +12,8 @@
namespace OCA\Documents\Db;
use OCP\Security\ISecureRandom;
use OCA\Documents\Filter;
/**
@ -88,6 +90,7 @@ class Session extends \OCA\Documents\Db {
if (!$member->insert()){
throw new \Exception('Failed to add member into database');
}
$sessionData['member_id'] = (string) $member->getLastInsertId();
// Do we have OC_Avatar in out disposal?
if (\OC_Config::getValue('enable_avatars', true) !== true){
@ -96,10 +99,11 @@ class Session extends \OCA\Documents\Db {
$imageUrl = $uid;
}
$displayName = $file->isPublicShare() ? $uid . ' ' . \OCA\Documents\Db\Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
$userId = $file->isPublicShare() ? $displayName : \OCP\User::getUser();
$sessionData['member_id'] = (string) $member->getLastInsertId();
$displayName = $file->isPublicShare()
? $uid . ' ' . \OCA\Documents\Db\Member::getGuestPostfix()
: \OC::$server->getUserSession()->getUser()->getDisplayName($uid)
;
$userId = $file->isPublicShare() ? $displayName : \OC::$server->getUserSession()->getUser()->getUID();
$op = new \OCA\Documents\Db\Op();
$op->addMember(
$sessionData['es_id'],
@ -188,10 +192,10 @@ class Session extends \OCA\Documents\Db {
WHERE `s`.`es_id` = ?
GROUP BY `m`.`es_id`
',
array(
\OCP\User::getUser(),
[
\OC::$server->getUserSession()->getUser()->getUID(),
$esId
)
]
);
$info = $result->fetchRow();
@ -204,7 +208,9 @@ class Session extends \OCA\Documents\Db {
protected function getUniqueSessionId(){
$testSession = new Session();
do{
$id = \OC_Util::generateRandomBytes(30);
$id = \OC::$server->getSecureRandom()
->getMediumStrengthGenerator()
->generate(30, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
} while ($testSession->load($id)->hasData());
return $id;

@ -147,7 +147,10 @@ class File {
if ($this->isPublicShare()){
if (isset($this->sharing['uid_owner'])){
$owner = $this->sharing['uid_owner'];
\OCP\JSON::checkUserExists($this->sharing['uid_owner']);
if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) {
throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist ');
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($this->sharing['uid_owner']);
} else {
@ -155,7 +158,7 @@ class File {
}
$view = new View('/' . $owner . '/files');
} else {
$owner = \OCP\User::getUser();
$owner = \OC::$server->getUserSession()->getUser()->getUID();
$root = '/' . $owner;
if ($useDefaultRoot){
$root .= '/' . 'files';

@ -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');

@ -12,10 +12,8 @@
namespace OCA\Documents;
\OCP\Util::addScript('documents', 'personal');
use \OCA\Documents\AppInfo\Application;
$tmpl = new \OCP\Template('documents', 'personal');
$savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/');
$tmpl->assign('savePath', $savePath);
return $tmpl->fetchPage();
$app = new Application();
$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->personalIndex();
return $response->render();

@ -15,8 +15,6 @@ namespace OCA\Documents;
\OCP\JSON::checkAppEnabled('documents');
\OCP\Util::addStyle( 'documents', 'style' );
if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');

@ -12,10 +12,8 @@
namespace OCA\Documents;
\OCP\Util::addScript('documents', 'settings');
use \OCA\Documents\AppInfo\Application;
$tmpl = new \OCP\Template('documents', 'settings');
$unstable = \OCP\Config::getAppValue('documents', 'unstable', 'false');
$tmpl->assign('unstable', $unstable);
return $tmpl->fetchPage();
$app = new Application();
$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->settingsIndex();
return $response->render();

@ -1,3 +1,6 @@
<?php
script('documents', 'admin');
?>
<div class="section" id="documents">
<h2><?php p($l->t('Documents')) ?></h2>
<p><?php p($l->t('MS Word support (requires openOffice/libreOffice)')) ?></p>

@ -1,3 +1,11 @@
<?php
style( 'documents', 'style' );
style( 'documents', '3rdparty/webodf/dojo-app' );
script('documents', 'documents');
script('files', 'file-upload');
script('files', 'jquery.iframe-transport');
script('files', 'jquery.fileupload');
?>
<div id="documents-content">
<ul class="documentslist">
<li class="add-document">

@ -1,7 +1,10 @@
<?php
script('documents', 'personal');
?>
<div class="section" id="documents-personal">
<h2><?php p($l->t('Documents')); ?></h2>
<div>
<label for="documents-default-path"><?php p($l->t('Save new documents to')) ?></label>
<input type="text" id="documents-default-path" value="<?php p($_['savePath']) ?>" /><span class="msg"></span>
<input type="text" id="documents-default-path" value="<?php p($_['save_path']) ?>" /><span class="msg"></span>
</div>
</div>

@ -1,3 +1,6 @@
<?php
style( 'documents', 'style' );
?>
<div id="notification-container">
<div id="notification" style="display: none;"></div>
</div>

@ -1,3 +1,6 @@
<?php
script('documents', 'settings');
?>
<div id="documents" class="section">
<h2><?php p($l->t('Documents')) ?></h2>
<input id="webodf-unstable" type ="checkbox"

Loading…
Cancel
Save