Remove deprecated API usage. Step 2

pull/1/head
Victor Dubiniuk 9 years ago
parent 8897dda9ab
commit 58725da687

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

@ -55,7 +55,6 @@ class Application extends App {
$c->query('AppName'), $c->query('AppName'),
$c->query('Request'), $c->query('Request'),
$c->query('CoreConfig'), $c->query('CoreConfig'),
$c->query('Logger'),
$c->query('L10N'), $c->query('L10N'),
$c->query('UserId') $c->query('UserId')
); );

@ -123,8 +123,8 @@ class SessionController extends Controller{
$member = new Db\Member(); $member = new Db\Member();
$member->load($memberId); $member->load($memberId);
if (!$member->getIsGuest()){ if (!$member->getIsGuest() && !\OCP\User::checkLoggedIn()){
\OCP\JSON::checkLoggedIn(); exit();
} }
try { try {
@ -236,7 +236,7 @@ class SessionController extends Controller{
if ($this->uid){ if ($this->uid){
$view = new View('/' . $this->uid . '/files'); $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'); $path = Helper::getNewFileName($view, $dir . 'New Document.odt');
} else { } else {
throw $e; throw $e;

@ -16,6 +16,7 @@ use \OCP\IRequest;
use \OCP\IConfig; use \OCP\IConfig;
use \OCP\IL10N; use \OCP\IL10N;
use \OCP\AppFramework\Http\JSONResponse; use \OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\Documents\Converter; use OCA\Documents\Converter;
use OCA\Documents\Config; use OCA\Documents\Config;
@ -23,16 +24,14 @@ use OCA\Documents\Filter;
class SettingsController extends Controller{ class SettingsController extends Controller{
private $uid; private $userId;
private $settings; private $settings;
private $logger;
private $l10n; 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); parent::__construct($appName, $request);
$this->uid = $uid; $this->userId = $userId;
$this->settings = $settings; $this->settings = $settings;
$this->logger = $logger;
$this->l10n = $l10n; $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 * @NoAdminRequired
@ -60,7 +98,7 @@ class SettingsController extends Controller{
} }
if ($status){ if ($status){
$this->settings->setUserValue($this->uid, $this->appName, 'save_path', $savePath); $this->settings->setUserValue($this->userId, $this->appName, 'save_path', $savePath);
$response = array( $response = array(
'status' => 'success', 'status' => 'success',
'data' => array('message'=> $this->l10n->t('Directory saved successfully.')) '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'); $currentConverter = $this->settings->getAppValue($this->appName, 'converter', 'off');
if ($currentConverter == 'external'){ if ($currentConverter == 'external'){
if (!Converter::checkConnection()){ 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( $response = array(
'status' => 'error', 'status' => 'error',
'data'=> 'data'=>

@ -66,11 +66,11 @@ class Config {
} }
protected static function getAppValue($key, $default){ 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){ 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 * @return string
*/ */
protected static function convertLocal($input, $targetFilter, $targetExtension){ protected static function convertLocal($input, $targetFilter, $targetExtension){
$infile = \OCP\Files::tmpFile(); $infile = \OC::$server->getTempManager()->getTemporaryFile();
$outdir = \OCP\Files::tmpFolder(); $outdir = \OC::$server->getTempManager()->getTemporaryFolder();
$cmd = Helper::findOpenOffice(); $cmd = Helper::findOpenOffice();
$params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' $params = ' --headless --convert-to ' . $targetFilter . ' --outdir '
. escapeshellarg($outdir) . escapeshellarg($outdir)

@ -12,6 +12,8 @@
namespace OCA\Documents\Db; namespace OCA\Documents\Db;
use OCP\Security\ISecureRandom;
use OCA\Documents\Filter; use OCA\Documents\Filter;
/** /**
@ -204,7 +206,9 @@ class Session extends \OCA\Documents\Db {
protected function getUniqueSessionId(){ protected function getUniqueSessionId(){
$testSession = new Session(); $testSession = new Session();
do{ do{
$id = \OC_Util::generateRandomBytes(30); $id = \OC::$server->getSecureRandom()
->getMediumStrengthGenerator()
->generate(30, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
} while ($testSession->load($id)->hasData()); } while ($testSession->load($id)->hasData());
return $id; return $id;

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

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

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

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

@ -1,7 +1,10 @@
<?php
script('documents', 'personal');
?>
<div class="section" id="documents-personal"> <div class="section" id="documents-personal">
<h2><?php p($l->t('Documents')); ?></h2> <h2><?php p($l->t('Documents')); ?></h2>
<div> <div>
<label for="documents-default-path"><?php p($l->t('Save new documents to')) ?></label> <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>
</div> </div>

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

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

Loading…
Cancel
Save