From 89f8f8e42d2729254a1b0e06c942af934bee3948 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 29 Jul 2013 18:36:52 +0200 Subject: app migrate: Use = instead of LIKE as described in the comment above. The LIKE operator is not defined on integers (probably any non-text) columns on PostgreSQL. --- lib/migration/content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 ); -- cgit v1.2.3 From 943288542804996687d41c548acf25800d270a49 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 29 Jul 2013 17:46:20 +0200 Subject: Change OC_DB_Schema to use DI for db connection object --- lib/db.php | 19 ++++++++---- lib/db/schema.php | 87 +++++++++++++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 51 deletions(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index dd48c329490..a618e8ebb94 100644 --- a/lib/db.php +++ b/lib/db.php @@ -397,7 +397,8 @@ class OC_DB { */ public static function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { self::connectDoctrine(); - return OC_DB_Schema::getDbStructure(self::$DOCTRINE, $file); + $schema = new \OC\DB\Schema(self::$connection); + return $schema->getDbStructure($file); } /** @@ -409,7 +410,9 @@ class OC_DB { */ public static function createDbFromStructure( $file ) { self::connectDoctrine(); - return OC_DB_Schema::createDbFromStructure(self::$DOCTRINE, $file); + $schema = new \OC\DB\Schema(self::$connection); + $result = $schema->createDbFromStructure($file); + return $result; } /** @@ -420,8 +423,9 @@ class OC_DB { */ public static function updateDbFromStructure($file) { self::connectDoctrine(); + $schema = new \OC\DB\Schema(self::$connection); try { - $result = OC_DB_Schema::updateDbFromStructure(self::$DOCTRINE, $file); + $result = $schema->updateDbFromStructure($file); } catch (Exception $e) { OC_Log::write('core', 'Failed to update database structure ('.$e.')', OC_Log::FATAL); throw $e; @@ -601,7 +605,8 @@ class OC_DB { */ public static function dropTable($tableName) { self::connectDoctrine(); - OC_DB_Schema::dropTable(self::$DOCTRINE, $tableName); + $schema = new \OC\DB\Schema(self::$connection); + $schema->dropTable($tableName); } /** @@ -610,7 +615,8 @@ class OC_DB { */ public static function removeDBStructure($file) { self::connectDoctrine(); - OC_DB_Schema::removeDBStructure(self::$DOCTRINE, $file); + $schema = new \OC\DB\Schema(self::$connection); + $schema->removeDBStructure($file); } /** @@ -619,7 +625,8 @@ class OC_DB { */ public static function replaceDB( $file ) { self::connectDoctrine(); - OC_DB_Schema::replaceDB(self::$DOCTRINE, $file); + $schema = new \OC\DB\Schema(self::$connection); + $schema->replaceDB($file); } /** diff --git a/lib/db/schema.php b/lib/db/schema.php index bc82249609d..b2dd982e8ea 100644 --- a/lib/db/schema.php +++ b/lib/db/schema.php @@ -6,47 +6,55 @@ * See the COPYING-README file. */ -class OC_DB_Schema { +namespace OC\DB; + +class Schema { + /** + * @var \Doctrine\DBAL\Connection $conn + */ + protected $conn; + + public function __construct(Connection $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 \OC\DB\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 \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $toSchema = $schemaReader->loadSchemaFromFile($file); // remove tables we don't know about @@ -65,43 +73,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 '
'; - //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->execute($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 \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $fromSchema = $schemaReader->loadSchemaFromFile($file); $toSchema = clone $fromSchema; foreach($toSchema->getTables() as $table) { @@ -109,42 +108,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; } } -- cgit v1.2.3 From 59c5529a2ba966b49622706eddce43f04b4a25b4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 2 Aug 2013 13:19:27 +0200 Subject: Rename \OC\DB\Schema to \OC\DB\MDB2SchemaManager --- lib/db.php | 12 ++-- lib/db/mdb2schemamanager.php | 147 +++++++++++++++++++++++++++++++++++++++++++ lib/db/schema.php | 147 ------------------------------------------- 3 files changed, 153 insertions(+), 153 deletions(-) create mode 100644 lib/db/mdb2schemamanager.php delete mode 100644 lib/db/schema.php (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index a618e8ebb94..b92f7820f31 100644 --- a/lib/db.php +++ b/lib/db.php @@ -397,7 +397,7 @@ class OC_DB { */ public static function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); return $schema->getDbStructure($file); } @@ -410,7 +410,7 @@ class OC_DB { */ public static function createDbFromStructure( $file ) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); $result = $schema->createDbFromStructure($file); return $result; } @@ -423,7 +423,7 @@ class OC_DB { */ public static function updateDbFromStructure($file) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); try { $result = $schema->updateDbFromStructure($file); } catch (Exception $e) { @@ -605,7 +605,7 @@ class OC_DB { */ public static function dropTable($tableName) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); $schema->dropTable($tableName); } @@ -615,7 +615,7 @@ class OC_DB { */ public static function removeDBStructure($file) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); $schema->removeDBStructure($file); } @@ -625,7 +625,7 @@ class OC_DB { */ public static function replaceDB( $file ) { self::connectDoctrine(); - $schema = new \OC\DB\Schema(self::$connection); + $schema = new \OC\DB\MDB2SchemaManager(self::$connection); $schema->replaceDB($file); } diff --git a/lib/db/mdb2schemamanager.php b/lib/db/mdb2schemamanager.php new file mode 100644 index 00000000000..2f828beb824 --- /dev/null +++ b/lib/db/mdb2schemamanager.php @@ -0,0 +1,147 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\DB; + +class MDB2SchemaManager { + /** + * @var \Doctrine\DBAL\Connection $conn + */ + protected $conn; + + public function __construct(Connection $conn) { + $this->conn = $conn; + } + + /** + * @brief saves database scheme to xml file + * @param string $file name of file + * @param int|string $mode + * @return bool + * + * TODO: write more documentation + */ + public function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { + $sm = $this->conn->getSchemaManager(); + + return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm); + } + + /** + * @brief Creates tables from XML file + * @param string $file file to read structure from + * @return bool + * + * TODO: write more documentation + */ + public function createDbFromStructure( $file ) { + $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $toSchema = $schemaReader->loadSchemaFromFile($file); + return $this->executeSchemaChange($toSchema); + } + + /** + * @brief update the database scheme + * @param string $file file to read structure from + * @return bool + */ + public function updateDbFromStructure($file) { + $sm = $this->conn->getSchemaManager(); + $fromSchema = $sm->createSchema(); + + $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $toSchema = $schemaReader->loadSchemaFromFile($file); + + // remove tables we don't know about + foreach($fromSchema->getTables() as $table) { + if (!$toSchema->hasTable($table->getName())) { + $fromSchema->dropTable($table->getName()); + } + } + // remove sequences we don't know about + foreach($fromSchema->getSequences() as $table) { + if (!$toSchema->hasSequence($table->getName())) { + $fromSchema->dropSequence($table->getName()); + } + } + + $comparator = new \Doctrine\DBAL\Schema\Comparator(); + $schemaDiff = $comparator->compare($fromSchema, $toSchema); + + $platform = $this->conn->getDatabasePlatform(); + $tables = $schemaDiff->newTables + $schemaDiff->changedTables + $schemaDiff->removedTables; + foreach($tables as $tableDiff) { + $tableDiff->name = $platform->quoteIdentifier($tableDiff->name); + } + + return $this->executeSchemaChange($schemaDiff); + } + + /** + * @brief drop a table + * @param string $tableName the table to drop + */ + public function dropTable($tableName) { + $sm = $this->conn->getSchemaManager(); + $fromSchema = $sm->createSchema(); + $toSchema = clone $fromSchema; + $toSchema->dropTable($tableName); + $sql = $fromSchema->getMigrateToSql($toSchema, $this->conn->getDatabasePlatform()); + $this->conn->execute($sql); + } + + /** + * remove all tables defined in a database structure xml file + * @param string $file the xml file describing the tables + */ + public function removeDBStructure($file) { + $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $fromSchema = $schemaReader->loadSchemaFromFile($file); + $toSchema = clone $fromSchema; + foreach($toSchema->getTables() as $table) { + $toSchema->dropTable($table->getName()); + } + $comparator = new \Doctrine\DBAL\Schema\Comparator(); + $schemaDiff = $comparator->compare($fromSchema, $toSchema); + $this->executeSchemaChange($schemaDiff); + } + + /** + * @brief replaces the ownCloud tables with a new set + * @param $file string path to the MDB2 xml db export file + */ + public function replaceDB( $file ) { + $apps = \OC_App::getAllApps(); + $this->conn->beginTransaction(); + // Delete the old tables + $this->removeDBStructure( OC::$SERVERROOT . '/db_structure.xml' ); + + foreach($apps as $app) { + $path = \OC_App::getAppPath($app).'/appinfo/database.xml'; + if(file_exists($path)) { + $this->removeDBStructure( $path ); + } + } + + // Create new tables + $this->conn->commit(); + } + + /** + * @param \Doctrine\DBAL\Schema\Schema $schema + * @return bool + */ + private function executeSchemaChange($schema) { + $this->conn->beginTransaction(); + foreach($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { + $this->conn->query($sql); + } + $this->conn->commit(); + return true; + } +} diff --git a/lib/db/schema.php b/lib/db/schema.php deleted file mode 100644 index b2dd982e8ea..00000000000 --- a/lib/db/schema.php +++ /dev/null @@ -1,147 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OC\DB; - -class Schema { - /** - * @var \Doctrine\DBAL\Connection $conn - */ - protected $conn; - - public function __construct(Connection $conn) { - $this->conn = $conn; - } - - /** - * @brief saves database scheme to xml file - * @param string $file name of file - * @param int|string $mode - * @return bool - * - * TODO: write more documentation - */ - public function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { - $sm = $this->conn->getSchemaManager(); - - return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm); - } - - /** - * @brief Creates tables from XML file - * @param string $file file to read structure from - * @return bool - * - * TODO: write more documentation - */ - public function createDbFromStructure( $file ) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); - $toSchema = $schemaReader->loadSchemaFromFile($file); - return $this->executeSchemaChange($toSchema); - } - - /** - * @brief update the database scheme - * @param string $file file to read structure from - * @return bool - */ - public function updateDbFromStructure($file) { - $sm = $this->conn->getSchemaManager(); - $fromSchema = $sm->createSchema(); - - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); - $toSchema = $schemaReader->loadSchemaFromFile($file); - - // remove tables we don't know about - foreach($fromSchema->getTables() as $table) { - if (!$toSchema->hasTable($table->getName())) { - $fromSchema->dropTable($table->getName()); - } - } - // remove sequences we don't know about - foreach($fromSchema->getSequences() as $table) { - if (!$toSchema->hasSequence($table->getName())) { - $fromSchema->dropSequence($table->getName()); - } - } - - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $schemaDiff = $comparator->compare($fromSchema, $toSchema); - - $platform = $this->conn->getDatabasePlatform(); - $tables = $schemaDiff->newTables + $schemaDiff->changedTables + $schemaDiff->removedTables; - foreach($tables as $tableDiff) { - $tableDiff->name = $platform->quoteIdentifier($tableDiff->name); - } - - return $this->executeSchemaChange($schemaDiff); - } - - /** - * @brief drop a table - * @param string $tableName the table to drop - */ - public function dropTable($tableName) { - $sm = $this->conn->getSchemaManager(); - $fromSchema = $sm->createSchema(); - $toSchema = clone $fromSchema; - $toSchema->dropTable($tableName); - $sql = $fromSchema->getMigrateToSql($toSchema, $this->conn->getDatabasePlatform()); - $this->conn->execute($sql); - } - - /** - * remove all tables defined in a database structure xml file - * @param string $file the xml file describing the tables - */ - public function removeDBStructure($file) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); - $fromSchema = $schemaReader->loadSchemaFromFile($file); - $toSchema = clone $fromSchema; - foreach($toSchema->getTables() as $table) { - $toSchema->dropTable($table->getName()); - } - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $schemaDiff = $comparator->compare($fromSchema, $toSchema); - $this->executeSchemaChange($schemaDiff); - } - - /** - * @brief replaces the ownCloud tables with a new set - * @param $file string path to the MDB2 xml db export file - */ - public function replaceDB( $file ) { - $apps = \OC_App::getAllApps(); - $this->conn->beginTransaction(); - // Delete the old tables - $this->removeDBStructure( OC::$SERVERROOT . '/db_structure.xml' ); - - foreach($apps as $app) { - $path = \OC_App::getAppPath($app).'/appinfo/database.xml'; - if(file_exists($path)) { - $this->removeDBStructure( $path ); - } - } - - // Create new tables - $this->conn->commit(); - } - - /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * @return bool - */ - private function executeSchemaChange($schema) { - $this->conn->beginTransaction(); - foreach($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { - $this->conn->query($sql); - } - $this->conn->commit(); - return true; - } -} -- cgit v1.2.3 From f5c3a346b00b7c8e4926b898f6e6ade86de74c73 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 2 Aug 2013 13:34:20 +0200 Subject: make log date configurable, default to iso 8601 --- lib/log/owncloud.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index 7a11a588330..e7246726d40 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -49,7 +49,9 @@ class OC_Log_Owncloud { 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) { -- cgit v1.2.3 From 258e54182a9d68191a721ddc904e3e0299438b70 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 2 Aug 2013 15:09:50 +0200 Subject: remove invalid type hinting and cleanup namespaces a bit --- lib/db/mdb2schemamanager.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/db/mdb2schemamanager.php b/lib/db/mdb2schemamanager.php index 2f828beb824..a34bc9dae75 100644 --- a/lib/db/mdb2schemamanager.php +++ b/lib/db/mdb2schemamanager.php @@ -14,7 +14,10 @@ class MDB2SchemaManager { */ protected $conn; - public function __construct(Connection $conn) { + /** + * @param \Doctrine\DBAL\Connection $conn + */ + public function __construct($conn) { $this->conn = $conn; } @@ -26,7 +29,7 @@ class MDB2SchemaManager { * * TODO: write more documentation */ - public function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { + public function getDbStructure( $file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) { $sm = $this->conn->getSchemaManager(); return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm); @@ -40,7 +43,7 @@ class MDB2SchemaManager { * TODO: write more documentation */ public function createDbFromStructure( $file ) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $toSchema = $schemaReader->loadSchemaFromFile($file); return $this->executeSchemaChange($toSchema); } @@ -54,7 +57,7 @@ class MDB2SchemaManager { $sm = $this->conn->getSchemaManager(); $fromSchema = $sm->createSchema(); - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $toSchema = $schemaReader->loadSchemaFromFile($file); // remove tables we don't know about @@ -100,7 +103,7 @@ class MDB2SchemaManager { * @param string $file the xml file describing the tables */ public function removeDBStructure($file) { - $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); + $schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $this->conn->getDatabasePlatform()); $fromSchema = $schemaReader->loadSchemaFromFile($file); $toSchema = clone $fromSchema; foreach($toSchema->getTables() as $table) { -- cgit v1.2.3 From 5ffb8fac24801800048c4c2e68c0f8fb6582769c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 2 Aug 2013 16:02:33 +0200 Subject: Use function to create schema manager --- lib/db.php | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index b92f7820f31..a14fab0c774 100644 --- a/lib/db.php +++ b/lib/db.php @@ -194,6 +194,27 @@ class OC_DB { return true; } + /** + * get the database connection object + * + * @return \Doctrine\DBAL\Connection + */ + private static function getConnection() + { + self::connect(); + return self::$connection; + } + + /** + * 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 @@ -388,7 +409,7 @@ 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 @@ -396,9 +417,8 @@ class OC_DB { * TODO: write more documentation */ public static function getDbStructure( $file, $mode=MDB2_SCHEMA_DUMP_STRUCTURE) { - self::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); - return $schema->getDbStructure($file); + $schemaManager = self::getMDB2SchemaManager(); + return $schemaManager->getDbStructure($file); } /** @@ -409,23 +429,21 @@ class OC_DB { * TODO: write more documentation */ public static function createDbFromStructure( $file ) { - self::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); - $result = $schema->createDbFromStructure($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::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); + $schemaManager = self::getMDB2SchemaManager(); try { - $result = $schema->updateDbFromStructure($file); + $result = $schemaManager->updateDbFromStructure($file); } catch (Exception $e) { OC_Log::write('core', 'Failed to update database structure ('.$e.')', OC_Log::FATAL); throw $e; @@ -604,9 +622,8 @@ class OC_DB { * @param string $tableName the table to drop */ public static function dropTable($tableName) { - self::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); - $schema->dropTable($tableName); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->dropTable($tableName); } /** @@ -614,9 +631,8 @@ class OC_DB { * @param string $file the xml file describing the tables */ public static function removeDBStructure($file) { - self::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); - $schema->removeDBStructure($file); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->removeDBStructure($file); } /** @@ -624,9 +640,8 @@ class OC_DB { * @param $file string path to the MDB2 xml db export file */ public static function replaceDB( $file ) { - self::connectDoctrine(); - $schema = new \OC\DB\MDB2SchemaManager(self::$connection); - $schema->replaceDB($file); + $schemaManager = self::getMDB2SchemaManager(); + $schemaManager->replaceDB($file); } /** -- cgit v1.2.3 From fd317f599bd1d5fe2ae0260f3dec476a6efd5fdd Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 25 Feb 2013 22:59:06 +0100 Subject: Simplify OC_DB transaction functions --- lib/db.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib') diff --git a/lib/db.php b/lib/db.php index dd48c329490..311cdcfecf5 100644 --- a/lib/db.php +++ b/lib/db.php @@ -56,7 +56,6 @@ class OC_DB { */ static private $DOCTRINE=null; - static private $inTransaction=false; static private $prefix=null; static private $type=null; @@ -624,27 +623,18 @@ class OC_DB { /** * Start a transaction - * @return bool */ public static function beginTransaction() { self::connect(); self::$connection->beginTransaction(); - self::$inTransaction=true; - return true; } /** * Commit the database changes done during a transaction that is in progress - * @return bool */ public static function commit() { self::connect(); - if(!self::$inTransaction) { - return false; - } self::$connection->commit(); - self::$inTransaction=false; - return true; } /** -- cgit v1.2.3 From 3534c3b3735242afa5c991417027a8c8e41e6465 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 3 Aug 2013 21:59:32 +0200 Subject: add reveal mimetype --- lib/mimetypes.list.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') 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' ); -- cgit v1.2.3 From e03d9e3aa07300aaee5ccad0d8e2b5352d107aee Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 4 Aug 2013 02:48:00 +0200 Subject: Port log level filtering from OC_Log_Owncloud to OC_Log_Syslog. --- lib/log/syslog.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/log/syslog.php b/lib/log/syslog.php index d1fb28d8b0a..a28255ed10e 100644 --- a/lib/log/syslog.php +++ b/lib/log/syslog.php @@ -31,7 +31,10 @@ class OC_Log_Syslog { * @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); + } } } -- cgit v1.2.3 From b716d035c32f5b04bfc398598ddf687a19a21c7d Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sun, 4 Aug 2013 22:58:40 +0200 Subject: fixing PHPDoc --- lib/log/syslog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/log/syslog.php b/lib/log/syslog.php index a28255ed10e..c98deab7109 100644 --- a/lib/log/syslog.php +++ b/lib/log/syslog.php @@ -28,7 +28,7 @@ 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) { $minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR); -- cgit v1.2.3 From 33d78ab9c719ac0677651cfe76bf6a2aa3073241 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sun, 4 Aug 2013 23:13:34 +0200 Subject: fixing PHPDoc --- lib/log/owncloud.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index e7246726d40..d16b9537a16 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -44,7 +44,7 @@ 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); @@ -63,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) { -- cgit v1.2.3 From 464afb5ecac95124c55b6a8af38410732a76275c Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 5 Aug 2013 13:51:45 +0200 Subject: use isset to prevent undefined index --- lib/files/cache/scanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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']; } -- cgit v1.2.3