From 50dfe471d0626998a72af79c031b20ec3ab409d1 Mon Sep 17 00:00:00 2001 From: aude Date: Tue, 4 Dec 2012 13:09:00 +0000 Subject: [PATCH] add method to check if ORMTable exists Change-Id: I7ef34545a9b4cfa6ed8bcdd302ad49faa7747974 --- includes/db/IORMTable.php | 9 +++++++++ includes/db/ORMTable.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/includes/db/IORMTable.php b/includes/db/IORMTable.php index be4036ea0e..dfc5916c44 100644 --- a/includes/db/IORMTable.php +++ b/includes/db/IORMTable.php @@ -229,6 +229,15 @@ interface IORMTable { */ public function has( array $conditions = array() ); + /** + * Checks if the table exists + * + * @since 1.21 + * + * @return boolean + */ + public function exists(); + /** * Returns the amount of matching records. * Condition field names get prefixed. diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php index a2ef9445cb..e3c8aa7a20 100644 --- a/includes/db/ORMTable.php +++ b/includes/db/ORMTable.php @@ -299,6 +299,21 @@ abstract class ORMTable extends DBAccessBase implements IORMTable { return $this->selectRow( array( 'id' ), $conditions ) !== false; } + /** + * Checks if the table exists + * + * @since 1.21 + * + * @return boolean + */ + public function exists() { + $dbr = $this->getReadDbConnection(); + $exists = $dbr->tableExists( $this->getName() ); + $this->releaseConnection( $dbr ); + + return $exists; + } + /** * Returns the amount of matching records. * Condition field names get prefixed. -- 2.20.1