summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-06-24 08:27:25 +0200
committerBart Visscher <bartv@thisnet.nl>2013-06-24 08:27:25 +0200
commit377e9a8677afc92bca61fb1bb055901db8457896 (patch)
tree43d98d7d0d00823714cc6b23aa9366dc93a42609 /lib
parent0bff53eb639eb0271e9c20df91a18247f88a3e1f (diff)
parentaaecfa18edf7c690f06d0ce460bd3a7a98269845 (diff)
downloadnextcloud-server-377e9a8677afc92bca61fb1bb055901db8457896.tar.gz
nextcloud-server-377e9a8677afc92bca61fb1bb055901db8457896.zip
Merge branch 'master' into doctrine
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php6
-rw-r--r--lib/autoloader.php4
-rw-r--r--lib/backgroundjob/job.php49
-rw-r--r--lib/backgroundjob/joblist.php172
-rw-r--r--lib/backgroundjob/legacy/queuedjob.php18
-rw-r--r--lib/backgroundjob/legacy/regularjob.php15
-rw-r--r--lib/backgroundjob/queuedjob.php28
-rw-r--r--lib/backgroundjob/queuedtask.php105
-rw-r--r--lib/backgroundjob/regulartask.php52
-rw-r--r--lib/backgroundjob/timedjob.php41
-rw-r--r--lib/backgroundjob/worker.php118
-rw-r--r--lib/base.php73
-rw-r--r--lib/cache/file.php1
-rw-r--r--lib/cache/fileglobalgc.php8
-rw-r--r--lib/config.php2
-rw-r--r--lib/connector/sabre/locks.php52
-rw-r--r--lib/connector/sabre/maintenanceplugin.php3
-rw-r--r--lib/db.php113
-rw-r--r--lib/defaults.php74
-rw-r--r--lib/files.php5
-rw-r--r--lib/files/cache/backgroundwatcher.php10
-rw-r--r--lib/files/cache/cache.php162
-rw-r--r--lib/files/cache/legacy.php17
-rw-r--r--lib/files/cache/permissions.php52
-rw-r--r--lib/files/cache/scanner.php96
-rw-r--r--lib/files/cache/storage.php13
-rw-r--r--lib/files/cache/updater.php5
-rw-r--r--lib/files/cache/upgrade.php4
-rw-r--r--lib/files/filesystem.php36
-rw-r--r--lib/files/mapper.php58
-rw-r--r--lib/files/view.php42
-rw-r--r--lib/helper.php76
-rw-r--r--lib/hooks/publicemitter.php20
-rw-r--r--lib/l10n/bg_BG.php5
-rw-r--r--lib/l10n/ca.php1
-rw-r--r--lib/l10n/cs_CZ.php1
-rw-r--r--lib/l10n/da.php1
-rw-r--r--lib/l10n/de.php1
-rw-r--r--lib/l10n/de_DE.php1
-rw-r--r--lib/l10n/es.php1
-rw-r--r--lib/l10n/es_AR.php1
-rw-r--r--lib/l10n/et_EE.php1
-rw-r--r--lib/l10n/fr.php1
-rw-r--r--lib/l10n/gl.php1
-rw-r--r--lib/l10n/he.php2
-rw-r--r--lib/l10n/hu_HU.php1
-rw-r--r--lib/l10n/ja_JP.php1
-rw-r--r--lib/l10n/ko.php2
-rw-r--r--lib/l10n/lt_LT.php4
-rw-r--r--lib/l10n/nl.php1
-rw-r--r--lib/l10n/pl.php1
-rw-r--r--lib/l10n/pt_PT.php1
-rw-r--r--lib/l10n/ru.php1
-rw-r--r--lib/l10n/sk_SK.php1
-rw-r--r--lib/l10n/sv.php19
-rw-r--r--lib/l10n/tr.php1
-rw-r--r--lib/l10n/zh_CN.php1
-rw-r--r--lib/l10n/zh_TW.php1
-rw-r--r--lib/mail.php2
-rw-r--r--lib/public/backgroundjob.php169
-rw-r--r--lib/public/share.php106
-rw-r--r--lib/response.php4
-rw-r--r--lib/session/internal.php39
-rw-r--r--lib/session/memory.php63
-rw-r--r--lib/session/session.php79
-rw-r--r--lib/setup.php41
-rw-r--r--lib/template.php29
-rw-r--r--lib/user.php546
-rw-r--r--lib/user/backend.php22
-rw-r--r--lib/user/database.php2
-rw-r--r--lib/user/dummy.php144
-rw-r--r--lib/user/manager.php228
-rw-r--r--lib/user/session.php173
-rw-r--r--lib/user/user.php197
-rwxr-xr-xlib/util.php75
-rw-r--r--lib/vcategories.php2
76 files changed, 2373 insertions, 1130 deletions
diff --git a/lib/app.php b/lib/app.php
index c6f6e92e60e..f974dd9f594 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -174,7 +174,8 @@ class OC_App{
$apps=array('files');
$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`'
.' WHERE `configkey` = \'enabled\' AND `configvalue`=\'yes\'';
- if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { //FIXME oracle hack
+ if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') {
+ //FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql = 'SELECT `appid` FROM `*PREFIX*appconfig`'
.' WHERE `configkey` = \'enabled\' AND to_char(`configvalue`)=\'yes\'';
}
@@ -348,7 +349,8 @@ class OC_App{
$settings = array();
// by default, settings only contain the help menu
- if(OC_Config::getValue('knowledgebaseenabled', true)==true) {
+ if(OC_Util::getEditionString() === '' &&
+ OC_Config::getValue('knowledgebaseenabled', true)==true) {
$settings = array(
array(
"id" => "help",
diff --git a/lib/autoloader.php b/lib/autoloader.php
index 9615838a9a2..21170639092 100644
--- a/lib/autoloader.php
+++ b/lib/autoloader.php
@@ -96,8 +96,8 @@ class Autoloader {
} else {
foreach ($this->prefixPaths as $prefix => $dir) {
if (0 === strpos($class, $prefix)) {
- $path = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
- $path = str_replace('_', DIRECTORY_SEPARATOR, $path);
+ $path = str_replace('\\', '/', $class) . '.php';
+ $path = str_replace('_', '/', $path);
$paths[] = $dir . '/' . $path;
}
}
diff --git a/lib/backgroundjob/job.php b/lib/backgroundjob/job.php
new file mode 100644
index 00000000000..49fbffbd684
--- /dev/null
+++ b/lib/backgroundjob/job.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob;
+
+abstract class Job {
+ protected $id;
+ protected $lastRun;
+ protected $argument;
+
+ /**
+ * @param JobList $jobList
+ */
+ public function execute($jobList) {
+ $jobList->setLastRun($this);
+ $this->run($this->argument);
+ }
+
+ abstract protected function run($argument);
+
+ public function setId($id) {
+ $this->id = $id;
+ }
+
+ public function setLastRun($lastRun) {
+ $this->lastRun = $lastRun;
+ }
+
+ public function setArgument($argument) {
+ $this->argument = $argument;
+ }
+
+ public function getId() {
+ return $this->id;
+ }
+
+ public function getLastRun() {
+ return $this->lastRun;
+ }
+
+ public function getArgument() {
+ return $this->argument;
+ }
+}
diff --git a/lib/backgroundjob/joblist.php b/lib/backgroundjob/joblist.php
new file mode 100644
index 00000000000..cc803dd9b5f
--- /dev/null
+++ b/lib/backgroundjob/joblist.php
@@ -0,0 +1,172 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob;
+
+/**
+ * Class QueuedJob
+ *
+ * create a background job that is to be executed once
+ *
+ * @package OC\BackgroundJob
+ */
+class JobList {
+ /**
+ * @param Job|string $job
+ * @param mixed $argument
+ */
+ public function add($job, $argument = null) {
+ if (!$this->has($job, $argument)) {
+ if ($job instanceof Job) {
+ $class = get_class($job);
+ } else {
+ $class = $job;
+ }
+ $argument = json_encode($argument);
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)');
+ $query->execute(array($class, $argument));
+ }
+ }
+
+ /**
+ * @param Job|string $job
+ * @param mixed $argument
+ */
+ public function remove($job, $argument = null) {
+ if ($job instanceof Job) {
+ $class = get_class($job);
+ } else {
+ $class = $job;
+ }
+ if (!is_null($argument)) {
+ $argument = json_encode($argument);
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?');
+ $query->execute(array($class, $argument));
+ } else {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?');
+ $query->execute(array($class));
+ }
+ }
+
+ /**
+ * check if a job is in the list
+ *
+ * @param $job
+ * @param mixed $argument
+ * @return bool
+ */
+ public function has($job, $argument) {
+ if ($job instanceof Job) {
+ $class = get_class($job);
+ } else {
+ $class = $job;
+ }
+ $argument = json_encode($argument);
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?');
+ $result = $query->execute(array($class, $argument));
+ return (bool)$result->fetchRow();
+ }
+
+ /**
+ * get all jobs in the list
+ *
+ * @return Job[]
+ */
+ public function getAll() {
+ $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`');
+ $result = $query->execute();
+ $jobs = array();
+ while ($row = $result->fetchRow()) {
+ $jobs[] = $this->buildJob($row);
+ }
+ return $jobs;
+ }
+
+ /**
+ * get the next job in the list
+ *
+ * @return Job
+ */
+ public function getNext() {
+ $lastId = $this->getLastJob();
+ $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1);
+ $result = $query->execute(array($lastId));
+ if ($row = $result->fetchRow()) {
+ return $this->buildJob($row);
+ } else {
+ //begin at the start of the queue
+ $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1);
+ $result = $query->execute();
+ if ($row = $result->fetchRow()) {
+ return $this->buildJob($row);
+ } else {
+ return null; //empty job list
+ }
+ }
+ }
+
+ /**
+ * @param int $id
+ * @return Job
+ */
+ public function getById($id) {
+ $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?');
+ $result = $query->execute(array($id));
+ if ($row = $result->fetchRow()) {
+ return $this->buildJob($row);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * get the job object from a row in the db
+ *
+ * @param array $row
+ * @return Job
+ */
+ private function buildJob($row) {
+ $class = $row['class'];
+ /**
+ * @var Job $job
+ */
+ $job = new $class();
+ $job->setId($row['id']);
+ $job->setLastRun($row['last_run']);
+ $job->setArgument(json_decode($row['argument']));
+ return $job;
+ }
+
+ /**
+ * set the job that was last ran
+ *
+ * @param Job $job
+ */
+ public function setLastJob($job) {
+ \OC_Appconfig::setValue('backgroundjob', 'lastjob', $job->getId());
+ }
+
+ /**
+ * get the id of the last ran job
+ *
+ * @return int
+ */
+ public function getLastJob() {
+ return \OC_Appconfig::getValue('backgroundjob', 'lastjob', 0);
+ }
+
+ /**
+ * set the lastRun of $job to now
+ *
+ * @param Job $job
+ */
+ public function setLastRun($job) {
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?');
+ $query->execute(array(time(), $job->getId()));
+ }
+}
diff --git a/lib/backgroundjob/legacy/queuedjob.php b/lib/backgroundjob/legacy/queuedjob.php
new file mode 100644
index 00000000000..2bc001103b8
--- /dev/null
+++ b/lib/backgroundjob/legacy/queuedjob.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob\Legacy;
+
+class QueuedJob extends \OC\BackgroundJob\QueuedJob {
+ public function run($argument) {
+ $class = $argument['klass'];
+ $method = $argument['method'];
+ $parameters = $argument['parameters'];
+ call_user_func(array($class, $method), $parameters);
+ }
+}
diff --git a/lib/backgroundjob/legacy/regularjob.php b/lib/backgroundjob/legacy/regularjob.php
new file mode 100644
index 00000000000..d4cfa348cea
--- /dev/null
+++ b/lib/backgroundjob/legacy/regularjob.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob\Legacy;
+
+class RegularJob extends \OC\BackgroundJob\Job {
+ public function run($argument) {
+ call_user_func($argument);
+ }
+}
diff --git a/lib/backgroundjob/queuedjob.php b/lib/backgroundjob/queuedjob.php
new file mode 100644
index 00000000000..1714182820d
--- /dev/null
+++ b/lib/backgroundjob/queuedjob.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob;
+
+/**
+ * Class QueuedJob
+ *
+ * create a background job that is to be executed once
+ *
+ * @package OC\BackgroundJob
+ */
+abstract class QueuedJob extends Job {
+ /**
+ * run the job, then remove it from the joblist
+ *
+ * @param JobList $jobList
+ */
+ public function execute($jobList) {
+ $jobList->remove($this);
+ $this->run($this->argument);
+ }
+}
diff --git a/lib/backgroundjob/queuedtask.php b/lib/backgroundjob/queuedtask.php
deleted file mode 100644
index b2ce6f39ed8..00000000000
--- a/lib/backgroundjob/queuedtask.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Jakob Sack
-* @copyright 2012 Jakob Sack owncloud@jakobsack.de
-*
-* 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/>.
-*
-*/
-
-/**
- * This class manages our queued tasks.
- */
-class OC_BackgroundJob_QueuedTask{
- /**
- * @brief Gets one queued task
- * @param $id ID of the task
- * @return associative array
- */
- public static function find( $id ) {
- $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks` WHERE `id` = ?' );
- $result = $stmt->execute(array($id));
- return $result->fetchRow();
- }
-
- /**
- * @brief Gets all queued tasks
- * @return array with associative arrays
- */
- public static function all() {
- // Array for objects
- $return = array();
-
- // Get Data
- $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks`' );
- $result = $stmt->execute(array());
- while( $row = $result->fetchRow()) {
- $return[] = $row;
- }
-
- return $return;
- }
-
- /**
- * @brief Gets all queued tasks of a specific app
- * @param $app app name
- * @return array with associative arrays
- */
- public static function whereAppIs( $app ) {
- // Array for objects
- $return = array();
-
- // Get Data
- $stmt = OC_DB::prepare( 'SELECT * FROM `*PREFIX*queuedtasks` WHERE `app` = ?' );
- $result = $stmt->execute(array($app));
- while( $row = $result->fetchRow()) {
- $return[] = $row;
- }
-
- // Und weg damit
- return $return;
- }
-
- /**
- * @brief queues a task
- * @param $app app name
- * @param $klass class name
- * @param $method method name
- * @param $parameters all useful data as text
- * @return id of task
- */
- public static function add( $app, $klass, $method, $parameters ) {
- $stmt = OC_DB::prepare( 'INSERT INTO `*PREFIX*queuedtasks` (`app`, `klass`, `method`, `parameters`)'
- .' VALUES(?,?,?,?)' );
- $result = $stmt->execute(array($app, $klass, $method, $parameters ));
-
- return OC_DB::insertid();
- }
-
- /**
- * @brief deletes a queued task
- * @param $id id of task
- * @return true/false
- *
- * Deletes a report
- */
- public static function delete( $id ) {
- $stmt = OC_DB::prepare( 'DELETE FROM `*PREFIX*queuedtasks` WHERE `id` = ?' );
- $result = $stmt->execute(array($id));
-
- return true;
- }
-}
diff --git a/lib/backgroundjob/regulartask.php b/lib/backgroundjob/regulartask.php
deleted file mode 100644
index 9976872ee13..00000000000
--- a/lib/backgroundjob/regulartask.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Jakob Sack
-* @copyright 2012 Jakob Sack owncloud@jakobsack.de
-*
-* 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/>.
-*
-*/
-
-/**
- * This class manages the regular tasks.
- */
-class OC_BackgroundJob_RegularTask{
- static private $registered = array();
-
- /**
- * @brief creates a regular task
- * @param $klass class name
- * @param $method method name
- * @return true
- */
- static public function register( $klass, $method ) {
- // Create the data structure
- self::$registered["$klass-$method"] = array( $klass, $method );
-
- // No chance for failure ;-)
- return true;
- }
-
- /**
- * @brief gets all regular tasks
- * @return associative array
- *
- * key is string "$klass-$method", value is array( $klass, $method )
- */
- static public function all() {
- return self::$registered;
- }
-}
diff --git a/lib/backgroundjob/timedjob.php b/lib/backgroundjob/timedjob.php
new file mode 100644
index 00000000000..ae9f33505ab
--- /dev/null
+++ b/lib/backgroundjob/timedjob.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\BackgroundJob;
+
+/**
+ * Class QueuedJob
+ *
+ * create a background job that is to be executed at an interval
+ *
+ * @package OC\BackgroundJob
+ */
+abstract class TimedJob extends Job {
+ protected $interval = 0;
+
+ /**
+ * set the interval for the job
+ *
+ * @param int $interval
+ */
+ public function setInterval($interval) {
+ $this->interval = $interval;
+ }
+
+ /**
+ * run the job if
+ *
+ * @param JobList $jobList
+ */
+ public function execute($jobList) {
+ if ((time() - $this->lastRun) > $this->interval) {
+ $jobList->setLastRun($this);
+ $this->run($this->argument);
+ }
+ }
+}
diff --git a/lib/backgroundjob/worker.php b/lib/backgroundjob/worker.php
deleted file mode 100644
index e966ac9647c..00000000000
--- a/lib/backgroundjob/worker.php
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Jakob Sack
-* @copyright 2012 Jakob Sack owncloud@jakobsack.de
-*
-* 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/>.
-*
-*/
-
-/**
- * This class does the dirty work.
- *
- * TODO: locking in doAllSteps
- */
-class OC_BackgroundJob_Worker{
- /**
- * @brief executes all tasks
- * @return boolean
- *
- * This method executes all regular tasks and then all queued tasks.
- * This method should be called by cli scripts that do not let the user
- * wait.
- */
- public static function doAllSteps() {
- // Do our regular work
- $lasttask = OC_Appconfig::getValue( 'core', 'backgroundjobs_task', '' );
-
- $regular_tasks = OC_BackgroundJob_RegularTask::all();
- ksort( $regular_tasks );
- foreach( $regular_tasks as $key => $value ) {
- if( strcmp( $key, $lasttask ) > 0 ) {
- // Set "restart here" config value
- OC_Appconfig::setValue( 'core', 'backgroundjobs_task', $key );
- call_user_func( $value );
- }
- }
- // Reset "start here" config value
- OC_Appconfig::setValue( 'core', 'backgroundjobs_task', '' );
-
- // Do our queued tasks
- $queued_tasks = OC_BackgroundJob_QueuedTask::all();
- foreach( $queued_tasks as $task ) {
- OC_BackgroundJob_QueuedTask::delete( $task['id'] );
- call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
- }
-
- return true;
- }
-
- /**
- * @brief does a single task
- * @return boolean
- *
- * This method executes one task. It saves the last state and continues
- * with the next step. This method should be used by webcron and ajax
- * services.
- */
- public static function doNextStep() {
- $laststep = OC_Appconfig::getValue( 'core', 'backgroundjobs_step', 'regular_tasks' );
-
- if( $laststep == 'regular_tasks' ) {
- // get last app
- $lasttask = OC_Appconfig::getValue( 'core', 'backgroundjobs_task', '' );
-
- // What's the next step?
- $regular_tasks = OC_BackgroundJob_RegularTask::all();
- ksort( $regular_tasks );
- $done = false;
-
- // search for next background job
- foreach( $regular_tasks as $key => $value ) {
- if( strcmp( $key, $lasttask ) > 0 ) {
- OC_Appconfig::setValue( 'core', 'backgroundjobs_task', $key );
- $done = true;
- call_user_func( $value );
- break;
- }
- }
-
- if( $done == false ) {
- // Next time load queued tasks
- OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'queued_tasks' );
- }
- }
- else{
- $tasks = OC_BackgroundJob_QueuedTask::all();
- if( count( $tasks )) {
- $task = $tasks[0];
- // delete job before we execute it. This prevents endless loops
- // of failing jobs.
- OC_BackgroundJob_QueuedTask::delete($task['id']);
-
- // execute job
- call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
- }
- else{
- // Next time load queued tasks
- OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'regular_tasks' );
- OC_Appconfig::setValue( 'core', 'backgroundjobs_task', '' );
- }
- }
-
- return true;
- }
-}
diff --git a/lib/base.php b/lib/base.php
index 724bd250a5c..26e9595e869 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -75,6 +75,11 @@ class OC {
protected static $router = null;
/**
+ * @var \OC\Session\Session
+ */
+ public static $session = null;
+
+ /**
* @var \OC\Autoloader $loader
*/
public static $loader = null;
@@ -230,10 +235,7 @@ class OC {
$currentVersion = implode('.', OC_Util::getVersion());
if (version_compare($currentVersion, $installedVersion, '>')) {
if ($showTemplate && !OC_Config::getValue('maintenance', false)) {
- OC_Config::setValue('maintenance', true);
- OC_Log::write('core',
- 'starting upgrade from ' . $installedVersion . ' to ' . $currentVersion,
- OC_Log::WARN);
+ OC_Config::setValue('theme', '');
$minimizerCSS = new OC_Minimizer_CSS();
$minimizerCSS->clearCache();
$minimizerJS = new OC_Minimizer_JS();
@@ -253,12 +255,14 @@ class OC {
public static function initTemplateEngine() {
// Add the stuff we need always
- OC_Util::addScript("jquery-1.7.2.min");
+ OC_Util::addScript("jquery-1.10.0.min");
+ OC_Util::addScript("jquery-migrate-1.2.1.min");
OC_Util::addScript("jquery-ui-1.10.0.custom");
OC_Util::addScript("jquery-showpassword");
OC_Util::addScript("jquery.infieldlabel");
OC_Util::addScript("jquery-tipsy");
OC_Util::addScript("compatibility");
+ OC_Util::addScript("jquery.ocdialog");
OC_Util::addScript("oc-dialogs");
OC_Util::addScript("octemplate");
OC_Util::addScript("js");
@@ -272,6 +276,7 @@ class OC {
OC_Util::addStyle("multiselect");
OC_Util::addStyle("jquery-ui-1.10.0.custom");
OC_Util::addStyle("jquery-tipsy");
+ OC_Util::addStyle("jquery.ocdialog");
OC_Util::addScript("oc-requesttoken");
}
@@ -283,14 +288,17 @@ class OC {
$cookie_path = OC::$WEBROOT ?: '/';
ini_set('session.cookie_path', $cookie_path);
- // set the session name to the instance id - which is unique
- session_name(OC_Util::getInstanceId());
+ try{
+ // set the session name to the instance id - which is unique
+ self::$session = new \OC\Session\Internal(OC_Util::getInstanceId());
+ // if session cant be started break with http 500 error
+ }catch (Exception $e){
+ //set the session object to a dummy session so code relying on the session existing still works
+ self::$session = new \OC\Session\Memory('');
- // if session cant be started break with http 500 error
- if (session_start() === false){
- OC_Log::write('core', 'Session could not be initialized',
+ OC_Log::write('core', 'Session could not be initialized',
OC_Log::ERROR);
-
+
header('HTTP/1.1 500 Internal Server Error');
OC_Util::addStyle("styles");
$error = 'Session could not be initialized. Please contact your ';
@@ -304,15 +312,15 @@ class OC {
}
// regenerate session id periodically to avoid session fixation
- if (!isset($_SESSION['SID_CREATED'])) {
- $_SESSION['SID_CREATED'] = time();
- } else if (time() - $_SESSION['SID_CREATED'] > 60*60*12) {
+ if (!self::$session->exists('SID_CREATED')) {
+ self::$session->set('SID_CREATED', time());
+ } else if (time() - self::$session->get('SID_CREATED') > 60*60*12) {
session_regenerate_id(true);
- $_SESSION['SID_CREATED'] = time();
+ self::$session->set('SID_CREATED', time());
}
// session timeout
- if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 60*60*24)) {
+ if (self::$session->exists('LAST_ACTIVITY') && (time() - self::$session->get('LAST_ACTIVITY') > 60*60*24)) {
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time() - 42000, $cookie_path);
}
@@ -320,7 +328,8 @@ class OC {
session_destroy();
session_start();
}
- $_SESSION['LAST_ACTIVITY'] = time();
+
+ self::$session->set('LAST_ACTIVITY', time());
}
public static function getRouter() {
@@ -431,12 +440,14 @@ class OC {
stream_wrapper_register('oc', 'OC\Files\Stream\OC');
self::initTemplateEngine();
- self::checkConfig();
- self::checkInstalled();
- self::checkSSL();
if ( !self::$CLI ) {
self::initSession();
+ } else {
+ self::$session = new \OC\Session\Memory('');
}
+ self::checkConfig();
+ self::checkInstalled();
+ self::checkSSL();
$errors = OC_Util::checkServer();
if (count($errors) > 0) {
@@ -446,14 +457,14 @@ class OC {
// User and Groups
if (!OC_Config::getValue("installed", false)) {
- $_SESSION['user_id'] = '';
+ self::$session->set('user_id','');
}
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
- if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SESSION['user_id'])
- && $_SERVER['PHP_AUTH_USER'] != $_SESSION['user_id']) {
+ if (isset($_SERVER['PHP_AUTH_USER']) && self::$session->exists('user_id')
+ && $_SERVER['PHP_AUTH_USER'] != self::$session->get('user_id')) {
OC_User::logout();
}
@@ -525,9 +536,15 @@ class OC {
* register hooks for the cache
*/
public static function registerCacheHooks() {
- // register cache cleanup jobs
- OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
- OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
+ if (OC_Config::getValue('installed', false)) { //don't try to do this before we are properly setup
+ // register cache cleanup jobs
+ try { //if this is executed before the upgrade to the new backgroundjob system is completed it will throw an exception
+ \OCP\BackgroundJob::registerJob('OC_Cache_FileGlobalGC');
+ } catch (Exception $e) {
+
+ }
+ OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
+ }
}
/**
@@ -598,7 +615,7 @@ class OC {
// Handle redirect URL for logged in users
if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
-
+
// Deny the redirect if the URL contains a @
// This prevents unvalidated redirects like ?redirect_url=:user@domain.com
if (strpos($location, '@') === false) {
@@ -748,7 +765,7 @@ class OC {
if (OC_User::login($_POST["user"], $_POST["password"])) {
// setting up the time zone
if (isset($_POST['timezone-offset'])) {
- $_SESSION['timezone'] = $_POST['timezone-offset'];
+ self::$session->set('timezone', $_POST['timezone-offset']);
}
self::cleanupLoginTokens($_POST['user']);
diff --git a/lib/cache/file.php b/lib/cache/file.php
index f9ecf41dcac..531e1d50f40 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -14,6 +14,7 @@ class OC_Cache_File{
return $this->storage;
}
if(OC_User::isLoggedIn()) {
+ \OC\Files\Filesystem::initMountPoints(OC_User::getUser());
$subdir = 'cache';
$view = new \OC\Files\View('/'.OC_User::getUser());
if(!$view->file_exists($subdir)) {
diff --git a/lib/cache/fileglobalgc.php b/lib/cache/fileglobalgc.php
new file mode 100644
index 00000000000..a29c31f9063
--- /dev/null
+++ b/lib/cache/fileglobalgc.php
@@ -0,0 +1,8 @@
+<?php
+
+
+class OC_Cache_FileGlobalGC extends \OC\BackgroundJob\Job{
+ public function run($argument){
+ OC_Cache_FileGlobal::gc();
+ }
+}
diff --git a/lib/config.php b/lib/config.php
index 9b87d4ce4e5..3cbb89fb981 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -187,7 +187,7 @@ class OC_Config{
}
// Prevent others not to read the config
@chmod($filename, 0640);
-
+ OC_Util::clearOpcodeCache();
return true;
}
}
diff --git a/lib/connector/sabre/locks.php b/lib/connector/sabre/locks.php
index e58e584fb41..cbc495dec19 100644
--- a/lib/connector/sabre/locks.php
+++ b/lib/connector/sabre/locks.php
@@ -45,7 +45,12 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
// but otherwise reading locks from SQLite Databases will return
// nothing
$query = 'SELECT * FROM `*PREFIX*locks`'
- .' WHERE `userid` = ? AND (`created` + `timeout`) > '.time().' AND (( `uri` = ?)';
+ .' WHERE `userid` = ? AND (`created` + `timeout`) > '.time().' AND (( `uri` = ?)';
+ if (OC_Config::getValue( "dbtype") === 'oci') {
+ //FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
+ $query = 'SELECT * FROM `*PREFIX*locks`'
+ .' WHERE `userid` = ? AND (`created` + `timeout`) > '.time().' AND (( to_char(`uri`) = ?)';
+ }
$params = array(OC_User::getUser(), $uri);
// We need to check locks for every part in the uri.
@@ -60,23 +65,31 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
if ($currentPath) $currentPath.='/';
$currentPath.=$part;
-
- $query.=' OR (`depth` != 0 AND `uri` = ?)';
+ //FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
+ if (OC_Config::getValue( "dbtype") === 'oci') {
+ $query.=' OR (`depth` != 0 AND to_char(`uri`) = ?)';
+ } else {
+ $query.=' OR (`depth` != 0 AND `uri` = ?)';
+ }
$params[] = $currentPath;
}
if ($returnChildLocks) {
- $query.=' OR (`uri` LIKE ?)';
+ //FIXME oracle hack: need to explicitly cast CLOB to CHAR for comparison
+ if (OC_Config::getValue( "dbtype") === 'oci') {
+ $query.=' OR (to_char(`uri`) LIKE ?)';
+ } else {
+ $query.=' OR (`uri` LIKE ?)';
+ }
$params[] = $uri . '/%';
}
$query.=')';
- $stmt = OC_DB::prepare( $query );
- $result = $stmt->execute( $params );
-
+ $result = OC_DB::executeAudited( $query, $params );
+
$lockList = array();
while( $row = $result->fetchRow()) {
@@ -113,14 +126,17 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
$locks = $this->getLocks($uri, false);
$exists = false;
foreach($locks as $lock) {
- if ($lock->token == $lockInfo->token) $exists = true;
+ if ($lock->token == $lockInfo->token) {
+ $exists = true;
+ break;
+ }
}
if ($exists) {
- $query = OC_DB::prepare( 'UPDATE `*PREFIX*locks`'
- .' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?'
- .' WHERE `userid` = ? AND `token` = ?' );
- $result = $query->execute( array(
+ $sql = 'UPDATE `*PREFIX*locks`'
+ .' SET `owner` = ?, `timeout` = ?, `scope` = ?, `depth` = ?, `uri` = ?, `created` = ?'
+ .' WHERE `userid` = ? AND `token` = ?';
+ $result = OC_DB::executeAudited( $sql, array(
$lockInfo->owner,
$lockInfo->timeout,
$lockInfo->scope,
@@ -131,10 +147,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
$lockInfo->token)
);
} else {
- $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*locks`'
- .' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)'
- .' VALUES (?,?,?,?,?,?,?,?)' );
- $result = $query->execute( array(
+ $sql = 'INSERT INTO `*PREFIX*locks`'
+ .' (`userid`,`owner`,`timeout`,`scope`,`depth`,`uri`,`created`,`token`)'
+ .' VALUES (?,?,?,?,?,?,?,?)';
+ $result = OC_DB::executeAudited( $sql, array(
OC_User::getUser(),
$lockInfo->owner,
$lockInfo->timeout,
@@ -159,8 +175,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
*/
public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) {
- $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?' );
- $result = $query->execute( array(OC_User::getUser(), $uri, $lockInfo->token));
+ $sql = 'DELETE FROM `*PREFIX*locks` WHERE `userid` = ? AND `uri` = ? AND `token` = ?';
+ $result = OC_DB::executeAudited( $sql, array(OC_User::getUser(), $uri, $lockInfo->token));
return $result->numRows() === 1;
diff --git a/lib/connector/sabre/maintenanceplugin.php b/lib/connector/sabre/maintenanceplugin.php
index 329fa4443ad..2eda269afc2 100644
--- a/lib/connector/sabre/maintenanceplugin.php
+++ b/lib/connector/sabre/maintenanceplugin.php
@@ -50,6 +50,9 @@ class OC_Connector_Sabre_MaintenancePlugin extends Sabre_DAV_ServerPlugin
if (OC_Config::getValue('maintenance', false)) {
throw new Sabre_DAV_Exception_ServiceUnavailable();
}
+ if (OC::checkUpgrade(false)) {
+ throw new Sabre_DAV_Exception_ServiceUnavailable('Upgrade needed');
+ }
return true;
}
diff --git a/lib/db.php b/lib/db.php
index 7db7711b376..8bd3964492a 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -25,7 +25,8 @@ define('MDB2_SCHEMA_DUMP_STRUCTURE', '1');
class DatabaseException extends Exception {
private $query;
- public function __construct($message, $query) {
+ //FIXME getQuery seems to be unused, maybe use parent constructor with $message, $code and $previous
+ public function __construct($message, $query = null){
parent::__construct($message);
$this->query = $query;
}
@@ -252,9 +253,59 @@ class OC_DB {
}
/**
+ * @brief execute a prepared statement, on error write log and throw exception
+ * @param mixed $stmt DoctrineStatementWrapperm,
+ * an array with 'sql' and optionally 'limit' and 'offset' keys
+ * .. or a simple sql query string
+ * @param array $parameters
+ * @return result
+ * @throws DatabaseException
+ */
+ static public function executeAudited( $stmt, array $parameters = null) {
+ if (is_string($stmt)) {
+ // convert to an array with 'sql'
+ if (stripos($stmt,'LIMIT') !== false) { //OFFSET requires LIMIT, se we only neet to check for LIMIT
+ // TODO try to convert LIMIT OFFSET notation to parameters, see fixLimitClauseForMSSQL
+ $message = 'LIMIT and OFFSET are forbidden for portability reasons,'
+ . ' pass an array with \'limit\' and \'offset\' instead';
+ throw new DatabaseException($message);
+ }
+ $stmt = array('sql' => $stmt, 'limit' => null, 'offset' => null);
+ }
+ if (is_array($stmt)){
+ // convert to prepared statement
+ if ( ! array_key_exists('sql', $stmt) ) {
+ $message = 'statement array must at least contain key \'sql\'';
+ throw new DatabaseException($message);
+ }
+ if ( ! array_key_exists('limit', $stmt) ) {
+ $stmt['limit'] = null;
+ }
+ if ( ! array_key_exists('limit', $stmt) ) {
+ $stmt['offset'] = null;
+ }
+ $stmt = self::prepare($stmt['sql'], $stmt['limit'], $stmt['offset']);
+ }
+ self::raiseExceptionOnError($stmt, 'Could not prepare statement');
+ if ($stmt instanceof DoctrineStatementWrapper) {
+ $result = $stmt->execute($parameters);
+ self::raiseExceptionOnError($result, 'Could not execute statement');
+ } else {
+ if (is_object($stmt)) {
+ $message = 'Expected a prepared statement or array got ' . get_class($stmt);
+ } else {
+ $message = 'Expected a prepared statement or array got ' . gettype($stmt);
+ }
+ throw new DatabaseException($message);
+ }
+ return $result;
+ }
+
+ /**
* @brief gets last value of autoincrement
* @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix
* @return int id
+ * @throws DatabaseException
*
* \Doctrine\DBAL\Connection lastInsertId
*
@@ -264,25 +315,27 @@ class OC_DB {
public static function insertid($table=null) {
self::connect();
$type = OC_Config::getValue( "dbtype", "sqlite" );
- if( $type == 'pgsql' ) {
- $query = self::prepare('SELECT lastval() AS id');
- $row = $query->execute()->fetchRow();
+ if( $type === 'pgsql' ) {
+ $result = self::executeAudited('SELECT lastval() AS id');
+ $row = $result->fetchRow();
+ self::raiseExceptionOnError($row, 'fetching row for insertid failed');
return $row['id'];
- }
- if( $type == 'mssql' ) {
+ } else if( $type === 'mssql' || $type === 'oci') {
if($table !== null) {
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
$table = str_replace( '*PREFIX*', $prefix, $table );
}
- return self::$connection->lastInsertId($table);
+ self::$connection->lastInsertId($table);
} else {
if($table !== null) {
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
$suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" );
$table = str_replace( '*PREFIX*', $prefix, $table ).$suffix;
}
- return self::$connection->lastInsertId($table);
+ $result = self::$connection->lastInsertId($table);
}
+ self::raiseExceptionOnError($result, 'insertid failed');
+ return $result;
}
/**
@@ -395,15 +448,9 @@ class OC_DB {
}
$query = substr($query, 0, strlen($query) - 5);
try {
- $stmt = self::prepare($query);
- $result = $stmt->execute($inserts);
- } catch(\Doctrine\DBAL\DBALException $e) {
- $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
- $entry .= 'Offending command was: ' . $query . '<br />';
- OC_Log::write('core', $entry, OC_Log::FATAL);
- error_log('DB error: '.$entry);
- OC_Template::printErrorPage( $entry );
- return false;
+ $result = self::executeAudited($query, $inserts);
+ } catch(DatabaseException $e) {
+ OC_Template::printExceptionErrorPage( $e );
}
if((int)$result->numRows() === 0) {
@@ -428,17 +475,12 @@ class OC_DB {
}
try {
- $result = self::prepare($query);
+ $result = self::executeAudited($query, $inserts);
} catch(\Doctrine\DBAL\DBALException $e) {
- $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
- $entry .= 'Offending command was: ' . $query.'<br />';
- OC_Log::write('core', $entry, OC_Log::FATAL);
- error_log('DB error: ' . $entry);
- OC_Template::printErrorPage( $entry );
- return false;
+ OC_Template::printExceptionErrorPage( $e );
}
- return $result->execute($inserts);
+ return $result;
}
/**
@@ -607,7 +649,28 @@ class OC_DB {
return false;
}
}
+ /**
+ * check if a result is an error and throws an exception, works with \Doctrine\DBAL\DBALException
+ * @param mixed $result
+ * @param string message
+ * @return void
+ * @throws DatabaseException
+ */
+ public static function raiseExceptionOnError($result, $message = null) {
+ if(self::isError($result)) {
+ if ($message === null) {
+ $message = self::getErrorMessage($result);
+ } else {
+ $message .= ', Root cause:' . self::getErrorMessage($result);
+ }
+ throw new DatabaseException($message, self::getErrorCode($result));
+ }
+ }
+ public static function getErrorCode($error) {
+ $code = self::$connection->errorCode();
+ return $code;
+ }
/**
* returns the error code and message as a string for logging
* works with DoctrineException
diff --git a/lib/defaults.php b/lib/defaults.php
new file mode 100644
index 00000000000..7dc6fbd0ada
--- /dev/null
+++ b/lib/defaults.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Default strings and values which differ between the enterprise and the
+ * community edition. Use the get methods to always get the right strings.
+ */
+
+class OC_Defaults {
+
+ private static $communityEntity = "ownCloud";
+ private static $communityName = "ownCloud";
+ private static $communityBaseUrl = "http://owncloud.org";
+ private static $communitySyncClientUrl = " http://owncloud.org/sync-clients/";
+ private static $communityDocBaseUrl = "http://doc.owncloud.org";
+ private static $communitySlogan = "web services under your control";
+
+ private static $enterpriseEntity = "ownCloud Inc.";
+ private static $enterpriseName = "ownCloud Enterprise Edition";
+ private static $enterpriseBaseUrl = "https://owncloud.com";
+ private static $enterpriseDocBaseUrl = "http://doc.owncloud.com";
+ private static $enterpiseSyncClientUrl = "https://owncloud.com/products/desktop-clients";
+ private static $enterpriseSlogan = "Your Cloud, Your Data, Your Way!";
+
+
+ public static function getBaseUrl() {
+ if (OC_Util::getEditionString() === '') {
+ return self::$communityBaseUrl;
+ } else {
+ return self::$enterpriseBaseUrl;
+ }
+ }
+
+ public static function getSyncClientUrl() {
+ if (OC_Util::getEditionString() === '') {
+ return self::$communitySyncClientUrl;
+ } else {
+ return self::$enterpiseSyncClientUrl;
+ }
+ }
+
+ public static function getDocBaseUrl() {
+ if (OC_Util::getEditionString() === '') {
+ return self::$communityDocBaseUrl;
+ } else {
+ return self::$enterpriseDocBaseUrl;
+ }
+ }
+
+ public static function getName() {
+ if (OC_Util::getEditionString() === '') {
+ return self::$communityName;
+ } else {
+ return self::$enterpriseName;
+ }
+ }
+
+ public static function getEntity() {
+ if (OC_Util::getEditionString() === '') {
+ return self::$communityEntity;
+ } else {
+ return self::$enterpriseEntity;
+ }
+ }
+
+ public static function getSlogan() {
+ $l = OC_L10N::get('core');
+ if (OC_Util::getEditionString() === '') {
+ return $l->t(self::$communitySlogan);
+ } else {
+ return self::$enterpriseSlogan;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/lib/files.php b/lib/files.php
index ab7fa1ed096..abb1617c25e 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -123,8 +123,11 @@ class OC_Files {
header('Content-Length: ' . filesize($filename));
self::addSendfileHeader($filename);
}else{
+ $filesize = \OC\Files\Filesystem::filesize($filename);
header('Content-Type: '.\OC\Files\Filesystem::getMimeType($filename));
- header("Content-Length: ".\OC\Files\Filesystem::filesize($filename));
+ if ($filesize > -1) {
+ header("Content-Length: ".$filesize);
+ }
list($storage) = \OC\Files\Filesystem::resolvePath($filename);
if ($storage instanceof \OC\Files\Storage\Local) {
self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php
index 8933101577d..923804f48d0 100644
--- a/lib/files/cache/backgroundwatcher.php
+++ b/lib/files/cache/backgroundwatcher.php
@@ -18,8 +18,8 @@ class BackgroundWatcher {
if (!is_null(self::$folderMimetype)) {
return self::$folderMimetype;
}
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
- $result = $query->execute(array('httpd/unix-directory'));
+ $sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
+ $result = \OC_DB::executeAudited($sql, array('httpd/unix-directory'));
$row = $result->fetchRow();
return $row['id'];
}
@@ -59,11 +59,11 @@ class BackgroundWatcher {
*/
static private function getNextFileId($previous, $folder) {
if ($folder) {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype = ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1);
+ $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` = ? ORDER BY `fileid` ASC', 1);
} else {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype != ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1);
+ $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` != ? ORDER BY `fileid` ASC', 1);
}
- $result = $query->execute(array($previous));
+ $result = \OC_DB::executeAudited($stmt, array($previous,self::getFolderMimetype()));
if ($row = $result->fetchRow()) {
return $row['fileid'];
} else {
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index b912b4423e7..3818fdbd840 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -65,13 +65,11 @@ class Cache {
*/
public function getMimetypeId($mime) {
if (!isset($this->mimetypeIds[$mime])) {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
- $result = $query->execute(array($mime));
+ $result = \OC_DB::executeAudited('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?', array($mime));
if ($row = $result->fetchRow()) {
$this->mimetypeIds[$mime] = $row['id'];
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)');
- $query->execute(array($mime));
+ $result = \OC_DB::executeAudited('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)', array($mime));
$this->mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes');
}
$this->mimetypes[$this->mimetypeIds[$mime]] = $mime;
@@ -81,8 +79,8 @@ class Cache {
public function getMimetype($id) {
if (!isset($this->mimetypes[$id])) {
- $query = \OC_DB::prepare('SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?');
- $result = $query->execute(array($id));
+ $sql = 'SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id));
if ($row = $result->fetchRow()) {
$this->mimetypes[$id] = $row['mimetype'];
} else {
@@ -96,22 +94,31 @@ class Cache {
* get the stored metadata of a file or folder
*
* @param string/int $file
- * @return array
+ * @return array | false
*/
public function get($file) {
if (is_string($file) or $file == '') {
+ // normalize file
+ $file = $this->normalize($file);
+
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
$params = array($this->getNumericStorageId(), md5($file));
} else { //file id
$where = 'WHERE `fileid` = ?';
$params = array($file);
}
- $query = \OC_DB::prepare(
- 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
- FROM `*PREFIX*filecache` ' . $where);
- $result = $query->execute($params);
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
+ `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` ' . $where;
+ $result = \OC_DB::executeAudited($sql, $params);
$data = $result->fetchRow();
+ //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
+ //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
+ if ($data === null) {
+ $data = false;
+ }
+
//merge partial data
if (!$data and is_string($file)) {
if (isset($this->partial[$file])) {
@@ -144,14 +151,10 @@ class Cache {
public function getFolderContents($folder) {
$fileId = $this->getId($folder);
if ($fileId > -1) {
- $query = \OC_DB::prepare(
- 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
- FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC');
-
- $result = $query->execute(array($fileId));
- if (\OC_DB::isError($result)) {
- \OCP\Util::writeLog('cache', 'getFolderContents failed: ' . $result->getMessage(), \OCP\Util::ERROR);
- }
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
+ `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
+ $result = \OC_DB::executeAudited($sql,array($fileId));
$files = $result->fetchAll();
foreach ($files as &$file) {
$file['mimetype'] = $this->getMimetype($file['mimetype']);
@@ -179,6 +182,9 @@ class Cache {
$this->update($id, $data);
return $id;
} else {
+ // normalize file
+ $file = $this->normalize($file);
+
if (isset($this->partial[$file])) { //add any saved partial data
$data = array_merge($this->partial[$file], $data);
unset($this->partial[$file]);
@@ -202,12 +208,9 @@ class Cache {
$params[] = $this->getNumericStorageId();
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')'
- . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
- $result = $query->execute($params);
- if (\OC_DB::isError($result)) {
- \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result->getMessage(), \OCP\Util::ERROR);
- }
+ $sql = 'INSERT INTO `*PREFIX*filecache` (' . implode(', ', $queryParts) . ')'
+ . ' VALUES (' . implode(', ', $valuesPlaceholder) . ')';
+ \OC_DB::executeAudited($sql, $params);
return (int)\OC_DB::insertid('*PREFIX*filecache');
}
@@ -220,12 +223,22 @@ class Cache {
* @param array $data
*/
public function update($id, array $data) {
+
+ if(isset($data['path'])) {
+ // normalize path
+ $data['path'] = $this->normalize($data['path']);
+ }
+
+ if(isset($data['name'])) {
+ // normalize path
+ $data['name'] = $this->normalize($data['name']);
+ }
+
list($queryParts, $params) = $this->buildParts($data);
$params[] = $id;
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?'
- . ' WHERE fileid = ?');
- $query->execute($params);
+ $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, $params);
}
/**
@@ -267,11 +280,13 @@ class Cache {
* @return int
*/
public function getId($file) {
- $pathHash = md5($file);
+ // normalize file
+ $file = $this->normalize($file);
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
- $result = $query->execute(array($this->getNumericStorageId(), $pathHash));
+ $pathHash = md5($file);
+ $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $pathHash));
if ($row = $result->fetchRow()) {
return $row['fileid'];
} else {
@@ -320,8 +335,9 @@ class Cache {
$this->remove($child['path']);
}
}
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?');
- $query->execute(array($entry['fileid']));
+
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($entry['fileid']));
$permissionsCache = new Permissions($this->storageId);
$permissionsCache->remove($entry['fileid']);
@@ -334,38 +350,41 @@ class Cache {
* @param string $target
*/
public function move($source, $target) {
+ // normalize source and target
+ $source = $this->normalize($source);
+ $target = $this->normalize($target);
+
$sourceData = $this->get($source);
$sourceId = $sourceData['fileid'];
$newParentId = $this->getParentId($target);
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
//find all child entries
- $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?');
- $result = $query->execute(array($source . '/%'));
+ $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $source . '/%'));
$childEntries = $result->fetchAll();
$sourceLength = strlen($source);
$query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
foreach ($childEntries as $child) {
$targetPath = $target . substr($child['path'], $sourceLength);
- $query->execute(array($targetPath, md5($targetPath), $child['fileid']));
+ \OC_DB::executeAudited($query, array($targetPath, md5($targetPath), $child['fileid']));
}
}
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?'
- . ' WHERE `fileid` = ?');
- $query->execute(array($target, md5($target), basename($target), $newParentId, $sourceId));
+ $sql = 'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($target, md5($target), basename($target), $newParentId, $sourceId));
}
/**
* remove all entries for files that are stored on the storage from the cache
*/
public function clear() {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?');
- $query->execute(array($this->getNumericStorageId()));
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
+ \OC_DB::executeAudited($sql, array($this->getNumericStorageId()));
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?');
- $query->execute(array($this->storageId));
+ $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
+ \OC_DB::executeAudited($sql, array($this->storageId));
}
/**
@@ -374,12 +393,12 @@ class Cache {
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
*/
public function getStatus($file) {
+ // normalize file
+ $file = $this->normalize($file);
+
$pathHash = md5($file);
- $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
- $result = $query->execute(array($this->getNumericStorageId(), $pathHash));
- if( \OC_DB::isError($result)) {
- \OCP\Util::writeLog('cache', 'get status failed: ' . $result->getMessage(), \OCP\Util::ERROR);
- }
+ $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $pathHash));
if ($row = $result->fetchRow()) {
if ((int)$row['size'] === -1) {
return self::SHALLOW;
@@ -402,11 +421,13 @@ class Cache {
* @return array of file data
*/
public function search($pattern) {
- $query = \OC_DB::prepare('
- SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
- FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
- );
- $result = $query->execute(array($pattern, $this->getNumericStorageId()));
+
+ // normalize pattern
+ $pattern = $this->normalize($pattern);
+
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($pattern, $this->getNumericStorageId()));
$files = array();
while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']);
@@ -428,12 +449,10 @@ class Cache {
} else {
$where = '`mimepart` = ?';
}
- $query = \OC_DB::prepare('
- SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
- FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'
- );
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
$mimetype = $this->getMimetypeId($mimetype);
- $result = $query->execute(array($mimetype, $this->getNumericStorageId()));
+ $result = \OC_DB::executeAudited($sql, array($mimetype, $this->getNumericStorageId()));
$files = array();
while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']);
@@ -470,8 +489,8 @@ class Cache {
if ($id === -1) {
return 0;
}
- $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?');
- $result = $query->execute(array($id, $this->getNumericStorageId()));
+ $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
$totalSize = 0;
$hasChilds = 0;
while ($row = $result->fetchRow()) {
@@ -497,8 +516,8 @@ class Cache {
* @return int[]
*/
public function getAll() {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?');
- $result = $query->execute(array($this->getNumericStorageId()));
+ $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId()));
$ids = array();
while ($row = $result->fetchRow()) {
$ids[] = $row['fileid'];
@@ -518,10 +537,7 @@ class Cache {
public function getIncomplete() {
$query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`'
. ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC',1);
- $result = $query->execute(array($this->getNumericStorageId()));
- if (\OC_DB::isError($result)) {
- \OCP\Util::writeLog('cache', 'getIncomplete failed: ' . $result->getMessage(), \OCP\Util::ERROR);
- }
+ $result = \OC_DB::executeAudited($query, array($this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
return $row['path'];
} else {
@@ -536,8 +552,8 @@ class Cache {
* @return array, first element holding the storage id, second the path
*/
static public function getById($id) {
- $query = \OC_DB::prepare('SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
- $result = $query->execute(array($id));
+ $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id));
if ($row = $result->fetchRow()) {
$numericId = $row['storage'];
$path = $row['path'];
@@ -551,4 +567,14 @@ class Cache {
return null;
}
}
+
+ /**
+ * normalize the given path
+ * @param $path
+ * @return string
+ */
+ public function normalize($path) {
+
+ return \OC_Util::normalizeUnicode($path);
+ }
}
diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php
index b8e2548639b..8eed1f67a5d 100644
--- a/lib/files/cache/legacy.php
+++ b/lib/files/cache/legacy.php
@@ -26,8 +26,8 @@ class Legacy {
* @return int
*/
function getCount() {
- $query = \OC_DB::prepare('SELECT COUNT(`id`) AS `count` FROM `*PREFIX*fscache` WHERE `user` = ?');
- $result = $query->execute(array($this->user));
+ $sql = 'SELECT COUNT(`id`) AS `count` FROM `*PREFIX*fscache` WHERE `user` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->user));
if ($row = $result->fetchRow()) {
return $row['count'];
} else {
@@ -45,7 +45,7 @@ class Legacy {
return $this->cacheHasItems;
}
try {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ? LIMIT 1');
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ?',1);
} catch (\Exception $e) {
$this->cacheHasItems = false;
return false;
@@ -74,11 +74,11 @@ class Legacy {
*/
function get($path) {
if (is_numeric($path)) {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?');
+ $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?';
} else {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?');
+ $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?';
}
- $result = $query->execute(array($path));
+ $result = \OC_DB::executeAudited($sql, array($path));
$data = $result->fetchRow();
$data['etag'] = $this->getEtag($data['path'], $data['user']);
return $data;
@@ -111,7 +111,7 @@ class Legacy {
if(is_null($query)){
$query = \OC_DB::prepare('SELECT `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = \'{DAV:}getetag\'');
}
- $result = $query->execute(array($user, '/' . $relativePath));
+ $result = \OC_DB::executeAudited($query,array($user, '/' . $relativePath));
if ($row = $result->fetchRow()) {
return trim($row['propertyvalue'], '"');
} else {
@@ -126,8 +126,7 @@ class Legacy {
* @return array
*/
function getChildren($id) {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?');
- $result = $query->execute(array($id));
+ $result = \OC_DB::executeAudited('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?', array($id));
$data = $result->fetchAll();
foreach ($data as $i => $item) {
$data[$i]['etag'] = $this->getEtag($item['path'], $item['user']);
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index faa5ff5eacc..2e2bdb20b78 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -33,8 +33,8 @@ class Permissions {
* @return int (-1 if file no permissions set)
*/
public function get($fileId, $user) {
- $query = \OC_DB::prepare('SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?');
- $result = $query->execute(array($user, $fileId));
+ $sql = 'SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($user, $fileId));
if ($row = $result->fetchRow()) {
return $row['permissions'];
} else {
@@ -51,13 +51,11 @@ class Permissions {
*/
public function set($fileId, $user, $permissions) {
if (self::get($fileId, $user) !== -1) {
- $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ?'
- . ' WHERE `user` = ? AND `fileid` = ?');
+ $sql = 'UPDATE `*PREFIX*permissions` SET `permissions` = ? WHERE `user` = ? AND `fileid` = ?';
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`)'
- . ' VALUES(?, ?,? )');
+ $sql = 'INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`) VALUES(?, ?,? )';
}
- $query->execute(array($permissions, $user, $fileId));
+ \OC_DB::executeAudited($sql, array($permissions, $user, $fileId));
}
/**
@@ -75,9 +73,30 @@ class Permissions {
$params[] = $user;
$inPart = implode(', ', array_fill(0, count($fileIds), '?'));
- $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
- . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
- $result = $query->execute($params);
+ $sql = 'SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
+ . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?';
+ $result = \OC_DB::executeAudited($sql, $params);
+ $filePermissions = array();
+ while ($row = $result->fetchRow()) {
+ $filePermissions[$row['fileid']] = $row['permissions'];
+ }
+ return $filePermissions;
+ }
+
+ /**
+ * get the permissions for all files in a folder
+ *
+ * @param int $parentId
+ * @param string $user
+ * @return int[]
+ */
+ public function getDirectoryPermissions($parentId, $user) {
+ $sql = 'SELECT `*PREFIX*permissions`.`fileid`, `permissions`
+ FROM `*PREFIX*permissions`
+ INNER JOIN `*PREFIX*filecache` ON `*PREFIX*permissions`.`fileid` = `*PREFIX*filecache`.`fileid`
+ WHERE `*PREFIX*filecache`.`parent` = ? AND `*PREFIX*permissions`.`user` = ?';
+
+ $result = \OC_DB::executeAudited($sql, array($parentId, $user));
$filePermissions = array();
while ($row = $result->fetchRow()) {
$filePermissions[$row['fileid']] = $row['permissions'];
@@ -93,18 +112,17 @@ class Permissions {
*/
public function remove($fileId, $user = null) {
if (is_null($user)) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?');
- $query->execute(array($fileId));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?', array($fileId));
} else {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
- $query->execute(array($fileId, $user));
+ $sql = 'DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?';
+ \OC_DB::executeAudited($sql, array($fileId, $user));
}
}
public function removeMultiple($fileIds, $user) {
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
foreach ($fileIds as $fileId) {
- $query->execute(array($fileId, $user));
+ \OC_DB::executeAudited($query, array($fileId, $user));
}
}
@@ -114,8 +132,8 @@ class Permissions {
* @param int $fileId
*/
public function getUsers($fileId) {
- $query = \OC_DB::prepare('SELECT `user` FROM `*PREFIX*permissions` WHERE `fileid` = ?');
- $result = $query->execute(array($fileId));
+ $sql = 'SELECT `user` FROM `*PREFIX*permissions` WHERE `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($fileId));
$users = array();
while ($row = $result->fetchRow()) {
$users[] = $row['user'];
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 46122221dc2..9b94a24f481 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -8,6 +8,8 @@
namespace OC\Files\Cache;
+use OC\Files\Filesystem;
+
class Scanner {
/**
* @var \OC\Files\Storage\Storage $storage
@@ -27,6 +29,9 @@ class Scanner {
const SCAN_RECURSIVE = true;
const SCAN_SHALLOW = false;
+ const REUSE_ETAG = 1;
+ const REUSE_SIZE = 2;
+
public function __construct(\OC\Files\Storage\Storage $storage) {
$this->storage = $storage;
$this->storageId = $this->storage->getId();
@@ -59,12 +64,12 @@ class Scanner {
* scan a single file and store it in the cache
*
* @param string $file
- * @param bool $checkExisting check existing folder sizes in the cache instead of always using -1 for folder size
+ * @param int $reuseExisting
* @return array with metadata of the scanned file
*/
- public function scanFile($file, $checkExisting = false) {
- if ( ! self::isPartialFile($file)
- and ! \OC\Files\Filesystem::isFileBlacklisted($file)
+ public function scanFile($file, $reuseExisting = 0) {
+ if (!self::isPartialFile($file)
+ and !Filesystem::isFileBlacklisted($file)
) {
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
$data = $this->getData($file);
@@ -78,18 +83,23 @@ class Scanner {
$this->scanFile($parent);
}
}
- if($cacheData = $this->cache->get($file)) {
- if ($data['mtime'] === $cacheData['mtime'] &&
- $data['size'] === $cacheData['size']) {
- $data['etag'] = $cacheData['etag'];
- }
- }
- if ($checkExisting and $cacheData) {
- if ($data['size'] === -1) {
- $data['size'] = $cacheData['size'];
+ $newData = $data;
+ if ($reuseExisting and $cacheData = $this->cache->get($file)) {
+ // only reuse data if the file hasn't explicitly changed
+ if ($data['mtime'] === $cacheData['mtime']) {
+ if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
+ $data['size'] = $cacheData['size'];
+ }
+ if ($reuseExisting & self::REUSE_ETAG) {
+ $data['etag'] = $cacheData['etag'];
+ }
}
+ // Only update metadata that has changed
+ $newData = array_diff($data, $cacheData);
}
- $this->cache->put($file, $data);
+ }
+ if (!empty($newData)) {
+ $this->cache->put($file, $newData);
}
return $data;
}
@@ -97,55 +107,79 @@ class Scanner {
}
/**
- * scan all the files in a folder and store them in the cache
+ * scan a folder and all it's children
*
* @param string $path
* @param bool $recursive
- * @param bool $onlyChilds
+ * @param int $reuse
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
*/
- public function scan($path, $recursive = self::SCAN_RECURSIVE, $onlyChilds = false) {
- \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId));
- $childQueue = array();
- if (!$onlyChilds) {
- $this->scanFile($path);
+ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
+ if ($reuse === -1) {
+ $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
}
+ $this->scanFile($path, $reuse);
+ return $this->scanChildren($path, $recursive, $reuse);
+ }
+ /**
+ * scan all the files and folders in a folder
+ *
+ * @param string $path
+ * @param bool $recursive
+ * @param int $reuse
+ * @return int the size of the scanned folder or -1 if the size is unknown at this stage
+ */
+ public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
+ if ($reuse === -1) {
+ $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
+ }
+ \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId));
$size = 0;
+ $childQueue = array();
+ $existingChildren = array();
+ if ($this->cache->inCache($path)) {
+ $children = $this->cache->getFolderContents($path);
+ foreach ($children as $child) {
+ $existingChildren[] = $child['name'];
+ }
+ }
+ $newChildren = array();
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
$child = ($path) ? $path . '/' . $file : $file;
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
- $data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
+ if (!Filesystem::isIgnoredDir($file)) {
+ $newChildren[] = $file;
+ $data = $this->scanFile($child, $reuse);
if ($data) {
if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
$childQueue[] = $child;
- $data['size'] = 0;
} else {
$size = -1;
}
- }
-
- if ($size !== -1) {
+ } else if ($size !== -1) {
$size += $data['size'];
}
}
}
}
+ $removedChildren = \array_diff($existingChildren, $newChildren);
+ foreach ($removedChildren as $childName) {
+ $child = ($path) ? $path . '/' . $childName : $childName;
+ $this->cache->remove($child);
+ }
\OC_DB::commit();
foreach ($childQueue as $child) {
- $childSize = $this->scan($child, self::SCAN_RECURSIVE, true);
+ $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE);
if ($childSize === -1) {
$size = -1;
} else {
$size += $childSize;
}
}
- if ($size !== -1) {
- $this->cache->put($path, array('size' => $size));
- }
+ $this->cache->put($path, array('size' => $size));
}
return $size;
}
diff --git a/lib/files/cache/storage.php b/lib/files/cache/storage.php
index 72de376798c..8a9e47ca36d 100644
--- a/lib/files/cache/storage.php
+++ b/lib/files/cache/storage.php
@@ -32,13 +32,13 @@ class Storage {
$this->storageId = md5($this->storageId);
}
- $query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
- $result = $query->execute(array($this->storageId));
+ $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->storageId));
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)');
- $query->execute(array($this->storageId));
+ $sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
+ \OC_DB::executeAudited($sql, array($this->storageId));
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
}
}
@@ -48,8 +48,9 @@ class Storage {
}
public static function getStorageId($numericId) {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?');
- $result = $query->execute(array($numericId));
+
+ $sql = 'SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($numericId));
if ($row = $result->fetchRow()) {
return $row['id'];
} else {
diff --git a/lib/files/cache/updater.php b/lib/files/cache/updater.php
index 417a47f3830..87c33a313a4 100644
--- a/lib/files/cache/updater.php
+++ b/lib/files/cache/updater.php
@@ -7,6 +7,7 @@
*/
namespace OC\Files\Cache;
+use OCP\Util;
/**
* listen to filesystem hooks and change the cache accordingly
@@ -102,7 +103,7 @@ class Updater {
static public function correctFolder($path, $time) {
if ($path !== '' && $path !== '/') {
$parent = dirname($path);
- if ($parent === '.') {
+ if ($parent === '.' || $parent === '\\') {
$parent = '';
}
/**
@@ -116,6 +117,8 @@ class Updater {
if ($id !== -1) {
$cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
self::correctFolder($parent, $time);
+ } else {
+ Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR);
}
}
}
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index ca044ba81de..cfb9a117311 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -78,7 +78,7 @@ class Upgrade {
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
}
if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
- $insertQuery->execute(array($data['id'], $data['storage'],
+ \OC_DB::executeAudited($insertQuery, array($data['id'], $data['storage'],
$data['path'], $data['path_hash'], $data['parent'], $data['name'],
$data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted'], $data['etag']));
}
@@ -97,7 +97,7 @@ class Upgrade {
if(is_null($query)) {
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?');
}
- $result = $query->execute(array($storage, $pathHash, $id));
+ $result = \OC_DB::executeAudited($query, array($storage, $pathHash, $id));
return (bool)$result->fetchRow();
}
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index b10625e20de..d3fddf8c421 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -152,6 +152,9 @@ class Filesystem {
* @return string
*/
static public function getMountPoint($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($path);
if ($mount) {
return $mount->getMountPoint();
@@ -167,6 +170,9 @@ class Filesystem {
* @return string[]
*/
static public function getMountPoints($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$result = array();
$mounts = self::$mounts->findIn($path);
foreach ($mounts as $mount) {
@@ -182,6 +188,9 @@ class Filesystem {
* @return \OC\Files\Storage\Storage
*/
public static function getStorage($mountPoint) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($mountPoint);
return $mount->getStorage();
}
@@ -191,6 +200,9 @@ class Filesystem {
* @return Mount\Mount[]
*/
public static function getMountByStorageId($id) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
return self::$mounts->findByStorageId($id);
}
@@ -199,6 +211,9 @@ class Filesystem {
* @return Mount\Mount[]
*/
public static function getMountByNumericId($id) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
return self::$mounts->findByNumericId($id);
}
@@ -209,6 +224,9 @@ class Filesystem {
* @return array consisting of the storage and the internal path
*/
static public function resolvePath($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($path);
if ($mount) {
return array($mount->getStorage(), $mount->getInternalPath($path));
@@ -223,7 +241,7 @@ class Filesystem {
}
self::$defaultInstance = new View($root);
- if(!self::$mounts) {
+ if (!self::$mounts) {
self::$mounts = new Mount\Manager();
}
@@ -235,8 +253,8 @@ class Filesystem {
return true;
}
- static public function initMounts(){
- if(!self::$mounts) {
+ static public function initMounts() {
+ if (!self::$mounts) {
self::$mounts = new Mount\Manager();
}
}
@@ -359,7 +377,9 @@ class Filesystem {
* clear all mounts and storage backends
*/
public static function clearMounts() {
- self::$mounts->clear();
+ if (self::$mounts) {
+ self::$mounts->clear();
+ }
}
/**
@@ -370,6 +390,9 @@ class Filesystem {
* @param string $mountpoint
*/
static public function mount($class, $arguments, $mountpoint) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = new Mount\Mount($class, $mountpoint, $arguments);
self::$mounts->addMount($mount);
}
@@ -631,9 +654,8 @@ class Filesystem {
$path = substr($path, 0, -1);
}
//normalize unicode if possible
- if (class_exists('Normalizer')) {
- $path = \Normalizer::normalize($path);
- }
+ $path = \OC_Util::normalizeUnicode($path);
+
return $path;
}
diff --git a/lib/files/mapper.php b/lib/files/mapper.php
index 15f5f0628b5..47abd4e52fe 100644
--- a/lib/files/mapper.php
+++ b/lib/files/mapper.php
@@ -53,11 +53,9 @@ class Mapper
}
if ($isLogicPath) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?');
- $query->execute(array($path));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?', array($path));
} else {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*file_map` WHERE `physic_path` LIKE ?');
- $query->execute(array($path));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*file_map` WHERE `physic_path` LIKE ?', array($path));
}
}
@@ -73,8 +71,8 @@ class Mapper
$physicPath1 = $this->logicToPhysical($path1, true);
$physicPath2 = $this->logicToPhysical($path2, true);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?');
- $result = $query->execute(array($path1.'%'));
+ $sql = 'SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?';
+ $result = \OC_DB::executeAudited($sql, array($path1.'%'));
$updateQuery = \OC_DB::prepare('UPDATE `*PREFIX*file_map`'
.' SET `logic_path` = ?'
.' , `logic_path_hash` = ?'
@@ -88,7 +86,8 @@ class Mapper
$newPhysic = $physicPath2.$this->stripRootFolder($currentPhysic, $physicPath1);
if ($path1 !== $currentLogic) {
try {
- $updateQuery->execute(array($newLogic, md5($newLogic), $newPhysic, md5($newPhysic), $currentLogic));
+ \OC_DB::executeAudited($updateQuery, array($newLogic, md5($newLogic), $newPhysic, md5($newPhysic),
+ $currentLogic));
} catch (\Exception $e) {
error_log('Mapper::Copy failed '.$currentLogic.' -> '.$newLogic.'\n'.$e);
throw $e;
@@ -123,8 +122,8 @@ class Mapper
private function resolveLogicPath($logicPath) {
$logicPath = $this->stripLast($logicPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?');
- $result = $query->execute(array(md5($logicPath)));
+ $sql = 'SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array(md5($logicPath)));
$result = $result->fetchRow();
if ($result === false) {
return null;
@@ -135,8 +134,8 @@ class Mapper
private function resolvePhysicalPath($physicalPath) {
$physicalPath = $this->stripLast($physicalPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
- $result = $query->execute(array(md5($physicalPath)));
+ $sql = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
+ $result = \OC_DB::executeAudited($sql, array(md5($physicalPath)));
$result = $result->fetchRow();
return $result['logic_path'];
@@ -163,8 +162,9 @@ class Mapper
}
private function insert($logicPath, $physicalPath) {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`) VALUES(?, ?, ?, ?)');
- $query->execute(array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
+ $sql = 'INSERT INTO `*PREFIX*file_map` (`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`)
+ VALUES (?, ?, ?, ?)';
+ \OC_DB::executeAudited($sql, array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
}
public function slugifyPath($path, $index=null) {
@@ -172,14 +172,9 @@ class Mapper
$pathElements = explode('/', $path);
$sluggedElements = array();
-
- // rip off the extension ext from last element
+
$last= end($pathElements);
- $parts = pathinfo($last);
- $filename = $parts['filename'];
- array_pop($pathElements);
- array_push($pathElements, $filename);
-
+
foreach ($pathElements as $pathElement) {
// remove empty elements
if (empty($pathElement)) {
@@ -192,13 +187,15 @@ class Mapper
// apply index to file name
if ($index !== null) {
$last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'-'.$index);
- }
+
+ // if filename contains periods - add index number before last period
+ if (preg_match('~\.[^\.]+$~i',$last,$extension)){
+ array_push($sluggedElements, substr($last,0,-(strlen($extension[0]))).'-'.$index.$extension[0]);
+ } else {
+ // if filename doesn't contain periods add index ofter the last char
+ array_push($sluggedElements, $last.'-'.$index);
+ }
- // add back the extension
- if (isset($parts['extension'])) {
- $last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'.'.$parts['extension']);
}
$sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);
@@ -213,8 +210,8 @@ class Mapper
*/
private function slugify($text)
{
- // replace non letter or digits by -
- $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
+ // replace non letter or digits or dots by -
+ $text = preg_replace('~[^\\pL\d\.]+~u', '-', $text);
// trim
$text = trim($text, '-');
@@ -228,7 +225,10 @@ class Mapper
$text = strtolower($text);
// remove unwanted characters
- $text = preg_replace('~[^-\w]+~', '', $text);
+ $text = preg_replace('~[^-\w\.]+~', '', $text);
+
+ // trim ending dots (for security reasons and win compatibility)
+ $text = preg_replace('~\.+$~', '', $text);
if (empty($text)) {
return uniqid();
diff --git a/lib/files/view.php b/lib/files/view.php
index 8e7727d335c..25071709fbe 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -267,7 +267,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
@@ -300,7 +300,7 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path) && $result !== false) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
@@ -344,7 +344,7 @@ class View {
\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -371,7 +371,7 @@ class View {
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
if ($storage) {
$result = $storage->rename($internalPath1, $internalPath2);
- \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
+ \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} else {
$result = false;
}
@@ -386,11 +386,19 @@ class View {
$source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w');
list($count, $result) = \OC_Helper::streamCopy($source, $target);
- list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
- $storage1->unlink($internalPath1);
+
+ // close open handle - especially $source is necessary because unlink below will
+ // throw an exception on windows because the file is locked
+ fclose($source);
+ fclose($target);
+
+ if ($result !== false) {
+ list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $storage1->unlink($internalPath1);
+ }
}
}
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1)) {
+ if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1) && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_rename,
@@ -418,7 +426,7 @@ class View {
\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -484,7 +492,7 @@ class View {
list($count, $result) = \OC_Helper::streamCopy($source, $target);
}
}
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_copy,
@@ -632,7 +640,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
@@ -648,7 +656,7 @@ class View {
$result = $storage->$operation($internalPath);
}
$result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) {
+ if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && $result !== false) {
if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
$this->runHooks($hooks, $path, true);
}
@@ -760,7 +768,7 @@ class View {
}
}
- $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
+ $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
return $data;
}
@@ -797,18 +805,18 @@ class View {
}
$files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+ $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user);
$ids = array();
foreach ($files as $i => $file) {
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$ids[] = $file['fileid'];
- $permissions = $permissionsCache->get($file['fileid'], $user);
- if ($permissions === -1) {
- $permissions = $storage->getPermissions($file['path']);
- $permissionsCache->set($file['fileid'], $user, $permissions);
+ if (!isset($permissions[$file['fileid']])) {
+ $permissions[$file['fileid']] = $storage->getPermissions($file['path']);
+ $permissionsCache->set($file['fileid'], $user, $permissions[$file['fileid']]);
}
- $files[$i]['permissions'] = $permissions;
+ $files[$i]['permissions'] = $permissions[$file['fileid']];
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
diff --git a/lib/helper.php b/lib/helper.php
index c69445ed788..a315c640d1a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -27,6 +27,7 @@
class OC_Helper {
private static $mimetypes=array();
private static $tmpFiles=array();
+ private static $mimetypeIcons = array();
/**
* @brief Creates an url using a defined route
@@ -187,31 +188,38 @@ class OC_Helper {
*
* Returns the path to the image of this file type.
*/
- public static function mimetypeIcon( $mimetype ) {
- $alias=array('application/xml'=>'code/xml');
- if(isset($alias[$mimetype])) {
- $mimetype=$alias[$mimetype];
+ public static function mimetypeIcon($mimetype) {
+ $alias = array('application/xml' => 'code/xml');
+ if (isset($alias[$mimetype])) {
+ $mimetype = $alias[$mimetype];
+ }
+ if (isset(self::$mimetypeIcons[$mimetype])) {
+ return self::$mimetypeIcons[$mimetype];
}
// Replace slash and backslash with a minus
- $mimetype = str_replace( "/", "-", $mimetype );
- $mimetype = str_replace( "\\", "-", $mimetype );
+ $icon = str_replace('/', '-', $mimetype);
+ $icon = str_replace( '\\', '-', $icon);
// Is it a dir?
- if( $mimetype == "dir" ) {
- return OC::$WEBROOT."/core/img/filetypes/folder.png";
+ if ($mimetype === 'dir') {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/folder.png';
+ return OC::$WEBROOT.'/core/img/filetypes/folder.png';
}
// Icon exists?
- if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) {
- return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
- }
- //try only the first part of the filetype
- $mimetype=substr($mimetype, 0, strpos($mimetype, '-'));
- if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) {
- return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
+ if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$icon.'.png')) {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png';
+ return OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png';
}
- else{
- return OC::$WEBROOT."/core/img/filetypes/file.png";
+
+ // Try only the first part of the filetype
+ $mimePart = substr($icon, 0, strpos($icon, '-'));
+ if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$mimePart.'.png')) {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png';
+ return OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png';
+ } else {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/file.png';
+ return OC::$WEBROOT.'/core/img/filetypes/file.png';
}
}
@@ -356,6 +364,26 @@ class OC_Helper {
}
/**
+ * Try to guess the mimetype based on filename
+ *
+ * @param string $path
+ * @return string
+ */
+ static public function getFileNameMimeType($path){
+ if(strpos($path, '.')) {
+ //try to guess the type by the file extension
+ if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
+ self::$mimetypes=include 'mimetypes.list.php';
+ }
+ $extension=strtolower(strrchr(basename($path), "."));
+ $extension=substr($extension, 1);//remove leading .
+ return (isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
+ }else{
+ return 'application/octet-stream';
+ }
+ }
+
+ /**
* get the mimetype form a local file
* @param string $path
* @return string
@@ -369,17 +397,7 @@ class OC_Helper {
return "httpd/unix-directory";
}
- if(strpos($path, '.')) {
- //try to guess the type by the file extension
- if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
- self::$mimetypes=include 'mimetypes.list.php';
- }
- $extension=strtolower(strrchr(basename($path), "."));
- $extension=substr($extension, 1);//remove leading .
- $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
- }else{
- $mimeType='application/octet-stream';
- }
+ $mimeType = self::getFileNameMimeType($path);
if($mimeType=='application/octet-stream' and function_exists('finfo_open')
and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
@@ -601,7 +619,7 @@ class OC_Helper {
}
/**
- * remove all files in PHP /oc-noclean temp dir
+ * remove all files in PHP /oc-noclean temp dir
*/
public static function cleanTmpNoClean() {
$tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/';
diff --git a/lib/hooks/publicemitter.php b/lib/hooks/publicemitter.php
new file mode 100644
index 00000000000..e2371713ac3
--- /dev/null
+++ b/lib/hooks/publicemitter.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Hooks;
+
+class PublicEmitter extends BasicEmitter {
+ /**
+ * @param string $scope
+ * @param string $method
+ * @param array $arguments optional
+ */
+ public function emit($scope, $method, $arguments = array()) {
+ parent::emit($scope, $method, $arguments);
+ }
+}
diff --git a/lib/l10n/bg_BG.php b/lib/l10n/bg_BG.php
index 2de4c0a6e68..8412ac9548f 100644
--- a/lib/l10n/bg_BG.php
+++ b/lib/l10n/bg_BG.php
@@ -21,16 +21,21 @@
"%s enter the database username." => "%s въведете потребителско име за базата с данни.",
"%s enter the database name." => "%s въведете име на базата с данни.",
"%s you may not use dots in the database name" => "%s, не можете да ползвате точки в името на базата от данни",
+"%s set the database host." => "%s задай хост на базата данни.",
"PostgreSQL username and/or password not valid" => "Невалидно PostgreSQL потребителско име и/или парола",
"You need to enter either an existing account or the administrator." => "Необходимо е да влезете в всъществуващ акаунт или като администратора",
+"Oracle connection could not be established" => "Oracle връзка не можа да се осъществи",
"MySQL username and/or password not valid" => "Невалидно MySQL потребителско име и/или парола",
"DB Error: \"%s\"" => "Грешка в базата от данни: \"%s\"",
+"Offending command was: \"%s\"" => "Проблемната команда беше: \"%s\"",
"MySQL user '%s'@'localhost' exists already." => "MySQL потребителят '%s'@'localhost' вече съществува",
"Drop this user from MySQL" => "Изтриване на потребителя от MySQL",
"MySQL user '%s'@'%%' already exists" => "MySQL потребителят '%s'@'%%' вече съществува.",
"Drop this user from MySQL." => "Изтриване на потребителя от MySQL.",
"Oracle username and/or password not valid" => "Невалидно Oracle потребителско име и/или парола",
+"Offending command was: \"%s\", name: %s, password: %s" => "Проблемната команда беше: \"%s\", име: %s, парола: %s",
"MS SQL username and/or password not valid: %s" => "Невалидно MS SQL потребителско име и/или парола: %s",
+"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Вашият web сървър все още не е удачно настроен да позволява синхронизация на файлове, защото WebDAV интерфейсът изглежда не работи.",
"Please double check the <a href='%s'>installation guides</a>." => "Моля направете повторна справка с <a href='%s'>ръководството за инсталиране</a>.",
"seconds ago" => "преди секунди",
"1 minute ago" => "преди 1 минута",
diff --git a/lib/l10n/ca.php b/lib/l10n/ca.php
index d431fd72072..5c368a85b28 100644
--- a/lib/l10n/ca.php
+++ b/lib/l10n/ca.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s establiu l'ordinador central de la base de dades.",
"PostgreSQL username and/or password not valid" => "Nom d'usuari i/o contrasenya PostgreSQL no vàlids",
"You need to enter either an existing account or the administrator." => "Heu d'escriure un compte existent o el d'administrador.",
+"Oracle connection could not be established" => "No s'ha pogut establir la connexió Oracle",
"MySQL username and/or password not valid" => "Nom d'usuari i/o contrasenya MySQL no vàlids",
"DB Error: \"%s\"" => "Error DB: \"%s\"",
"Offending command was: \"%s\"" => "L'ordre en conflicte és: \"%s\"",
diff --git a/lib/l10n/cs_CZ.php b/lib/l10n/cs_CZ.php
index 36469507d40..b74b9a7184c 100644
--- a/lib/l10n/cs_CZ.php
+++ b/lib/l10n/cs_CZ.php
@@ -24,6 +24,7 @@
"%s set the database host." => "Zadejte název počítače s databází %s.",
"PostgreSQL username and/or password not valid" => "Uživatelské jméno, či heslo PostgreSQL není platné",
"You need to enter either an existing account or the administrator." => "Musíte zadat existující účet, či správce.",
+"Oracle connection could not be established" => "Spojení s Oracle nemohlo být navázáno",
"MySQL username and/or password not valid" => "Uživatelské jméno, či heslo MySQL není platné",
"DB Error: \"%s\"" => "Chyba DB: \"%s\"",
"Offending command was: \"%s\"" => "Podezřelý příkaz byl: \"%s\"",
diff --git a/lib/l10n/da.php b/lib/l10n/da.php
index aead17f510e..3202ae3a335 100644
--- a/lib/l10n/da.php
+++ b/lib/l10n/da.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s sæt database værten.",
"PostgreSQL username and/or password not valid" => "PostgreSQL brugernavn og/eller kodeord er ikke gyldigt.",
"You need to enter either an existing account or the administrator." => "Du bliver nødt til at indtaste en eksisterende bruger eller en administrator.",
+"Oracle connection could not be established" => "Oracle forbindelsen kunne ikke etableres",
"MySQL username and/or password not valid" => "MySQL brugernavn og/eller kodeord er ikke gyldigt.",
"DB Error: \"%s\"" => "Databasefejl: \"%s\"",
"Offending command was: \"%s\"" => "Fejlende kommando var: \"%s\"",
diff --git a/lib/l10n/de.php b/lib/l10n/de.php
index 74715bc66eb..4869689ba78 100644
--- a/lib/l10n/de.php
+++ b/lib/l10n/de.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s setze den Datenbank-Host",
"PostgreSQL username and/or password not valid" => "PostgreSQL Benutzername und/oder Passwort ungültig",
"You need to enter either an existing account or the administrator." => "Du musst entweder ein existierendes Benutzerkonto oder das Administratoren-Konto angeben.",
+"Oracle connection could not be established" => "Es konnte keine Verbindung zur Oracle-Datenbank hergestellt werden",
"MySQL username and/or password not valid" => "MySQL Benutzername und/oder Passwort ungültig",
"DB Error: \"%s\"" => "DB Fehler: \"%s\"",
"Offending command was: \"%s\"" => "Fehlerhafter Befehl war: \"%s\"",
diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php
index d93f9e4de9e..5ebe4fb26fc 100644
--- a/lib/l10n/de_DE.php
+++ b/lib/l10n/de_DE.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s setze den Datenbank-Host",
"PostgreSQL username and/or password not valid" => "PostgreSQL Benutzername und/oder Passwort ungültig",
"You need to enter either an existing account or the administrator." => "Sie müssen entweder ein existierendes Benutzerkonto oder das Administratoren-Konto angeben.",
+"Oracle connection could not be established" => "Die Oracle-Verbindung konnte nicht aufgebaut werden.",
"MySQL username and/or password not valid" => "MySQL Benutzername und/oder Passwort ungültig",
"DB Error: \"%s\"" => "DB Fehler: \"%s\"",
"Offending command was: \"%s\"" => "Fehlerhafter Befehl war: \"%s\"",
diff --git a/lib/l10n/es.php b/lib/l10n/es.php
index fa95089a617..3b32036d3af 100644
--- a/lib/l10n/es.php
+++ b/lib/l10n/es.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s ingresar el host de la base de datos.",
"PostgreSQL username and/or password not valid" => "Usuario y/o contraseña de PostgreSQL no válidos",
"You need to enter either an existing account or the administrator." => "Tiene que ingresar una cuenta existente o la del administrador.",
+"Oracle connection could not be established" => "No se pudo establecer la conexión a Oracle",
"MySQL username and/or password not valid" => "Usuario y/o contraseña de MySQL no válidos",
"DB Error: \"%s\"" => "Error BD: \"%s\"",
"Offending command was: \"%s\"" => "Comando infractor: \"%s\"",
diff --git a/lib/l10n/es_AR.php b/lib/l10n/es_AR.php
index 1df1b16de65..b4b2a33cd01 100644
--- a/lib/l10n/es_AR.php
+++ b/lib/l10n/es_AR.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s Especifique la dirección de la Base de Datos",
"PostgreSQL username and/or password not valid" => "Nombre de usuario o contraseña de PostgradeSQL no válido.",
"You need to enter either an existing account or the administrator." => "Debe ingresar una cuenta existente o el administrador",
+"Oracle connection could not be established" => "No fue posible establecer la conexión a Oracle",
"MySQL username and/or password not valid" => "Usuario y/o contraseña MySQL no válido",
"DB Error: \"%s\"" => "Error DB: \"%s\"",
"Offending command was: \"%s\"" => "El comando no comprendido es: \"%s\"",
diff --git a/lib/l10n/et_EE.php b/lib/l10n/et_EE.php
index 2e25f1aa711..24fc98bde64 100644
--- a/lib/l10n/et_EE.php
+++ b/lib/l10n/et_EE.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s määra andmebaasi server.",
"PostgreSQL username and/or password not valid" => "PostgreSQL kasutajatunnus ja/või parool pole õiged",
"You need to enter either an existing account or the administrator." => "Sisesta kas juba olemasolev konto või administrator.",
+"Oracle connection could not be established" => "Ei suuda luua ühendust Oracle baasiga",
"MySQL username and/or password not valid" => "MySQL kasutajatunnus ja/või parool pole õiged",
"DB Error: \"%s\"" => "Andmebaasi viga: \"%s\"",
"Offending command was: \"%s\"" => "Tõrkuv käsk oli: \"%s\"",
diff --git a/lib/l10n/fr.php b/lib/l10n/fr.php
index af4efc2b63f..aed5d056f37 100644
--- a/lib/l10n/fr.php
+++ b/lib/l10n/fr.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s spécifiez l'hôte de la base de données.",
"PostgreSQL username and/or password not valid" => "Nom d'utilisateur et/ou mot de passe de la base PostgreSQL invalide",
"You need to enter either an existing account or the administrator." => "Vous devez spécifier soit le nom d'un compte existant, soit celui de l'administrateur.",
+"Oracle connection could not be established" => "La connexion Oracle ne peut pas être établie",
"MySQL username and/or password not valid" => "Nom d'utilisateur et/ou mot de passe de la base MySQL invalide",
"DB Error: \"%s\"" => "Erreur de la base de données : \"%s\"",
"Offending command was: \"%s\"" => "La requête en cause est : \"%s\"",
diff --git a/lib/l10n/gl.php b/lib/l10n/gl.php
index 96b083821dc..1b4db4b30af 100644
--- a/lib/l10n/gl.php
+++ b/lib/l10n/gl.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s estabeleza o servidor da base de datos",
"PostgreSQL username and/or password not valid" => "Nome de usuario e/ou contrasinal de PostgreSQL incorrecto",
"You need to enter either an existing account or the administrator." => "Deberá introducir unha conta existente ou o administrador.",
+"Oracle connection could not be established" => "Non foi posíbel estabelecer a conexión con Oracle",
"MySQL username and/or password not valid" => "Nome de usuario e/ou contrasinal de MySQL incorrecto",
"DB Error: \"%s\"" => "Produciuse un erro na base de datos: «%s»",
"Offending command was: \"%s\"" => "A orde ofensiva foi: «%s»",
diff --git a/lib/l10n/he.php b/lib/l10n/he.php
index dcd0545adba..0069d77eee4 100644
--- a/lib/l10n/he.php
+++ b/lib/l10n/he.php
@@ -15,6 +15,8 @@
"Files" => "קבצים",
"Text" => "טקסט",
"Images" => "תמונות",
+"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "שרת האינטרנט שלך אינו מוגדר לצורכי סנכרון קבצים עדיין כיוון שמנשק ה־WebDAV כנראה אינו תקין.",
+"Please double check the <a href='%s'>installation guides</a>." => "נא לעיין שוב ב<a href='%s'>מדריכי ההתקנה</a>.",
"seconds ago" => "שניות",
"1 minute ago" => "לפני דקה אחת",
"%d minutes ago" => "לפני %d דקות",
diff --git a/lib/l10n/hu_HU.php b/lib/l10n/hu_HU.php
index de63ae3fadc..3b5c886bd2c 100644
--- a/lib/l10n/hu_HU.php
+++ b/lib/l10n/hu_HU.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s adja meg az adatbázist szolgáltató számítógép nevét.",
"PostgreSQL username and/or password not valid" => "A PostgreSQL felhasználói név és/vagy jelszó érvénytelen",
"You need to enter either an existing account or the administrator." => "Vagy egy létező felhasználó vagy az adminisztrátor bejelentkezési nevét kell megadnia",
+"Oracle connection could not be established" => "Az Oracle kapcsolat nem hozható létre",
"MySQL username and/or password not valid" => "A MySQL felhasználói név és/vagy jelszó érvénytelen",
"DB Error: \"%s\"" => "Adatbázis hiba: \"%s\"",
"Offending command was: \"%s\"" => "A hibát ez a parancs okozta: \"%s\"",
diff --git a/lib/l10n/ja_JP.php b/lib/l10n/ja_JP.php
index 0e856b0497d..a2eb4bee67b 100644
--- a/lib/l10n/ja_JP.php
+++ b/lib/l10n/ja_JP.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s にデータベースホストを設定します。",
"PostgreSQL username and/or password not valid" => "PostgreSQLのユーザ名もしくはパスワードは有効ではありません",
"You need to enter either an existing account or the administrator." => "既存のアカウントもしくは管理者のどちらかを入力する必要があります。",
+"Oracle connection could not be established" => "Oracleへの接続が確立できませんでした。",
"MySQL username and/or password not valid" => "MySQLのユーザ名もしくはパスワードは有効ではありません",
"DB Error: \"%s\"" => "DBエラー: \"%s\"",
"Offending command was: \"%s\"" => "違反コマンド: \"%s\"",
diff --git a/lib/l10n/ko.php b/lib/l10n/ko.php
index bf2a68369f1..bfb99544a3b 100644
--- a/lib/l10n/ko.php
+++ b/lib/l10n/ko.php
@@ -16,6 +16,8 @@
"Files" => "파일",
"Text" => "텍스트",
"Images" => "그림",
+"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "WebDAV 인터페이스가 제대로 작동하지 않습니다. 웹 서버에서 파일 동기화를 사용할 수 있도록 설정이 제대로 되지 않은 것 같습니다.",
+"Please double check the <a href='%s'>installation guides</a>." => "<a href='%s'>설치 가이드</a>를 다시 한 번 확인하십시오.",
"seconds ago" => "초 전",
"1 minute ago" => "1분 전",
"%d minutes ago" => "%d분 전",
diff --git a/lib/l10n/lt_LT.php b/lib/l10n/lt_LT.php
index cebaa6937d8..b8268ed4376 100644
--- a/lib/l10n/lt_LT.php
+++ b/lib/l10n/lt_LT.php
@@ -14,13 +14,17 @@
"Token expired. Please reload page." => "Sesija baigėsi. Prašome perkrauti puslapį.",
"Files" => "Failai",
"Text" => "Žinučių",
+"Images" => "Paveikslėliai",
"seconds ago" => "prieš sekundę",
"1 minute ago" => "Prieš 1 minutę",
"%d minutes ago" => "prieš %d minučių",
+"1 hour ago" => "prieš 1 valandą",
+"%d hours ago" => "prieš %d valandų",
"today" => "šiandien",
"yesterday" => "vakar",
"%d days ago" => "prieš %d dienų",
"last month" => "praeitą mėnesį",
+"%d months ago" => "prieš %d mėnesių",
"last year" => "praeitais metais",
"years ago" => "prieš metus"
);
diff --git a/lib/l10n/nl.php b/lib/l10n/nl.php
index 7340591e9af..2a6086a5968 100644
--- a/lib/l10n/nl.php
+++ b/lib/l10n/nl.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s instellen databaseservernaam.",
"PostgreSQL username and/or password not valid" => "PostgreSQL gebruikersnaam en/of wachtwoord ongeldig",
"You need to enter either an existing account or the administrator." => "Geef of een bestaand account op of het beheerdersaccount.",
+"Oracle connection could not be established" => "Er kon geen verbinding met Oracle worden bereikt",
"MySQL username and/or password not valid" => "MySQL gebruikersnaam en/of wachtwoord ongeldig",
"DB Error: \"%s\"" => "DB Fout: \"%s\"",
"Offending command was: \"%s\"" => "Onjuiste commande was: \"%s\"",
diff --git a/lib/l10n/pl.php b/lib/l10n/pl.php
index de15964b13b..53a9290785c 100644
--- a/lib/l10n/pl.php
+++ b/lib/l10n/pl.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s ustaw hosta bazy danych.",
"PostgreSQL username and/or password not valid" => "PostgreSQL: Nazwa użytkownika i/lub hasło jest niepoprawne",
"You need to enter either an existing account or the administrator." => "Należy wprowadzić istniejące konto użytkownika lub administratora.",
+"Oracle connection could not be established" => "Nie można ustanowić połączenia z bazą Oracle",
"MySQL username and/or password not valid" => "MySQL: Nazwa użytkownika i/lub hasło jest niepoprawne",
"DB Error: \"%s\"" => "Błąd DB: \"%s\"",
"Offending command was: \"%s\"" => "Niepoprawna komenda: \"%s\"",
diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php
index 176f4286c9d..f49258157ed 100644
--- a/lib/l10n/pt_PT.php
+++ b/lib/l10n/pt_PT.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s defina o servidor da base de dados (geralmente localhost)",
"PostgreSQL username and/or password not valid" => "Nome de utilizador/password do PostgreSQL inválido",
"You need to enter either an existing account or the administrator." => "Precisa de introduzir uma conta existente ou de administrador",
+"Oracle connection could not be established" => "Não foi possível estabelecer a ligação Oracle",
"MySQL username and/or password not valid" => "Nome de utilizador/password do MySQL inválida",
"DB Error: \"%s\"" => "Erro na BD: \"%s\"",
"Offending command was: \"%s\"" => "O comando gerador de erro foi: \"%s\"",
diff --git a/lib/l10n/ru.php b/lib/l10n/ru.php
index e077b688c09..e3e3aee5a92 100644
--- a/lib/l10n/ru.php
+++ b/lib/l10n/ru.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s задайте хост базы данных.",
"PostgreSQL username and/or password not valid" => "Неверное имя пользователя и/или пароль PostgreSQL",
"You need to enter either an existing account or the administrator." => "Вы должны войти или в существующий аккаунт или под администратором.",
+"Oracle connection could not be established" => "соединение с Oracle не может быть установлено",
"MySQL username and/or password not valid" => "Неверное имя пользователя и/или пароль MySQL",
"DB Error: \"%s\"" => "Ошибка БД: \"%s\"",
"Offending command was: \"%s\"" => "Вызываемая команда была: \"%s\"",
diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php
index 121b2405dcf..c1ec2470b46 100644
--- a/lib/l10n/sk_SK.php
+++ b/lib/l10n/sk_SK.php
@@ -24,6 +24,7 @@
"%s set the database host." => "Zadajte názov počítača s databázou %s.",
"PostgreSQL username and/or password not valid" => "Používateľské meno a/alebo heslo pre PostgreSQL databázu je neplatné",
"You need to enter either an existing account or the administrator." => "Musíte zadať jestvujúci účet alebo administrátora.",
+"Oracle connection could not be established" => "Nie je možné pripojiť sa k Oracle",
"MySQL username and/or password not valid" => "Používateľské meno a/alebo heslo pre MySQL databázu je neplatné",
"DB Error: \"%s\"" => "Chyba DB: \"%s\"",
"Offending command was: \"%s\"" => "Podozrivý príkaz bol: \"%s\"",
diff --git a/lib/l10n/sv.php b/lib/l10n/sv.php
index 3dcb26d5d8d..f2b7c892058 100644
--- a/lib/l10n/sv.php
+++ b/lib/l10n/sv.php
@@ -16,6 +16,25 @@
"Files" => "Filer",
"Text" => "Text",
"Images" => "Bilder",
+"Set an admin username." => "Ange ett användarnamn för administratören.",
+"Set an admin password." => "Ange ett administratörslösenord.",
+"%s enter the database username." => "%s ange databasanvändare.",
+"%s enter the database name." => "%s ange databasnamn",
+"%s you may not use dots in the database name" => "%s du får inte använda punkter i databasnamnet",
+"%s set the database host." => "%s ange databasserver/host.",
+"PostgreSQL username and/or password not valid" => "PostgreSQL-användarnamnet och/eller lösenordet är felaktigt",
+"You need to enter either an existing account or the administrator." => "Du måste antingen ange ett befintligt konto eller administratör.",
+"Oracle connection could not be established" => "Oracle-anslutning kunde inte etableras",
+"MySQL username and/or password not valid" => "MySQL-användarnamnet och/eller lösenordet är felaktigt",
+"DB Error: \"%s\"" => "DB error: \"%s\"",
+"Offending command was: \"%s\"" => "Det felaktiga kommandot var: \"%s\"",
+"MySQL user '%s'@'localhost' exists already." => "MySQL-användaren '%s'@'localhost' existerar redan.",
+"Drop this user from MySQL" => "Radera denna användare från MySQL",
+"MySQL user '%s'@'%%' already exists" => "MySQl-användare '%s'@'%%' existerar redan",
+"Drop this user from MySQL." => "Radera denna användare från MySQL.",
+"Oracle username and/or password not valid" => "Oracle-användarnamnet och/eller lösenordet är felaktigt",
+"Offending command was: \"%s\", name: %s, password: %s" => "Det felande kommandot var: \"%s\", name: %s, password: %s",
+"MS SQL username and/or password not valid: %s" => "MS SQL-användaren och/eller lösenordet var inte giltigt: %s",
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Din webbserver är inte korrekt konfigurerad för att tillåta filsynkronisering eftersom WebDAV inte verkar fungera.",
"Please double check the <a href='%s'>installation guides</a>." => "Var god kontrollera <a href='%s'>installationsguiden</a>.",
"seconds ago" => "sekunder sedan",
diff --git a/lib/l10n/tr.php b/lib/l10n/tr.php
index 7996447b95d..2662d61649d 100644
--- a/lib/l10n/tr.php
+++ b/lib/l10n/tr.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s veritabanı sunucu adını tanımla",
"PostgreSQL username and/or password not valid" => "PostgreSQL adi kullanici ve/veya parola yasal degildir. ",
"You need to enter either an existing account or the administrator." => "Bir konto veya kullanici birlemek ihtiyacin. ",
+"Oracle connection could not be established" => "Oracle bağlantısı kurulamadı",
"MySQL username and/or password not valid" => "MySQL kullanıcı adı ve/veya parolası geçerli değil",
"DB Error: \"%s\"" => "DB Hata: ''%s''",
"Offending command was: \"%s\"" => "Komut rahasiz ''%s''. ",
diff --git a/lib/l10n/zh_CN.php b/lib/l10n/zh_CN.php
index 61e405d8058..edb0f81ee9d 100644
--- a/lib/l10n/zh_CN.php
+++ b/lib/l10n/zh_CN.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s 设置数据库所在主机。",
"PostgreSQL username and/or password not valid" => "PostgreSQL 数据库用户名和/或密码无效",
"You need to enter either an existing account or the administrator." => "你需要输入一个数据库中已有的账户或管理员账户。",
+"Oracle connection could not be established" => "不能建立甲骨文连接",
"MySQL username and/or password not valid" => "MySQL 数据库用户名和/或密码无效",
"DB Error: \"%s\"" => "数据库错误:\"%s\"",
"Offending command was: \"%s\"" => "冲突命令为:\"%s\"",
diff --git a/lib/l10n/zh_TW.php b/lib/l10n/zh_TW.php
index ec7310d4e4e..4e0d50e7fc9 100644
--- a/lib/l10n/zh_TW.php
+++ b/lib/l10n/zh_TW.php
@@ -24,6 +24,7 @@
"%s set the database host." => "%s 設定資料庫主機。",
"PostgreSQL username and/or password not valid" => "PostgreSQL 用戶名和/或密碼無效",
"You need to enter either an existing account or the administrator." => "您必須輸入一個現有的帳號或管理員帳號。",
+"Oracle connection could not be established" => "無法建立 Oracle 資料庫連線",
"MySQL username and/or password not valid" => "MySQL 用戶名和/或密碼無效",
"DB Error: \"%s\"" => "資料庫錯誤:\"%s\"",
"Offending command was: \"%s\"" => "有問題的指令是:\"%s\"",
diff --git a/lib/mail.php b/lib/mail.php
index 61634632efc..e15af277a64 100644
--- a/lib/mail.php
+++ b/lib/mail.php
@@ -113,7 +113,7 @@ class OC_Mail {
*/
public static function getfooter() {
- $txt="\n--\n";
+ $txt="\n-- \n";
$txt.="ownCloud\n";
$txt.="Your Cloud, Your Data, Your Way!\n";
return($txt);
diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php
index 601046fe691..cc076a3a845 100644
--- a/lib/public/backgroundjob.php
+++ b/lib/public/backgroundjob.php
@@ -1,49 +1,46 @@
<?php
/**
-* ownCloud
-*
-* @author Jakob Sack
-* @copyright 2012 Jakob Sack owncloud@jakobsack.de
-*
-* 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/>.
-*
-*/
+ * ownCloud
+ *
+ * @author Jakob Sack
+ * @copyright 2012 Jakob Sack owncloud@jakobsack.de
+ *
+ * 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/>.
+ *
+ */
/**
- * Public interface of ownCloud forbackground jobs.
+ * Public interface of ownCloud for background jobs.
*/
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP;
+use \OC\BackgroundJob\JobList;
+
/**
- * This class provides functions to manage backgroundjobs in ownCloud
- *
- * There are two kind of background jobs in ownCloud: regular tasks and
- * queued tasks.
+ * This class provides functions to register backgroundjobs in ownCloud
*
- * Regular tasks have to be registered in appinfo.php and
- * will run on a regular base. Fetching news could be a task that should run
- * frequently.
+ * To create a new backgroundjob create a new class that inharits from either \OC\BackgroundJob\Job,
+ * \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using
+ * \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function
+ * of the job when the job is executed.
*
- * Queued tasks have to be registered each time you want to execute them.
- * An example of the queued task would be the creation of the thumbnail. As
- * soon as the user uploads a picture the gallery app registers the queued
- * task "create thumbnail" and saves the path in the parameter instead of doing
- * the work right away. This makes the app more responsive. As soon as the task
- * is done it will be deleted from the list.
+ * A regular Job will be executed every time cron.php is run, a QueuedJob will only run once and a TimedJob
+ * will only run at a specific interval which is to be specified in the constructor of the job by calling
+ * $this->setInterval($interval) with $interval in seconds.
*/
class BackgroundJob {
/**
@@ -59,82 +56,136 @@ class BackgroundJob {
/**
* @brief sets the background jobs execution type
- * @param $type execution type
+ * @param string $type execution type
* @return boolean
*
* This method sets the execution type of the background jobs. Possible types
* are "none", "ajax", "webcron", "cron"
*/
- public static function setExecutionType( $type ) {
- return \OC_BackgroundJob::setExecutionType( $type );
+ public static function setExecutionType($type) {
+ return \OC_BackgroundJob::setExecutionType($type);
+ }
+
+ /**
+ * @param \OC\BackgroundJob\Job|string $job
+ * @param mixed $argument
+ */
+ public static function registerJob($job, $argument = null) {
+ $jobList = new JobList();
+ $jobList->add($job, $argument);
}
/**
+ * @deprecated
* @brief creates a regular task
- * @param $klass class name
- * @param $method method name
+ * @param string $klass class name
+ * @param string $method method name
* @return true
*/
- public static function addRegularTask( $klass, $method ) {
- return \OC_BackgroundJob_RegularTask::register( $klass, $method );
+ public static function addRegularTask($klass, $method) {
+ self::registerJob('OC\BackgroundJob\Legacy\RegularJob', array($klass, $method));
+ return true;
}
/**
+ * @deprecated
* @brief gets all regular tasks
* @return associative array
*
* key is string "$klass-$method", value is array( $klass, $method )
*/
static public function allRegularTasks() {
- return \OC_BackgroundJob_RegularTask::all();
+ $jobList = new JobList();
+ $allJobs = $jobList->getAll();
+ $regularJobs = array();
+ foreach ($allJobs as $job) {
+ if ($job instanceof RegularLegacyJob) {
+ $key = implode('-', $job->getArgument());
+ $regularJobs[$key] = $job->getArgument();
+ }
+ }
+ return $regularJobs;
}
/**
+ * @deprecated
* @brief Gets one queued task
- * @param $id ID of the task
+ * @param int $id ID of the task
* @return associative array
*/
- public static function findQueuedTask( $id ) {
- return \OC_BackgroundJob_QueuedTask::find( $id );
+ public static function findQueuedTask($id) {
+ $jobList = new JobList();
+ return $jobList->getById($id);
}
/**
+ * @deprecated
* @brief Gets all queued tasks
* @return array with associative arrays
*/
public static function allQueuedTasks() {
- return \OC_BackgroundJob_QueuedTask::all();
+ $jobList = new JobList();
+ $allJobs = $jobList->getAll();
+ $queuedJobs = array();
+ foreach ($allJobs as $job) {
+ if ($job instanceof QueuedLegacyJob) {
+ $queuedJob = $job->getArgument();
+ $queuedJob['id'] = $job->getId();
+ $queuedJobs[] = $queuedJob;
+ }
+ }
+ return $queuedJobs;
}
/**
+ * @deprecated
* @brief Gets all queued tasks of a specific app
- * @param $app app name
+ * @param string $app app name
* @return array with associative arrays
*/
- public static function queuedTaskWhereAppIs( $app ) {
- return \OC_BackgroundJob_QueuedTask::whereAppIs( $app );
+ public static function queuedTaskWhereAppIs($app) {
+ $jobList = new JobList();
+ $allJobs = $jobList->getAll();
+ $queuedJobs = array();
+ foreach ($allJobs as $job) {
+ if ($job instanceof QueuedLegacyJob) {
+ $queuedJob = $job->getArgument();
+ $queuedJob['id'] = $job->getId();
+ if ($queuedJob['app'] === $app) {
+ $queuedJobs[] = $queuedJob;
+ }
+ }
+ }
+ return $queuedJobs;
}
/**
+ * @deprecated
* @brief queues a task
- * @param $app app name
- * @param $klass class name
- * @param $method method name
- * @param $parameters all useful data as text
- * @return id of task
+ * @param string $app app name
+ * @param string $class class name
+ * @param string $method method name
+ * @param string $parameters all useful data as text
+ * @return int id of task
*/
- public static function addQueuedTask( $app, $klass, $method, $parameters ) {
- return \OC_BackgroundJob_QueuedTask::add( $app, $klass, $method, $parameters );
+ public static function addQueuedTask($app, $class, $method, $parameters) {
+ self::registerJob('OC\BackgroundJob\Legacy\QueuedJob', array('app' => $app, 'klass' => $class, 'method' => $method, 'parameters' => $parameters));
+ return true;
}
/**
+ * @deprecated
* @brief deletes a queued task
- * @param $id id of task
- * @return true/false
+ * @param int $id id of task
+ * @return bool
*
* Deletes a report
*/
- public static function deleteQueuedTask( $id ) {
- return \OC_BackgroundJob_QueuedTask::delete( $id );
+ public static function deleteQueuedTask($id) {
+ $jobList = new JobList();
+ $job = $jobList->getById($id);
+ if ($job) {
+ $jobList->remove($job);
+ }
}
}
diff --git a/lib/public/share.php b/lib/public/share.php
index 03d662676c6..122ab3fa030 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -123,85 +123,99 @@ class Share {
return $path;
}
-
+
/**
* @brief Find which users can access a shared item
* @param $path to the file
* @param $user owner of the file
* @param include owner to the list of users with access to the file
* @return array
- * @note $path needs to be relative to user data dir, e.g. 'file.txt'
+ * @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
*/
- public static function getUsersSharingFile($path, $user, $includeOwner = false, $removeDuplicates = true) {
+ public static function getUsersSharingFile($path, $user, $includeOwner = false) {
- $path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
- $path = '';
$shares = array();
$publicShare = false;
+ $source = -1;
+ $cache = false;
+
$view = new \OC\Files\View('/' . $user . '/files/');
- foreach ($path_parts as $p) {
- $path .= '/' . $p;
- $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path));
+ $meta = $view->getFileInfo(\OC\Files\Filesystem::normalizePath($path));
+
+ if($meta !== false) {
$source = $meta['fileid'];
+ $cache = new \OC\Files\Cache\Cache($meta['storage']);
+ }
+
+ while ($source !== -1) {
// Fetch all shares of this file path from DB
$query = \OC_DB::prepare(
- 'SELECT share_with
+ 'SELECT `share_with`
FROM
`*PREFIX*share`
WHERE
- item_source = ? AND share_type = ?'
+ `item_source` = ? AND `share_type` = ?'
);
$result = $query->execute(array($source, self::SHARE_TYPE_USER));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
- }
-
- while ($row = $result->fetchRow()) {
- $shares[] = $row['share_with'];
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ while ($row = $result->fetchRow()) {
+ $shares[] = $row['share_with'];
+ }
}
-
// We also need to take group shares into account
$query = \OC_DB::prepare(
- 'SELECT share_with
+ 'SELECT `share_with`
FROM
`*PREFIX*share`
WHERE
- item_source = ? AND share_type = ?'
+ `item_source` = ? AND `share_type` = ?'
);
$result = $query->execute(array($source, self::SHARE_TYPE_GROUP));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
- }
-
- while ($row = $result->fetchRow()) {
- $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
- $shares = array_merge($shares, $usersInGroup);
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ while ($row = $result->fetchRow()) {
+ $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
+ $shares = array_merge($shares, $usersInGroup);
+ }
}
//check for public link shares
- $query = \OC_DB::prepare(
- 'SELECT share_with
- FROM
- `*PREFIX*share`
- WHERE
- item_source = ? AND share_type = ?'
- );
+ if (!$publicShare) {
+ $query = \OC_DB::prepare(
+ 'SELECT `share_with`
+ FROM
+ `*PREFIX*share`
+ WHERE
+ `item_source` = ? AND `share_type` = ?'
+ );
- $result = $query->execute(array($source, self::SHARE_TYPE_LINK));
+ $result = $query->execute(array($source, self::SHARE_TYPE_LINK));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ if ($result->fetchRow()) {
+ $publicShare = true;
+ }
+ }
}
-
- if ($result->fetchRow()) {
- $publicShare = true;
+
+ // let's get the parent for the next round
+ $meta = $cache->get((int)$source);
+ if($meta !== false) {
+ $source = (int)$meta['parent'];
+ } else {
+ $source = -1;
}
}
// Include owner in list of users, if requested
@@ -995,7 +1009,7 @@ class Share {
if (!isset($mounts[$row['storage']])) {
$mountPoints = \OC\Files\Filesystem::getMountByNumericId($row['storage']);
if (is_array($mountPoints)) {
- $mounts[$row['storage']] = $mountPoints[key($mountPoints)];
+ $mounts[$row['storage']] = current($mountPoints);
}
}
if ($mounts[$row['storage']]) {
@@ -1572,10 +1586,10 @@ class Share {
public static function post_removeFromGroup($arguments) {
// TODO Don't call if user deleted?
- $query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share`'
- .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)');
- $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique,
- $arguments['uid']));
+ $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
+ .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
+ $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
+ self::$shareTypeGroupUserUnique, $arguments['uid']));
while ($item = $result->fetchRow()) {
if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
// Delete all reshares by this user of the group share
@@ -1587,8 +1601,8 @@ class Share {
}
public static function post_deleteGroup($arguments) {
- $query = \OC_DB::prepare('SELECT id FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
- $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
+ $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
+ $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid']));
while ($item = $result->fetchRow()) {
self::delete($item['id']);
}
diff --git a/lib/response.php b/lib/response.php
index 49d79fda709..674176d078b 100644
--- a/lib/response.php
+++ b/lib/response.php
@@ -11,6 +11,7 @@ class OC_Response {
const STATUS_NOT_MODIFIED = 304;
const STATUS_TEMPORARY_REDIRECT = 307;
const STATUS_NOT_FOUND = 404;
+ const STATUS_INTERNAL_SERVER_ERROR = 500;
/**
* @brief Enable response caching by sending correct HTTP headers
@@ -70,6 +71,9 @@ class OC_Response {
case self::STATUS_NOT_FOUND;
$status = $status . ' Not Found';
break;
+ case self::STATUS_INTERNAL_SERVER_ERROR;
+ $status = $status . ' Internal Server Error';
+ break;
}
header($protocol.' '.$status);
}
diff --git a/lib/session/internal.php b/lib/session/internal.php
new file mode 100644
index 00000000000..60aecccc8aa
--- /dev/null
+++ b/lib/session/internal.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Session;
+
+/**
+ * Class Internal
+ *
+ * wrap php's internal session handling into the Session interface
+ *
+ * @package OC\Session
+ */
+class Internal extends Memory {
+ public function __construct($name) {
+ session_name($name);
+ session_start();
+ if (!isset($_SESSION)) {
+ throw new \Exception('Failed to start session');
+ }
+ $this->data = $_SESSION;
+ }
+
+ public function __destruct() {
+ $_SESSION = $this->data;
+ session_write_close();
+ }
+
+ public function clear() {
+ session_unset();
+ @session_regenerate_id(true);
+ @session_start();
+ $this->data = $_SESSION = array();
+ }
+}
diff --git a/lib/session/memory.php b/lib/session/memory.php
new file mode 100644
index 00000000000..c148ff4b9b9
--- /dev/null
+++ b/lib/session/memory.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Session;
+
+/**
+ * Class Internal
+ *
+ * store session data in an in-memory array, not persistance
+ *
+ * @package OC\Session
+ */
+class Memory extends Session {
+ protected $data;
+
+ public function __construct($name) {
+ //no need to use $name since all data is already scoped to this instance
+ $this->data = array();
+ }
+
+ /**
+ * @param string $key
+ * @param mixed $value
+ */
+ public function set($key, $value) {
+ $this->data[$key] = $value;
+ }
+
+ /**
+ * @param string $key
+ * @return mixed
+ */
+ public function get($key) {
+ if (!$this->exists($key)) {
+ return null;
+ }
+ return $this->data[$key];
+ }
+
+ /**
+ * @param string $key
+ * @return bool
+ */
+ public function exists($key) {
+ return isset($this->data[$key]);
+ }
+
+ /**
+ * @param string $key
+ */
+ public function remove($key) {
+ unset($this->data[$key]);
+ }
+
+ public function clear() {
+ $this->data = array();
+ }
+}
diff --git a/lib/session/session.php b/lib/session/session.php
new file mode 100644
index 00000000000..55515f57a87
--- /dev/null
+++ b/lib/session/session.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Session;
+
+abstract class Session implements \ArrayAccess {
+ /**
+ * $name serves as a namespace for the session keys
+ *
+ * @param string $name
+ */
+ abstract public function __construct($name);
+
+ /**
+ * @param string $key
+ * @param mixed $value
+ */
+ abstract public function set($key, $value);
+
+ /**
+ * @param string $key
+ * @return mixed should return null if $key does not exist
+ */
+ abstract public function get($key);
+
+ /**
+ * @param string $key
+ * @return bool
+ */
+ abstract public function exists($key);
+
+ /**
+ * should not throw any errors if $key does not exist
+ *
+ * @param string $key
+ */
+ abstract public function remove($key);
+
+ /**
+ * removes all entries within the cache namespace
+ */
+ abstract public function clear();
+
+ /**
+ * @param mixed $offset
+ * @return bool
+ */
+ public function offsetExists($offset) {
+ return $this->exists($offset);
+ }
+
+ /**
+ * @param mixed $offset
+ * @return mixed
+ */
+ public function offsetGet($offset) {
+ return $this->get($offset);
+ }
+
+ /**
+ * @param mixed $offset
+ * @param mixed $value
+ */
+ public function offsetSet($offset, $value) {
+ $this->set($offset, $value);
+ }
+
+ /**
+ * @param mixed $offset
+ */
+ public function offsetUnset($offset) {
+ $this->remove($offset);
+ }
+}
diff --git a/lib/setup.php b/lib/setup.php
index c7e9fc0c521..66dd51dcad3 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -4,7 +4,7 @@ class DatabaseSetupException extends Exception
{
private $hint;
- public function __construct($message, $hint, $code = 0, Exception $previous = null) {
+ public function __construct($message, $hint = '', $code = 0, Exception $previous = null) {
$this->hint = $hint;
parent::__construct($message, $code, $previous);
}
@@ -106,12 +106,6 @@ class OC_Setup {
'hint' => $e->getHint()
);
return($error);
- } catch (Exception $e) {
- $error[] = array(
- 'error' => $e->getMessage(),
- 'hint' => ''
- );
- return($error);
}
}
elseif($dbtype == 'pgsql') {
@@ -127,7 +121,7 @@ class OC_Setup {
try {
self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
- } catch (Exception $e) {
+ } catch (DatabaseSetupException $e) {
$error[] = array(
'error' => $l->t('PostgreSQL username and/or password not valid'),
'hint' => $l->t('You need to enter either an existing account or the administrator.')
@@ -139,18 +133,21 @@ class OC_Setup {
$dbuser = $options['dbuser'];
$dbpass = $options['dbpass'];
$dbname = $options['dbname'];
- $dbtablespace = $options['dbtablespace'];
+ if (array_key_exists('dbtablespace', $options)) {
+ $dbtablespace = $options['dbtablespace'];
+ } else {
+ $dbtablespace = 'USERS';
+ }
$dbhost = isset($options['dbhost'])?$options['dbhost']:'';
$dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
OC_Config::setValue('dbname', $dbname);
- OC_Config::setValue('dbtablespace', $dbtablespace);
OC_Config::setValue('dbhost', $dbhost);
OC_Config::setValue('dbtableprefix', $dbtableprefix);
try {
self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
- } catch (Exception $e) {
+ } catch (DatabaseSetupException $e) {
$error[] = array(
'error' => $l->t('Oracle connection could not be established'),
'hint' => $e->getMessage().' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
@@ -177,7 +174,7 @@ class OC_Setup {
try {
self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix);
- } catch (Exception $e) {
+ } catch (DatabaseSetupException $e) {
$error[] = array(
'error' => 'MS SQL username and/or password not valid',
'hint' => 'You need to enter either an existing account or the administrator.'
@@ -326,7 +323,13 @@ class OC_Setup {
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
$connection = @pg_connect($connection_string);
if(!$connection) {
- throw new Exception($l->t('PostgreSQL username and/or password not valid'));
+ // Try if we can connect to the DB with the specified name
+ $e_dbname = addslashes($dbname);
+ $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
+ $connection = @pg_connect($connection_string);
+
+ if(!$connection)
+ throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
}
$e_user = pg_escape_string($dbuser);
//check for roles creation rights in postgresql
@@ -371,7 +374,7 @@ class OC_Setup {
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
$connection = @pg_connect($connection_string);
if(!$connection) {
- throw new Exception($l->t('PostgreSQL username and/or password not valid'));
+ throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
}
$query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
$result = pg_query($connection, $query);
@@ -446,7 +449,7 @@ class OC_Setup {
}
private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace,
- $username) {
+ $username) {
$l = self::getTrans();
$e_host = addslashes($dbhost);
$e_dbname = addslashes($dbname);
@@ -461,9 +464,9 @@ class OC_Setup {
if(!$connection) {
$e = oci_error();
if (is_array ($e) && isset ($e['message'])) {
- throw new Exception($e['message']);
+ throw new DatabaseSetupException($e['message']);
}
- throw new Exception($l->t('Oracle username and/or password not valid'));
+ throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
}
//check for roles creation rights in oracle
@@ -530,7 +533,7 @@ class OC_Setup {
}
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
if(!$connection) {
- throw new Exception($l->t('Oracle username and/or password not valid'));
+ throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
}
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
$stmt = oci_parse($connection, $query);
@@ -641,7 +644,7 @@ class OC_Setup {
} else {
$entry = '';
}
- throw new Exception($l->t('MS SQL username and/or password not valid: %s', array($entry)));
+ throw new DatabaseSetupException($l->t('MS SQL username and/or password not valid: %s', array($entry)));
}
OC_Config::setValue('dbuser', $dbuser);
diff --git a/lib/template.php b/lib/template.php
index 2f535335648..ae9ea187445 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -246,14 +246,14 @@ class OC_Template{
// if the formfactor is not yet autodetected do the
// autodetection now. For possible formfactors check the
// detectFormfactor documentation
- if(!isset($_SESSION['formfactor'])) {
- $_SESSION['formfactor'] = self::detectFormfactor();
+ if (!\OC::$session->exists('formfactor')) {
+ \OC::$session->set('formfactor', self::detectFormfactor());
}
// allow manual override via GET parameter
if(isset($_GET['formfactor'])) {
- $_SESSION['formfactor']=$_GET['formfactor'];
+ \OC::$session->set('formfactor', $_GET['formfactor']);
}
- $formfactor=$_SESSION['formfactor'];
+ $formfactor = \OC::$session->get('formfactor');
if($formfactor=='default') {
$fext='';
}elseif($formfactor=='mobile') {
@@ -535,4 +535,25 @@ class OC_Template{
$content->printPage();
die();
}
+
+ /**
+ * print error page using Exception details
+ * @param Exception $exception
+ */
+
+ public static function printExceptionErrorPage(Exception $exception) {
+ $error_msg = $exception->getMessage();
+ if ($exception->getCode()) {
+ $error_msg = '['.$exception->getCode().'] '.$error_msg;
+ }
+ $hint = $exception->getTraceAsString();
+ while (method_exists($exception,'previous') && $exception = $exception->previous()) {
+ $error_msg .= '<br/>Caused by: ';
+ if ($exception->getCode()) {
+ $error_msg .= '['.$exception->getCode().'] ';
+ }
+ $error_msg .= $exception->getMessage();
+ };
+ self::printErrorPage($error_msg, $hint);
+ }
}
diff --git a/lib/user.php b/lib/user.php
index 26fe73f8bfe..830f13bb8df 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -30,35 +30,85 @@
* post_createUser(uid, password)
* pre_deleteUser(&run, uid)
* post_deleteUser(uid)
- * pre_setPassword(&run, uid, password)
- * post_setPassword(uid, password)
+ * pre_setPassword(&run, uid, password, recoveryPassword)
+ * post_setPassword(uid, password, recoveryPassword)
* pre_login(&run, uid, password)
* post_login(uid)
* logout()
*/
class OC_User {
- // The backend used for user management
- private static $_usedBackends = array();
+ public static $userSession = null;
+
+ private static function getUserSession() {
+ if (!self::$userSession) {
+ $manager = new \OC\User\Manager();
+ self::$userSession = new \OC\User\Session($manager, \OC::$session);
+ self::$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
+ \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
+ });
+ self::$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
+ /** @var $user \OC\User\User */
+ \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
+ });
+ self::$userSession->listen('\OC\User', 'preDelete', function ($user) {
+ /** @var $user \OC\User\User */
+ \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
+ });
+ self::$userSession->listen('\OC\User', 'postDelete', function ($user) {
+ /** @var $user \OC\User\User */
+ \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
+ });
+ self::$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
+ /** @var $user \OC\User\User */
+ OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
+ });
+ self::$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
+ /** @var $user \OC\User\User */
+ OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
+ });
+ self::$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
+ \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
+ });
+ self::$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
+ /** @var $user \OC\User\User */
+ \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
+ });
+ self::$userSession->listen('\OC\User', 'logout', function () {
+ \OC_Hook::emit('OC_User', 'logout', array());
+ });
+ }
+ return self::$userSession;
+ }
- private static $_setupedBackends = array();
+ /**
+ * @return \OC\User\Manager
+ */
+ private static function getManager() {
+ return self::getUserSession()->getManager();
+ }
- // Backends available (except database)
private static $_backends = array();
+ private static $_usedBackends = array();
+
+ private static $_setupedBackends = array();
+
/**
* @brief registers backend
- * @param $name name of the backend
- * @returns true/false
+ * @param string $backend name of the backend
+ * @deprecated Add classes by calling useBackend with a class instance instead
+ * @return bool
*
* Makes a list of backends that can be used by other modules
*/
- public static function registerBackend( $backend ) {
+ public static function registerBackend($backend) {
self::$_backends[] = $backend;
return true;
}
/**
* @brief gets available backends
+ * @deprecated
* @returns array of backends
*
* Returns the names of all backends.
@@ -69,6 +119,7 @@ class OC_User {
/**
* @brief gets used backends
+ * @deprecated
* @returns array of backends
*
* Returns the names of all used backends.
@@ -79,33 +130,36 @@ class OC_User {
/**
* @brief Adds the backend to the list of used backends
- * @param $backend default: database The backend to use for user managment
- * @returns true/false
+ * @param string | OC_User_Backend $backend default: database The backend to use for user management
+ * @return bool
*
* Set the User Authentication Module
*/
- public static function useBackend( $backend = 'database' ) {
- if($backend instanceof OC_User_Interface) {
- OC_Log::write('core', 'Adding user backend instance of '.get_class($backend).'.', OC_Log::DEBUG);
- self::$_usedBackends[get_class($backend)]=$backend;
+ public static function useBackend($backend = 'database') {
+ if ($backend instanceof OC_User_Interface) {
+ OC_Log::write('core', 'Adding user backend instance of ' . get_class($backend) . '.', OC_Log::DEBUG);
+ self::$_usedBackends[get_class($backend)] = $backend;
+ self::getManager()->registerBackend($backend);
} else {
// You'll never know what happens
- if( null === $backend OR !is_string( $backend )) {
+ if (null === $backend OR !is_string($backend)) {
$backend = 'database';
}
// Load backend
- switch( $backend ) {
+ switch ($backend) {
case 'database':
case 'mysql':
case 'sqlite':
- OC_Log::write('core', 'Adding user backend '.$backend.'.', OC_Log::DEBUG);
+ OC_Log::write('core', 'Adding user backend ' . $backend . '.', OC_Log::DEBUG);
self::$_usedBackends[$backend] = new OC_User_Database();
+ self::getManager()->registerBackend(self::$_usedBackends[$backend]);
break;
default:
- OC_Log::write('core', 'Adding default user backend '.$backend.'.', OC_Log::DEBUG);
+ OC_Log::write('core', 'Adding default user backend ' . $backend . '.', OC_Log::DEBUG);
$className = 'OC_USER_' . strToUpper($backend);
self::$_usedBackends[$backend] = new $className();
+ self::getManager()->registerBackend(self::$_usedBackends[$backend]);
break;
}
}
@@ -116,121 +170,73 @@ class OC_User {
* remove all used backends
*/
public static function clearBackends() {
- self::$_usedBackends=array();
+ self::$_usedBackends = array();
+ self::getManager()->clearBackends();
}
/**
* setup the configured backends in config.php
*/
public static function setupBackends() {
- $backends=OC_Config::getValue('user_backends', array());
- foreach($backends as $i=>$config) {
- $class=$config['class'];
- $arguments=$config['arguments'];
- if(class_exists($class)) {
- if(array_search($i, self::$_setupedBackends)===false) {
+ $backends = OC_Config::getValue('user_backends', array());
+ foreach ($backends as $i => $config) {
+ $class = $config['class'];
+ $arguments = $config['arguments'];
+ if (class_exists($class)) {
+ if (array_search($i, self::$_setupedBackends) === false) {
// make a reflection object
$reflectionObj = new ReflectionClass($class);
// use Reflection to create a new instance, using the $args
$backend = $reflectionObj->newInstanceArgs($arguments);
self::useBackend($backend);
- $_setupedBackends[]=$i;
+ self::$_setupedBackends[] = $i;
} else {
- OC_Log::write('core', 'User backend '.$class.' already initialized.', OC_Log::DEBUG);
+ OC_Log::write('core', 'User backend ' . $class . ' already initialized.', OC_Log::DEBUG);
}
} else {
- OC_Log::write('core', 'User backend '.$class.' not found.', OC_Log::ERROR);
+ OC_Log::write('core', 'User backend ' . $class . ' not found.', OC_Log::ERROR);
}
}
}
/**
* @brief Create a new user
- * @param $uid The username of the user to create
- * @param $password The password of the new user
- * @returns true/false
+ * @param string $uid The username of the user to create
+ * @param string $password The password of the new user
+ * @throws Exception
+ * @return bool true/false
*
* Creates a new user. Basic checking of username is done in OC_User
* itself, not in its subclasses.
*
* Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-"
*/
- public static function createUser( $uid, $password ) {
- // Check the name for bad characters
- // Allowed are: "a-z", "A-Z", "0-9" and "_.@-"
- if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $uid )) {
- throw new Exception('Only the following characters are allowed in a username:'
- .' "a-z", "A-Z", "0-9", and "_.@-"');
- }
- // No empty username
- if(trim($uid) == '') {
- throw new Exception('A valid username must be provided');
- }
- // No empty password
- if(trim($password) == '') {
- throw new Exception('A valid password must be provided');
- }
-
- // Check if user already exists
- if( self::userExistsForCreation($uid) ) {
- throw new Exception('The username is already being used');
- }
-
-
- $run = true;
- OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password ));
-
- if( $run ) {
- //create the user in the first backend that supports creating users
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->implementsActions(OC_USER_BACKEND_CREATE_USER))
- continue;
-
- $backend->createUser($uid, $password);
- OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => $uid, "password" => $password ));
-
- return self::userExists($uid);
- }
- }
- return false;
+ public static function createUser($uid, $password) {
+ return self::getManager()->createUser($uid, $password);
}
/**
* @brief delete a user
- * @param $uid The username of the user to delete
- * @returns true/false
+ * @param string $uid The username of the user to delete
+ * @return bool
*
* Deletes a user
*/
- public static function deleteUser( $uid ) {
- $run = true;
- OC_Hook::emit( "OC_User", "pre_deleteUser", array( "run" => &$run, "uid" => $uid ));
-
- if( $run ) {
- //delete the user from all backends
- foreach(self::$_usedBackends as $backend) {
- $backend->deleteUser($uid);
- }
- if (self::userExists($uid)) {
- return false;
- }
+ public static function deleteUser($uid) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ $user->delete();
+
// We have to delete the user from all groups
- foreach( OC_Group::getUserGroups( $uid ) as $i ) {
- OC_Group::removeFromGroup( $uid, $i );
+ foreach (OC_Group::getUserGroups($uid) as $i) {
+ OC_Group::removeFromGroup($uid, $i);
}
// Delete the user's keys in preferences
OC_Preferences::deleteUser($uid);
// Delete user files in /data/
- OC_Helper::rmdirr(OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/'.$uid.'/');
-
- // Emit and exit
- OC_Hook::emit( "OC_User", "post_deleteUser", array( "uid" => $uid ));
- return true;
- }
- else{
- return false;
+ OC_Helper::rmdirr(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid . '/');
}
}
@@ -238,75 +244,34 @@ class OC_User {
* @brief Try to login a user
* @param $uid The username of the user to log in
* @param $password The password of the user
- * @returns true/false
+ * @return bool
*
* Log in a user and regenerate a new session - if the password is ok
*/
- public static function login( $uid, $password ) {
- $run = true;
- OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid, "password" => $password));
-
- if( $run ) {
- $uid = self::checkPassword( $uid, $password );
- $enabled = self::isEnabled($uid);
- if($uid && $enabled) {
- session_regenerate_id(true);
- self::setUserId($uid);
- self::setDisplayName($uid);
- OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
- return true;
- }
- }
- return false;
+ public static function login($uid, $password) {
+ return self::getUserSession()->login($uid, $password);
}
/**
* @brief Sets user id for session and triggers emit
*/
public static function setUserId($uid) {
- $_SESSION['user_id'] = $uid;
+ OC::$session->set('user_id', $uid);
}
/**
* @brief Sets user display name for session
*/
public static function setDisplayName($uid, $displayName = null) {
- $result = false;
- if ($displayName ) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
- if($backend->userExists($uid)) {
- $result |= $backend->setDisplayName($uid, $displayName);
- }
- }
- }
- } else {
- $displayName = self::determineDisplayName($uid);
- $result = true;
- }
- if (OC_User::getUser() === $uid) {
- $_SESSION['display_name'] = $displayName;
+ if (is_null($displayName)) {
+ $displayName = $uid;
}
- return $result;
- }
-
-
- /**
- * @brief get display name
- * @param $uid The username
- * @returns string display name or uid if no display name is defined
- *
- */
- private static function determineDisplayName( $uid ) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
- $result=$backend->getDisplayName( $uid );
- if($result) {
- return $result;
- }
- }
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->setDisplayName($displayName);
+ } else {
+ return false;
}
- return $uid;
}
/**
@@ -315,36 +280,31 @@ class OC_User {
* Logout, destroys session
*/
public static function logout() {
- OC_Hook::emit( "OC_User", "logout", array());
- session_unset();
- session_destroy();
- OC_User::unsetMagicInCookie();
+ self::getUserSession()->logout();
}
/**
* @brief Check if the user is logged in
- * @returns true/false
+ * @returns bool
*
* Checks if the user is logged in
*/
public static function isLoggedIn() {
- if( isset($_SESSION['user_id']) AND $_SESSION['user_id']) {
+ if (\OC::$session->get('user_id')) {
OC_App::loadApps(array('authentication'));
self::setupBackends();
- if (self::userExists($_SESSION['user_id']) ) {
- return true;
- }
+ return self::userExists(\OC::$session->get('user_id'));
}
return false;
}
/**
* @brief Check if the user is an admin user
- * @param $uid uid of the admin
- * @returns bool
+ * @param string $uid uid of the admin
+ * @return bool
*/
public static function isAdminUser($uid) {
- if(OC_Group::inGroup($uid, 'admin' )) {
+ if (OC_Group::inGroup($uid, 'admin')) {
return true;
}
return false;
@@ -356,32 +316,40 @@ class OC_User {
* @return string uid or false
*/
public static function getUser() {
- if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) {
- return $_SESSION['user_id'];
- }
- else{
+ $uid = OC::$session->get('user_id');
+ if (!is_null($uid)) {
+ return $uid;
+ } else {
return false;
}
}
/**
* @brief get the display name of the user currently logged in.
+ * @param string $uid
* @return string uid or false
*/
- public static function getDisplayName($user=null) {
- if ( $user ) {
- return self::determineDisplayName($user);
- } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) {
- return $_SESSION['display_name'];
- }
- else{
- return false;
+ public static function getDisplayName($uid = null) {
+ if ($uid) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->getDisplayName();
+ } else {
+ return $uid;
+ }
+ } else {
+ $user = self::getUserSession()->getUser();
+ if ($user) {
+ return $user->getDisplayName();
+ } else {
+ return false;
+ }
}
}
/**
* @brief Autogenerate a password
- * @returns string
+ * @return string
*
* generates a password
*/
@@ -391,112 +359,89 @@ class OC_User {
/**
* @brief Set password
- * @param $uid The username
- * @param $password The new password
- * @param $recoveryPassword for the encryption app to reset encryption keys
- * @returns true/false
+ * @param string $uid The username
+ * @param string $password The new password
+ * @param string $recoveryPassword for the encryption app to reset encryption keys
+ * @return bool
*
* Change the password of a user
*/
- public static function setPassword( $uid, $password, $recoveryPassword = null ) {
- $run = true;
- OC_Hook::emit( "OC_User", "pre_setPassword", array( "run" => &$run, "uid" => $uid, "password" => $password, "recoveryPassword" => $recoveryPassword ));
-
- if( $run ) {
- $success = false;
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)) {
- if($backend->userExists($uid)) {
- $success |= $backend->setPassword($uid, $password);
- }
- }
- }
- // invalidate all login cookies
- OC_Preferences::deleteApp($uid, 'login_token');
- OC_Hook::emit( "OC_User", "post_setPassword", array( "uid" => $uid, "password" => $password, "recoveryPassword" => $recoveryPassword ));
- return $success;
- }
- else{
+ public static function setPassword($uid, $password, $recoveryPassword = null) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->setPassword($password, $recoveryPassword);
+ } else {
return false;
}
}
/**
* @brief Check whether user can change his password
- * @param $uid The username
- * @returns true/false
+ * @param string $uid The username
+ * @return bool
*
* Check whether a specified user can change his password
*/
public static function canUserChangePassword($uid) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)) {
- if($backend->userExists($uid)) {
- return true;
- }
- }
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->canChangePassword();
+ } else {
+ return false;
}
- return false;
}
/**
* @brief Check whether user can change his display name
- * @param $uid The username
- * @returns true/false
+ * @param string $uid The username
+ * @return bool
*
* Check whether a specified user can change his display name
*/
public static function canUserChangeDisplayName($uid) {
- if (OC_Config::getValue('allow_user_to_change_display_name', true)) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
- if($backend->userExists($uid)) {
- return true;
- }
- }
- }
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->canChangeDisplayName();
+ } else {
+ return false;
}
- return false;
}
/**
* @brief Check if the password is correct
- * @param $uid The username
- * @param $password The password
- * @returns string
+ * @param string $uid The username
+ * @param string $password The password
+ * @return bool
*
* Check if the password is correct without logging in the user
* returns the user id or false
*/
- public static function checkPassword( $uid, $password ) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_CHECK_PASSWORD)) {
- $result=$backend->checkPassword( $uid, $password );
- if($result) {
- return $result;
- }
+ public static function checkPassword($uid, $password) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ if ($user->checkPassword($password)) {
+ return $user->getUID();
+ } else {
+ return false;
}
+ } else {
+ return false;
}
}
/**
- * @brief Check if the password is correct
* @param string $uid The username
- * @param string $password The password
- * @returns string
+ * @return string
*
* returns the path to the users home directory
*/
public static function getHome($uid) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_USER_BACKEND_GET_HOME) && $backend->userExists($uid)) {
- $result=$backend->getHome($uid);
- if($result) {
- return $result;
- }
- }
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->getHome();
+ } else {
+ return OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
}
- return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $uid;
}
/**
@@ -506,152 +451,93 @@ class OC_User {
* Get a list of all users.
*/
public static function getUsers($search = '', $limit = null, $offset = null) {
- $users = array();
- foreach (self::$_usedBackends as $backend) {
- $backendUsers = $backend->getUsers($search, $limit, $offset);
- if (is_array($backendUsers)) {
- $users = array_merge($users, $backendUsers);
- }
+ $users = self::getManager()->search($search, $limit, $offset);
+ $uids = array();
+ foreach ($users as $user) {
+ $uids[] = $user->getUID();
}
- asort($users);
- return $users;
+ return $uids;
}
/**
* @brief Get a list of all users display name
- * @returns associative array with all display names (value) and corresponding uids (key)
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array associative array with all display names (value) and corresponding uids (key)
*
* Get a list of all display names and user ids.
*/
public static function getDisplayNames($search = '', $limit = null, $offset = null) {
$displayNames = array();
- foreach (self::$_usedBackends as $backend) {
- $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset);
- if (is_array($backendDisplayNames)) {
- $displayNames = $displayNames + $backendDisplayNames;
- }
+ $users = self::getManager()->searchDisplayName($search, $limit, $offset);
+ foreach ($users as $user) {
+ $displayNames[$user->getUID()] = $user->getDisplayName();
}
- asort($displayNames);
return $displayNames;
}
/**
* @brief check if a user exists
* @param string $uid the username
- * @param string $excludingBackend (default none)
* @return boolean
*/
- public static function userExists($uid, $excludingBackend=null) {
- foreach(self::$_usedBackends as $backend) {
- if (!is_null($excludingBackend) && !strcmp(get_class($backend), $excludingBackend)) {
- OC_Log::write('OC_User', $excludingBackend . 'excluded from user existance check.', OC_Log::DEBUG);
- continue;
- }
- $result=$backend->userExists($uid);
- if($result===true) {
- return true;
- }
- }
- return false;
+ public static function userExists($uid) {
+ return self::getManager()->userExists($uid);
}
- public static function userExistsForCreation($uid) {
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->hasUserListings())
- continue;
-
- $result=$backend->userExists($uid);
- if($result===true) {
- return true;
- }
- }
- return false;
- }
-
/**
* disables a user
- * @param string $userid the user to disable
+ *
+ * @param string $uid the user to disable
*/
- public static function disableUser($userid) {
- $sql = "INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)";
- $stmt = OC_DB::prepare($sql);
- if ( ! OC_DB::isError($stmt) ) {
- $result = $stmt->execute(array($userid, 'core', 'enabled', 'false'));
- if ( OC_DB::isError($result) ) {
- OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($result), OC_Log::ERROR);
- }
- } else {
- OC_Log::write('OC_User', 'could not disable user: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR);
+ public static function disableUser($uid) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ $user->setEnabled(false);
}
}
/**
* enable a user
- * @param string $userid
+ *
+ * @param string $uid
*/
- public static function enableUser($userid) {
- $sql = 'DELETE FROM `*PREFIX*preferences`'
- ." WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?";
- $stmt = OC_DB::prepare($sql);
- if ( ! OC_DB::isError($stmt) ) {
- $result = $stmt->execute(array($userid, 'core', 'enabled', 'false'));
- if ( OC_DB::isError($result) ) {
- OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($result), OC_Log::ERROR);
- }
- } else {
- OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR);
+ public static function enableUser($uid) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ $user->setEnabled(true);
}
}
/**
* checks if a user is enabled
- * @param string $userid
+ *
+ * @param string $uid
* @return bool
*/
- public static function isEnabled($userid) {
- $sql = 'SELECT `userid` FROM `*PREFIX*preferences`'
- .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?';
- if (OC_Config::getValue( 'dbtype', 'sqlite' ) === 'oci') { //FIXME oracle hack
- $sql = 'SELECT `userid` FROM `*PREFIX*preferences`'
- .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND to_char(`configvalue`) = ?';
- }
- $stmt = OC_DB::prepare($sql);
- if ( ! OC_DB::isError($stmt) ) {
- $result = $stmt->execute(array($userid, 'core', 'enabled', 'false'));
- if ( ! OC_DB::isError($result) ) {
- return $result->numRows() ? false : true;
- } else {
- OC_Log::write('OC_User',
- 'could not check if enabled: '. OC_DB::getErrorMessage($result),
- OC_Log::ERROR);
- }
+ public static function isEnabled($uid) {
+ $user = self::getManager()->get($uid);
+ if ($user) {
+ return $user->isEnabled();
} else {
- OC_Log::write('OC_User', 'could not check if enabled: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR);
+ return false;
}
- return false;
}
/**
* @brief Set cookie value to use in next page load
* @param string $username username to be set
+ * @param string $token
*/
public static function setMagicInCookie($username, $token) {
- $secure_cookie = OC_Config::getValue("forcessl", false);
- $expires = time() + OC_Config::getValue('remember_login_cookie_lifetime', 60*60*24*15);
- setcookie("oc_username", $username, $expires, OC::$WEBROOT, '', $secure_cookie);
- setcookie("oc_token", $token, $expires, OC::$WEBROOT, '', $secure_cookie, true);
- setcookie("oc_remember_login", true, $expires, OC::$WEBROOT, '', $secure_cookie);
+ self::getUserSession()->setMagicInCookie($username, $token);
}
/**
* @brief Remove cookie for "remember username"
*/
public static function unsetMagicInCookie() {
- unset($_COOKIE["oc_username"]);
- unset($_COOKIE["oc_token"]);
- unset($_COOKIE["oc_remember_login"]);
- setcookie("oc_username", null, -1);
- setcookie("oc_token", null, -1);
- setcookie("oc_remember_login", null, -1);
+ self::getUserSession()->unsetMagicInCookie();
}
}
diff --git a/lib/user/backend.php b/lib/user/backend.php
index 93e8f17ca98..e9be08e429c 100644
--- a/lib/user/backend.php
+++ b/lib/user/backend.php
@@ -58,7 +58,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
/**
* @brief Get all supported actions
- * @returns bitwise-or'ed actions
+ * @return int bitwise-or'ed actions
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
@@ -76,8 +76,8 @@ abstract class OC_User_Backend implements OC_User_Interface {
/**
* @brief Check if backend implements actions
- * @param $actions bitwise-or'ed actions
- * @returns boolean
+ * @param int $actions bitwise-or'ed actions
+ * @return boolean
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
@@ -87,12 +87,12 @@ abstract class OC_User_Backend implements OC_User_Interface {
}
/**
- * @brief delete a user
- * @param $uid The username of the user to delete
- * @returns true/false
- *
- * Deletes a user
- */
+ * @brief delete a user
+ * @param string $uid The username of the user to delete
+ * @return bool
+ *
+ * Deletes a user
+ */
public function deleteUser( $uid ) {
return false;
}
@@ -127,8 +127,8 @@ abstract class OC_User_Backend implements OC_User_Interface {
/**
* @brief get display name of the user
- * @param $uid user ID of the user
- * @return display name
+ * @param string $uid user ID of the user
+ * @return string display name
*/
public function getDisplayName($uid) {
return $uid;
diff --git a/lib/user/database.php b/lib/user/database.php
index d70b620f2ab..9f00a022d9f 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -85,7 +85,7 @@ class OC_User_Database extends OC_User_Backend {
*/
public function deleteUser( $uid ) {
// Delete user-group-relation
- $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*users` WHERE uid = ?' );
+ $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*users` WHERE `uid` = ?' );
$query->execute( array( $uid ));
return true;
}
diff --git a/lib/user/dummy.php b/lib/user/dummy.php
index d63f60efbeb..b5b7a6c3c7a 100644
--- a/lib/user/dummy.php
+++ b/lib/user/dummy.php
@@ -1,114 +1,118 @@
<?php
/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
-*
-*/
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @copyright 2012 Frank Karlitschek frank@owncloud.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/>.
+ *
+ */
/**
* dummy user backend, does not keep state, only for testing use
*/
class OC_User_Dummy extends OC_User_Backend {
- private $users=array();
+ private $users = array();
+
/**
- * @brief Create a new user
- * @param $uid The username of the user to create
- * @param $password The password of the new user
- * @returns true/false
- *
- * Creates a new user. Basic checking of username is done in OC_User
- * itself, not in its subclasses.
- */
+ * @brief Create a new user
+ * @param string $uid The username of the user to create
+ * @param string $password The password of the new user
+ * @return bool
+ *
+ * Creates a new user. Basic checking of username is done in OC_User
+ * itself, not in its subclasses.
+ */
public function createUser($uid, $password) {
- if(isset($this->users[$uid])) {
+ if (isset($this->users[$uid])) {
return false;
- }else{
- $this->users[$uid]=$password;
+ } else {
+ $this->users[$uid] = $password;
return true;
}
}
/**
- * @brief delete a user
- * @param $uid The username of the user to delete
- * @returns true/false
- *
- * Deletes a user
- */
- public function deleteUser( $uid ) {
- if(isset($this->users[$uid])) {
+ * @brief delete a user
+ * @param string $uid The username of the user to delete
+ * @return bool
+ *
+ * Deletes a user
+ */
+ public function deleteUser($uid) {
+ if (isset($this->users[$uid])) {
unset($this->users[$uid]);
return true;
- }else{
+ } else {
return false;
}
}
/**
- * @brief Set password
- * @param $uid The username
- * @param $password The new password
- * @returns true/false
- *
- * Change the password of a user
- */
+ * @brief Set password
+ * @param string $uid The username
+ * @param string $password The new password
+ * @return bool
+ *
+ * Change the password of a user
+ */
public function setPassword($uid, $password) {
- if(isset($this->users[$uid])) {
- $this->users[$uid]=$password;
+ if (isset($this->users[$uid])) {
+ $this->users[$uid] = $password;
return true;
- }else{
+ } else {
return false;
}
}
/**
- * @brief Check if the password is correct
- * @param $uid The username
- * @param $password The password
- * @returns string
- *
- * Check if the password is correct without logging in the user
- * returns the user id or false
- */
+ * @brief Check if the password is correct
+ * @param string $uid The username
+ * @param string $password The password
+ * @return string
+ *
+ * Check if the password is correct without logging in the user
+ * returns the user id or false
+ */
public function checkPassword($uid, $password) {
- if(isset($this->users[$uid])) {
- return ($this->users[$uid]==$password);
- }else{
+ if (isset($this->users[$uid])) {
+ return ($this->users[$uid] == $password);
+ } else {
return false;
}
}
/**
- * @brief Get a list of all users
- * @returns array with all uids
- *
- * Get a list of all users.
- */
+ * @brief Get a list of all users
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with all uids
+ *
+ * Get a list of all users.
+ */
public function getUsers($search = '', $limit = null, $offset = null) {
return array_keys($this->users);
}
/**
- * @brief check if a user exists
- * @param string $uid the username
- * @return boolean
- */
+ * @brief check if a user exists
+ * @param string $uid the username
+ * @return boolean
+ */
public function userExists($uid) {
return isset($this->users[$uid]);
}
diff --git a/lib/user/manager.php b/lib/user/manager.php
new file mode 100644
index 00000000000..d17cdf1a200
--- /dev/null
+++ b/lib/user/manager.php
@@ -0,0 +1,228 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\User;
+
+use OC\Hooks\PublicEmitter;
+
+/**
+ * Class Manager
+ *
+ * Hooks available in scope \OC\User:
+ * - preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
+ * - postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
+ * - preDelete(\OC\User\User $user)
+ * - postDelete(\OC\User\User $user)
+ * - preCreateUser(string $uid, string $password)
+ * - postCreateUser(\OC\User\User $user, string $password)
+ *
+ * @package OC\User
+ */
+class Manager extends PublicEmitter {
+ /**
+ * @var \OC_User_Backend[] $backends
+ */
+ private $backends = array();
+
+ private $cachedUsers = array();
+
+ public function __construct() {
+ $cachedUsers = $this->cachedUsers;
+ $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
+ $i = array_search($user, $cachedUsers);
+ if ($i !== false) {
+ unset($cachedUsers[$i]);
+ }
+ });
+ }
+
+ /**
+ * register a user backend
+ *
+ * @param \OC_User_Backend $backend
+ */
+ public function registerBackend($backend) {
+ $this->backends[] = $backend;
+ }
+
+ /**
+ * remove a user backend
+ *
+ * @param \OC_User_Backend $backend
+ */
+ public function removeBackend($backend) {
+ $this->cachedUsers = array();
+ if (($i = array_search($backend, $this->backends)) !== false) {
+ unset($this->backends[$i]);
+ }
+ }
+
+ /**
+ * remove all user backends
+ */
+ public function clearBackends() {
+ $this->cachedUsers = array();
+ $this->backends = array();
+ }
+
+ /**
+ * get a user by user id
+ *
+ * @param string $uid
+ * @return \OC\User\User
+ */
+ public function get($uid) {
+ if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends
+ return $this->cachedUsers[$uid];
+ }
+ foreach ($this->backends as $backend) {
+ if ($backend->userExists($uid)) {
+ return $this->getUserObject($uid, $backend);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get or construct the user object
+ *
+ * @param string $uid
+ * @param \OC_User_Backend $backend
+ * @return \OC\User\User
+ */
+ protected function getUserObject($uid, $backend) {
+ if (isset($this->cachedUsers[$uid])) {
+ return $this->cachedUsers[$uid];
+ }
+ $this->cachedUsers[$uid] = new User($uid, $backend, $this);
+ return $this->cachedUsers[$uid];
+ }
+
+ /**
+ * check if a user exists
+ *
+ * @param string $uid
+ * @return bool
+ */
+ public function userExists($uid) {
+ $user = $this->get($uid);
+ return ($user !== null);
+ }
+
+ /**
+ * search by user id
+ *
+ * @param string $pattern
+ * @param int $limit
+ * @param int $offset
+ * @return \OC\User\User[]
+ */
+ public function search($pattern, $limit = null, $offset = null) {
+ $users = array();
+ foreach ($this->backends as $backend) {
+ $backendUsers = $backend->getUsers($pattern, $limit, $offset);
+ if (is_array($backendUsers)) {
+ foreach ($backendUsers as $uid) {
+ $users[] = $this->getUserObject($uid, $backend);
+ if (!is_null($limit)) {
+ $limit--;
+ }
+ if (!is_null($offset) and $offset > 0) {
+ $offset--;
+ }
+
+ }
+ }
+ }
+
+ usort($users, function ($a, $b) {
+ /**
+ * @var \OC\User\User $a
+ * @var \OC\User\User $b
+ */
+ return strcmp($a->getUID(), $b->getUID());
+ });
+ return $users;
+ }
+
+ /**
+ * search by displayName
+ *
+ * @param string $pattern
+ * @param int $limit
+ * @param int $offset
+ * @return \OC\User\User[]
+ */
+ public function searchDisplayName($pattern, $limit = null, $offset = null) {
+ $users = array();
+ foreach ($this->backends as $backend) {
+ $backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
+ if (is_array($backendUsers)) {
+ foreach ($backendUsers as $uid => $displayName) {
+ $users[] = $this->getUserObject($uid, $backend);
+ if (!is_null($limit)) {
+ $limit--;
+ }
+ if (!is_null($offset) and $offset > 0) {
+ $offset--;
+ }
+
+ }
+ }
+ }
+
+ usort($users, function ($a, $b) {
+ /**
+ * @var \OC\User\User $a
+ * @var \OC\User\User $b
+ */
+ return strcmp($a->getDisplayName(), $b->getDisplayName());
+ });
+ return $users;
+ }
+
+ /**
+ * @param string $uid
+ * @param string $password
+ * @throws \Exception
+ * @return bool | \OC\User\User the created user of false
+ */
+ public function createUser($uid, $password) {
+ // Check the name for bad characters
+ // Allowed are: "a-z", "A-Z", "0-9" and "_.@-"
+ if (preg_match('/[^a-zA-Z0-9 _\.@\-]/', $uid)) {
+ throw new \Exception('Only the following characters are allowed in a username:'
+ . ' "a-z", "A-Z", "0-9", and "_.@-"');
+ }
+ // No empty username
+ if (trim($uid) == '') {
+ throw new \Exception('A valid username must be provided');
+ }
+ // No empty password
+ if (trim($password) == '') {
+ throw new \Exception('A valid password must be provided');
+ }
+
+ // Check if user already exists
+ if ($this->userExists($uid)) {
+ throw new \Exception('The username is already being used');
+ }
+
+ $this->emit('\OC\User', 'preCreateUser', array($uid, $password));
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(\OC_USER_BACKEND_CREATE_USER)) {
+ $backend->createUser($uid, $password);
+ $user = $this->getUserObject($uid, $backend);
+ $this->emit('\OC\User', 'postCreateUser', array($user, $password));
+ return $user;
+ }
+ }
+ return false;
+ }
+}
diff --git a/lib/user/session.php b/lib/user/session.php
new file mode 100644
index 00000000000..cf93d9593af
--- /dev/null
+++ b/lib/user/session.php
@@ -0,0 +1,173 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\User;
+
+use OC\Hooks\Emitter;
+
+/**
+ * Class Session
+ *
+ * Hooks available in scope \OC\User:
+ * - preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
+ * - postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
+ * - preDelete(\OC\User\User $user)
+ * - postDelete(\OC\User\User $user)
+ * - preCreateUser(string $uid, string $password)
+ * - postCreateUser(\OC\User\User $user)
+ * - preLogin(string $user, string $password)
+ * - postLogin(\OC\User\User $user)
+ * - logout()
+ *
+ * @package OC\User
+ */
+class Session implements Emitter {
+ /**
+ * @var \OC\User\Manager $manager
+ */
+ private $manager;
+
+ /**
+ * @var \OC\Session\Session $session
+ */
+ private $session;
+
+ /**
+ * @var \OC\User\User $activeUser
+ */
+ protected $activeUser;
+
+ /**
+ * @param \OC\User\Manager $manager
+ * @param \OC\Session\Session $session
+ */
+ public function __construct($manager, $session) {
+ $this->manager = $manager;
+ $this->session = $session;
+ }
+
+ /**
+ * @param string $scope
+ * @param string $method
+ * @param callable $callback
+ */
+ public function listen($scope, $method, $callback) {
+ $this->manager->listen($scope, $method, $callback);
+ }
+
+ /**
+ * @param string $scope optional
+ * @param string $method optional
+ * @param callable $callback optional
+ */
+ public function removeListener($scope = null, $method = null, $callback = null) {
+ $this->manager->removeListener($scope, $method, $callback);
+ }
+
+ /**
+ * get the manager object
+ *
+ * @return \OC\User\Manager
+ */
+ public function getManager() {
+ return $this->manager;
+ }
+
+ /**
+ * set the currently active user
+ *
+ * @param \OC\User\User $user
+ */
+ public function setUser($user) {
+ if (is_null($user)) {
+ $this->session->remove('user_id');
+ } else {
+ $this->session->set('user_id', $user->getUID());
+ }
+ $this->activeUser = $user;
+ }
+
+ /**
+ * get the current active user
+ *
+ * @return \OC\User\User
+ */
+ public function getUser() {
+ if ($this->activeUser) {
+ return $this->activeUser;
+ } else {
+ $uid = $this->session->get('user_id');
+ if ($uid) {
+ $this->activeUser = $this->manager->get($uid);
+ return $this->activeUser;
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /**
+ * try to login with the provided credentials
+ *
+ * @param string $uid
+ * @param string $password
+ * @return bool
+ */
+ public function login($uid, $password) {
+ $this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
+ $user = $this->manager->get($uid);
+ if ($user) {
+ $result = $user->checkPassword($password);
+ if ($result and $user->isEnabled()) {
+ $this->setUser($user);
+ $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * logout the user from the session
+ */
+ public function logout() {
+ $this->manager->emit('\OC\User', 'logout');
+ $this->setUser(null);
+ $this->unsetMagicInCookie();
+ }
+
+ /**
+ * Set cookie value to use in next page load
+ *
+ * @param string $username username to be set
+ * @param string $token
+ */
+ public function setMagicInCookie($username, $token) {
+ $secure_cookie = \OC_Config::getValue("forcessl", false); //TODO: DI for cookies and OC_Config
+ $expires = time() + \OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
+ setcookie("oc_username", $username, $expires, \OC::$WEBROOT, '', $secure_cookie);
+ setcookie("oc_token", $token, $expires, \OC::$WEBROOT, '', $secure_cookie, true);
+ setcookie("oc_remember_login", true, $expires, \OC::$WEBROOT, '', $secure_cookie);
+ }
+
+ /**
+ * Remove cookie for "remember username"
+ */
+ public function unsetMagicInCookie() {
+ unset($_COOKIE["oc_username"]); //TODO: DI
+ unset($_COOKIE["oc_token"]);
+ unset($_COOKIE["oc_remember_login"]);
+ setcookie("oc_username", null, -1);
+ setcookie("oc_token", null, -1);
+ setcookie("oc_remember_login", null, -1);
+ }
+}
diff --git a/lib/user/user.php b/lib/user/user.php
new file mode 100644
index 00000000000..55d7848a979
--- /dev/null
+++ b/lib/user/user.php
@@ -0,0 +1,197 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\User;
+
+use OC\Hooks\Emitter;
+
+class User {
+ /**
+ * @var string $uid
+ */
+ private $uid;
+
+ /**
+ * @var string $displayName
+ */
+ private $displayName;
+
+ /**
+ * @var \OC_User_Backend $backend
+ */
+ private $backend;
+
+ /**
+ * @var bool $enabled
+ */
+ private $enabled;
+
+ /**
+ * @var Emitter | Manager $emitter
+ */
+ private $emitter;
+
+ /**
+ * @param string $uid
+ * @param \OC_User_Backend $backend
+ * @param Emitter $emitter
+ */
+ public function __construct($uid, $backend, $emitter = null) {
+ $this->uid = $uid;
+ if ($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
+ $this->displayName = $backend->getDisplayName($uid);
+ } else {
+ $this->displayName = $uid;
+ }
+ $this->backend = $backend;
+ $this->emitter = $emitter;
+ $enabled = \OC_Preferences::getValue($uid, 'core', 'enabled', 'true'); //TODO: DI for OC_Preferences
+ $this->enabled = ($enabled === 'true');
+ }
+
+ /**
+ * get the user id
+ *
+ * @return string
+ */
+ public function getUID() {
+ return $this->uid;
+ }
+
+ /**
+ * get the displayname for the user, if no specific displayname is set it will fallback to the user id
+ *
+ * @return string
+ */
+ public function getDisplayName() {
+ return $this->displayName;
+ }
+
+ /**
+ * set the displayname for the user
+ *
+ * @param string $displayName
+ * @return bool
+ */
+ public function setDisplayName($displayName) {
+ if ($this->canChangeDisplayName()) {
+ $this->displayName = $displayName;
+ $result = $this->backend->setDisplayName($this->uid, $displayName);
+ return $result !== false;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Delete the user
+ *
+ * @return bool
+ */
+ public function delete() {
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\User', 'preDelete', array($this));
+ }
+ $result = $this->backend->deleteUser($this->uid);
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\User', 'postDelete', array($this));
+ }
+ return !($result === false);
+ }
+
+ /**
+ * Check if the password is valid for the user
+ *
+ * @param $password
+ * @return bool
+ */
+ public function checkPassword($password) {
+ if ($this->backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
+ $result = $this->backend->checkPassword($this->uid, $password);
+ if ($result !== false) {
+ $this->uid = $result;
+ }
+ return !($result === false);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Set the password of the user
+ *
+ * @param string $password
+ * @param string $recoveryPassword for the encryption app to reset encryption keys
+ * @return bool
+ */
+ public function setPassword($password, $recoveryPassword) {
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
+ }
+ if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD)) {
+ $result = $this->backend->setPassword($this->uid, $password);
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
+ }
+ return !($result === false);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * get the users home folder to mount
+ *
+ * @return string
+ */
+ public function getHome() {
+ if ($this->backend->implementsActions(\OC_USER_BACKEND_GET_HOME) and $home = $this->backend->getHome($this->uid)) {
+ return $home;
+ }
+ return \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data") . '/' . $this->uid; //TODO switch to Config object once implemented
+ }
+
+ /**
+ * check if the backend supports changing passwords
+ *
+ * @return bool
+ */
+ public function canChangePassword() {
+ return $this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD);
+ }
+
+ /**
+ * check if the backend supports changing display names
+ *
+ * @return bool
+ */
+ public function canChangeDisplayName() {
+ return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
+ }
+
+ /**
+ * check if the user is enabled
+ *
+ * @return bool
+ */
+ public function isEnabled() {
+ return $this->enabled;
+ }
+
+ /**
+ * set the enabled status for the user
+ *
+ * @param bool $enabled
+ */
+ public function setEnabled($enabled) {
+ $this->enabled = $enabled;
+ $enabled = ($enabled) ? 'true' : 'false';
+ \OC_Preferences::setValue($this->uid, 'core', 'enabled', $enabled);
+ }
+}
diff --git a/lib/util.php b/lib/util.php
index 01e2df7bfc4..4bc02daf36e 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -1,4 +1,7 @@
<?php
+
+require_once 'Patchwork/PHP/Shim/Normalizer.php';
+
/**
* Class for utility functions
*
@@ -77,7 +80,7 @@ class OC_Util {
public static function getVersion() {
// hint: We only can count up. Reset minor/patchlevel when
// updating major/minor version number.
- return array(5, 80, 03);
+ return array(5, 80, 05);
}
/**
@@ -151,10 +154,10 @@ class OC_Util {
* @param bool dateOnly option to omit time from the result
*/
public static function formatDate( $timestamp, $dateOnly=false) {
- if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it
+ if(\OC::$session->exists('timezone')) {//adjust to clients timezone if we know it
$systemTimeZone = intval(date('O'));
$systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100);
- $clientTimeZone=$_SESSION['timezone']*60;
+ $clientTimeZone=\OC::$session->get('timezone')*60;
$offset=$clientTimeZone-$systemTimeZone;
$timestamp=$timestamp+$offset*60;
}
@@ -458,13 +461,13 @@ class OC_Util {
*/
public static function callRegister() {
// Check if a token exists
- if(!isset($_SESSION['requesttoken'])) {
+ if(!\OC::$session->exists('requesttoken')) {
// No valid token found, generate a new one.
$requestToken = self::generate_random_bytes(20);
- $_SESSION['requesttoken']=$requestToken;
+ \OC::$session->set('requesttoken', $requestToken);
} else {
// Valid token already exists, send it
- $requestToken = $_SESSION['requesttoken'];
+ $requestToken = \OC::$session->get('requesttoken');
}
return($requestToken);
}
@@ -476,7 +479,7 @@ class OC_Util {
* @see OC_Util::callRegister()
*/
public static function isCallRegistered() {
- if(!isset($_SESSION['requesttoken'])) {
+ if(!\OC::$session->exists('requesttoken')) {
return false;
}
@@ -492,7 +495,7 @@ class OC_Util {
}
// Check if the token is valid
- if($token !== $_SESSION['requesttoken']) {
+ if($token !== \OC::$session->get('requesttoken')) {
// Not valid
return false;
} else {
@@ -641,11 +644,10 @@ class OC_Util {
/**
* Check if the ownCloud server can connect to the internet
*/
- public static function isinternetconnectionworking() {
-
- // in case there is no internet connection on purpose there is no need to display a warning
- if (!\OC_Config::getValue("has_internet_connection", true)) {
- return true;
+ public static function isInternetConnectionWorking() {
+ // in case there is no internet connection on purpose return false
+ if (self::isInternetConnectionEnabled() === false) {
+ return false;
}
// try to connect to owncloud.org to see if http connections to the internet are possible.
@@ -667,6 +669,13 @@ class OC_Util {
}
}
+
+ /**
+ * Check if the connection to the internet is disabled on purpose
+ */
+ public static function isInternetConnectionEnabled(){
+ return \OC_Config::getValue("has_internet_connection", true);
+ }
/**
* clear all levels of output buffering
@@ -810,9 +819,9 @@ class OC_Util {
* @return string the theme
*/
public static function getTheme() {
- $theme = OC_Config::getValue("theme");
+ $theme = OC_Config::getValue("theme", '');
- if(is_null($theme)) {
+ if($theme === '') {
if(is_dir(OC::$SERVERROOT . '/themes/default')) {
$theme = 'default';
@@ -823,5 +832,41 @@ class OC_Util {
return $theme;
}
+ /**
+ * Clear the opcode cache if one exists
+ * This is necessary for writing to the config file
+ * in case the opcode cache doesn't revalidate files
+ */
+ public static function clearOpcodeCache() {
+ // APC
+ if (function_exists('apc_clear_cache')) {
+ apc_clear_cache();
+ }
+ // Zend Opcache
+ if (function_exists('accelerator_reset')) {
+ accelerator_reset();
+ }
+ // XCache
+ if (function_exists('xcache_clear_cache')) {
+ xcache_clear_cache(XC_TYPE_VAR, 0);
+ }
+ }
+
+ /**
+ * Normalize a unicode string
+ * @param string $value a not normalized string
+ * @return bool|string
+ */
+ public static function normalizeUnicode($value) {
+ if(class_exists('Patchwork\PHP\Shim\Normalizer')) {
+ $normalizedValue = \Patchwork\PHP\Shim\Normalizer::normalize($value);
+ if($normalizedValue === false) {
+ \OC_Log::write( 'core', 'normalizing failed for "' . $value . '"', \OC_Log::WARN);
+ } else {
+ $value = $normalizedValue;
+ }
+ }
+ return $value;
+ }
}
diff --git a/lib/vcategories.php b/lib/vcategories.php
index 91c72d5dfae..7bac6e7d4e3 100644
--- a/lib/vcategories.php
+++ b/lib/vcategories.php
@@ -554,7 +554,7 @@ class OC_VCategories {
}
try {
$stmt = OCP\DB::prepare('DELETE FROM `' . self::CATEGORY_TABLE . '` '
- . 'WHERE `uid` = ? AND');
+ . 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid']));
if (OC_DB::isError($result)) {
OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);