From: aude Date: Tue, 4 Dec 2012 13:09:00 +0000 (+0000) Subject: add method to check if ORMTable exists X-Git-Tag: 1.31.0-rc.0~21434^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=50dfe471d0626998a72af79c031b20ec3ab409d1;p=lhc%2Fweb%2Fwiklou.git add method to check if ORMTable exists Change-Id: I7ef34545a9b4cfa6ed8bcdd302ad49faa7747974 --- 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.