diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-08-06 15:43:58 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-08-06 15:43:58 +0200 |
commit | 95a959b10b7c9dc7b0529fbb7b05c11685f19e8b (patch) | |
tree | f283b4980f39ec4c998fc3a4d8a6a3d241109d6a /lib | |
parent | ed054e67d60e8ad8074b38842935e5dff927350c (diff) | |
parent | 057d7aa108f9b24c12b97f5f78008eb17a6d3bee (diff) | |
download | nextcloud-server-95a959b10b7c9dc7b0529fbb7b05c11685f19e8b.tar.gz nextcloud-server-95a959b10b7c9dc7b0529fbb7b05c11685f19e8b.zip |
merge master into doctrine-object
Diffstat (limited to 'lib')
-rw-r--r-- | lib/db.php | 62 | ||||
-rw-r--r-- | lib/db/connection.php | 3 | ||||
-rw-r--r-- | lib/db/mdb2schemamanager.php (renamed from lib/db/schema.php) | 90 | ||||
-rw-r--r-- | lib/files/cache/scanner.php | 2 | ||||
-rw-r--r-- | lib/log/owncloud.php | 10 | ||||
-rw-r--r-- | lib/log/syslog.php | 9 | ||||
-rw-r--r-- | lib/migration/content.php | 2 | ||||
-rw-r--r-- | lib/mimetypes.list.php | 3 |
8 files changed, 99 insertions, 82 deletions
diff --git a/lib/db.php b/lib/db.php index fec4eaaf93f..2b6cd59366a 100644 --- a/lib/db.php +++ b/lib/db.php @@ -46,6 +46,7 @@ class OC_DB { */ static private $connection; //the prefered connection to use, only Doctrine + static private $prefix=null; static private $type=null; /** @@ -170,6 +171,16 @@ class OC_DB { } /** + * get MDB2 schema manager + * + * @return \OC\DB\MDB2SchemaManager + */ + private static function getMDB2SchemaManager() + { + return new \OC\DB\MDB2SchemaManager(self::getConnection()); + } + + /** * @brief Prepare a SQL query * @param string $query Query string * @param int $limit @@ -204,22 +215,23 @@ class OC_DB { * the current check allows some whitespace but does not work with IF EXISTS or other more complex statements * * @param string $sql + * @return bool */ static public function isManipulation( $sql ) { - $selectOccurence = stripos ($sql, "SELECT"); - if ($selectOccurence !== false && $selectOccurence < 10) { + $selectOccurrence = stripos ($sql, "SELECT"); + if ($selectOccurrence !== false && $selectOccurrence < 10) { return false; } - $insertOccurence = stripos ($sql, "INSERT"); - if ($insertOccurence !== false && $insertOccurence < 10) { + $insertOccurrence = stripos ($sql, "INSERT"); + if ($insertOccurrence !== false && $insertOccurrence < 10) { return true; } - $updateOccurence = stripos ($sql, "UPDATE"); - if ($updateOccurence !== false && $updateOccurence < 10) { + $updateOccurrence = stripos ($sql, "UPDATE"); + if ($updateOccurrence !== false && $updateOccurrence < 10) { return true; } - $deleteOccurance = stripos ($sql, "DELETE"); - if ($deleteOccurance !== false && $deleteOccurance < 10) { + $deleteOccurrence = stripos ($sql, "DELETE"); + if ($deleteOccurrence !== false && $deleteOccurrence < 10) { return true; } return false; @@ -294,7 +306,7 @@ class OC_DB { * @brief Insert a row if a matching row doesn't exists. * @param string $table. The table to insert into in the form '*PREFIX*tableName' * @param array $input. An array of fieldname/value pairs - * @returns int number of updated rows + * @return int number of updated rows */ public static function insertIfNotExist($table, $input) { self::connect(); @@ -329,17 +341,17 @@ class OC_DB { } } - /** else { - * @brief saves database scheme to xml file + /** + * @brief saves database schema to xml file * @param string $file name of file * @param int $mode * @return bool * * TODO: write more documentation */ - public static function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { - self::connect(); - return OC_DB_Schema::getDbStructure(self::$connection, $file); + public static function getDbStructure( $file, $mode = 0) { + $schemaManager = self::getMDB2SchemaManager(); + return $schemaManager->getDbStructure($file); } /** @@ -350,21 +362,21 @@ class OC_DB { * TODO: write more documentation */ public static function createDbFromStructure( $file ) { - self::connect(); - $result = OC_DB_Schema::createDbFromStructure(self::$connection, $file); + $schemaManager = self::getMDB2SchemaManager(); + $result = $schemaManager->createDbFromStructure($file); return $result; } /** - * @brief update the database scheme + * @brief update the database schema * @param string $file file to read structure from * @throws Exception * @return bool */ public static function updateDbFromStructure($file) { - self::connect(); + $schemaManager = self::getMDB2SchemaManager(); try { - $result = OC_DB_Schema::updateDbFromStructure(self::$connection, $file); + $result = $schemaManager->updateDbFromStructure($file); } catch (Exception $e) { OC_Log::write('core', 'Failed to update database structure ('.$e.')', OC_Log::FATAL); throw $e; @@ -377,8 +389,8 @@ class OC_DB { * @param string $tableName the table to drop */ public static function dropTable($tableName) { - self::connect(); - OC_DB_Schema::dropTable(self::$connection, $tableName); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->dropTable($tableName); } /** @@ -386,8 +398,8 @@ class OC_DB { * @param string $file the xml file describing the tables */ public static function removeDBStructure($file) { - self::connect(); - OC_DB_Schema::removeDBStructure(self::$connection, $file); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->removeDBStructure($file); } /** @@ -395,8 +407,8 @@ class OC_DB { * @param $file string path to the MDB2 xml db export file */ public static function replaceDB( $file ) { - self::connect(); - OC_DB_Schema::replaceDB(self::$connection, $file); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->replaceDB($file); } /** diff --git a/lib/db/connection.php b/lib/db/connection.php index 920fe144a8a..7f207ff76ec 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -76,13 +76,12 @@ class Connection extends \Doctrine\DBAL\Connection { return $this->preparedQueries[$statement]; } } - $rawQuery = $statement; if(\OC_Config::getValue( "log_query", false)) { \OC_Log::write('core', 'DB prepare : '.$statement, \OC_Log::DEBUG); } $result = parent::prepare($statement); if (is_null($limit) && $this->cachingQueryStatementEnabled) { - $this->preparedQueries[$rawQuery] = $result; + $this->preparedQueries[$statement] = $result; } return $result; } diff --git a/lib/db/schema.php b/lib/db/mdb2schemamanager.php index bc82249609d..8e76f46c78f 100644 --- a/lib/db/schema.php +++ b/lib/db/mdb2schemamanager.php @@ -6,47 +6,58 @@ * See the COPYING-README file. */ -class OC_DB_Schema { +namespace OC\DB; + +class MDB2SchemaManager { + /** + * @var \OC\DB\Connection $conn + */ + protected $conn; + + /** + * @param \OC\DB\Connection $conn + */ + public function __construct($conn) { + $this->conn = $conn; + } + /** * @brief saves database scheme to xml file - * @param \Doctrine\DBAL\Connection $conn * @param string $file name of file * @param int|string $mode * @return bool * * TODO: write more documentation */ - public static function getDbStructure( $conn, $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { - $sm = $conn->getSchemaManager(); + public function getDbStructure( $file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) { + $sm = $this->conn->getSchemaManager(); - return OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm); + return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm); } /** * @brief Creates tables from XML file - * @param \Doctrine\DBAL\Connection $conn * @param string $file file to read structure from * @return bool * * TODO: write more documentation */ - public static function createDbFromStructure( $conn, $file ) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform()); + public function createDbFromStructure( $file ) { + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $toSchema = $schemaReader->loadSchemaFromFile($file); - return self::executeSchemaChange($conn, $toSchema); + return $this->executeSchemaChange($toSchema); } /** * @brief update the database scheme - * @param \Doctrine\DBAL\Connection $conn * @param string $file file to read structure from * @return bool */ - public static function updateDbFromStructure($conn, $file) { - $sm = $conn->getSchemaManager(); + public function updateDbFromStructure($file) { + $sm = $this->conn->getSchemaManager(); $fromSchema = $sm->createSchema(); - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform()); + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $toSchema = $schemaReader->loadSchemaFromFile($file); // remove tables we don't know about @@ -65,43 +76,34 @@ class OC_DB_Schema { $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); - $platform = $conn->getDatabasePlatform(); + $platform = $this->conn->getDatabasePlatform(); $tables = $schemaDiff->newTables + $schemaDiff->changedTables + $schemaDiff->removedTables; foreach($tables as $tableDiff) { $tableDiff->name = $platform->quoteIdentifier($tableDiff->name); } - - //$from = $fromSchema->toSql($conn->getDatabasePlatform()); - //$to = $toSchema->toSql($conn->getDatabasePlatform()); - //echo($from[9]); - //echo '<br>'; - //echo($to[9]); - //var_dump($from, $to); - return self::executeSchemaChange($conn, $schemaDiff); + return $this->executeSchemaChange($schemaDiff); } /** * @brief drop a table - * @param \Doctrine\DBAL\Connection $conn * @param string $tableName the table to drop */ - public static function dropTable($conn, $tableName) { - $sm = $conn->getSchemaManager(); + public function dropTable($tableName) { + $sm = $this->conn->getSchemaManager(); $fromSchema = $sm->createSchema(); $toSchema = clone $fromSchema; $toSchema->dropTable($tableName); - $sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform()); - $conn->execute($sql); + $sql = $fromSchema->getMigrateToSql($toSchema, $this->conn->getDatabasePlatform()); + $this->conn->executeQuery($sql); } /** * remove all tables defined in a database structure xml file - * @param \Doctrine\DBAL\Connection $conn * @param string $file the xml file describing the tables */ - public static function removeDBStructure($conn, $file) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform()); + public function removeDBStructure($file) { + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $fromSchema = $schemaReader->loadSchemaFromFile($file); $toSchema = clone $fromSchema; foreach($toSchema->getTables() as $table) { @@ -109,42 +111,40 @@ class OC_DB_Schema { } $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); - self::executeSchemaChange($conn, $schemaDiff); + $this->executeSchemaChange($schemaDiff); } /** * @brief replaces the ownCloud tables with a new set - * @param \Doctrine\DBAL\Connection $conn * @param $file string path to the MDB2 xml db export file */ - public static function replaceDB( $conn, $file ) { - $apps = OC_App::getAllApps(); - self::beginTransaction(); + public function replaceDB( $file ) { + $apps = \OC_App::getAllApps(); + $this->conn->beginTransaction(); // Delete the old tables - self::removeDBStructure( $conn, OC::$SERVERROOT . '/db_structure.xml' ); + $this->removeDBStructure( \OC::$SERVERROOT . '/db_structure.xml' ); foreach($apps as $app) { - $path = OC_App::getAppPath($app).'/appinfo/database.xml'; + $path = \OC_App::getAppPath($app).'/appinfo/database.xml'; if(file_exists($path)) { - self::removeDBStructure( $conn, $path ); + $this->removeDBStructure( $path ); } } // Create new tables - self::commit(); + $this->conn->commit(); } /** - * @param \Doctrine\DBAL\Connection $conn * @param \Doctrine\DBAL\Schema\Schema $schema * @return bool */ - private static function executeSchemaChange($conn, $schema) { - $conn->beginTransaction(); - foreach($schema->toSql($conn->getDatabasePlatform()) as $sql) { - $conn->query($sql); + private function executeSchemaChange($schema) { + $this->conn->beginTransaction(); + foreach($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { + $this->conn->query($sql); } - $conn->commit(); + $this->conn->commit(); return true; } } diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index dd212d84cc5..adecc2bb901 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -98,7 +98,7 @@ class Scanner extends BasicEmitter { $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 (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) { if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { $data['size'] = $cacheData['size']; } diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index 7a11a588330..d16b9537a16 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -44,12 +44,14 @@ class OC_Log_Owncloud { * write a message in the log * @param string $app * @param string $message - * @param int level + * @param int $level */ public static function write($app, $message, $level) { $minLevel=min(OC_Config::getValue( "loglevel", OC_Log::WARN ), OC_Log::ERROR); if($level>=$minLevel) { - $time = date("F d, Y H:i:s", time()); + // default to ISO8601 + $format = OC_Config::getValue('logdateformat', 'c'); + $time = date($format, time()); $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time); $handle = @fopen(self::$logFile, 'a'); if ($handle) { @@ -61,8 +63,8 @@ class OC_Log_Owncloud { /** * get entries from the log in reverse chronological order - * @param int limit - * @param int offset + * @param int $limit + * @param int $offset * @return array */ public static function getEntries($limit=50, $offset=0) { diff --git a/lib/log/syslog.php b/lib/log/syslog.php index d1fb28d8b0a..c98deab7109 100644 --- a/lib/log/syslog.php +++ b/lib/log/syslog.php @@ -28,10 +28,13 @@ class OC_Log_Syslog { * write a message in the log * @param string $app * @param string $message - * @param int level + * @param int $level */ public static function write($app, $message, $level) { - $syslog_level = self::$levels[$level]; - syslog($syslog_level, '{'.$app.'} '.$message); + $minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR); + if ($level >= $minLevel) { + $syslog_level = self::$levels[$level]; + syslog($syslog_level, '{'.$app.'} '.$message); + } } } diff --git a/lib/migration/content.php b/lib/migration/content.php index 400a46a4340..2d8268a1d74 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -112,7 +112,7 @@ class OC_Migration_Content{ foreach( $options['matchval'] as $matchval ) { // Run the query for this match value (where x = y value) - $sql = 'SELECT * FROM `*PREFIX*' . $options['table'] . '` WHERE `' . $options['matchcol'] . '` LIKE ?'; + $sql = 'SELECT * FROM `*PREFIX*' . $options['table'] . '` WHERE `' . $options['matchcol'] . '` = ?'; $query = OC_DB::prepare( $sql ); $results = $query->execute( array( $matchval ) ); $newreturns = $this->insertData( $results, $options ); diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php index 2aac3bbfd27..8ab8ac81bd8 100644 --- a/lib/mimetypes.list.php +++ b/lib/mimetypes.list.php @@ -102,5 +102,6 @@ return array( 'md' => 'text/markdown', 'markdown' => 'text/markdown', 'mdown' => 'text/markdown', - 'mdwn' => 'text/markdown' + 'mdwn' => 'text/markdown', + 'reveal' => 'text/reveal' ); |