PageRenderTime 64ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/core/Db/Schema/Myisam.php

https://github.com/quarkness/piwik
PHP | 569 lines | 442 code | 48 blank | 79 comment | 14 complexity | 444c7e17882f3b76038db72fd0b17d98 MD5 | raw file
  1. <?php
  2. /**
  3. * Piwik - Open source web analytics
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. * @version $Id$
  8. *
  9. * @category Piwik
  10. * @package Piwik
  11. */
  12. /**
  13. * MySQL schema
  14. *
  15. * @package Piwik
  16. * @subpackage Piwik_Db
  17. */
  18. class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
  19. {
  20. /**
  21. * Is this MySQL storage engine available?
  22. *
  23. * @param string $engineName
  24. * @return bool True if available and enabled; false otherwise
  25. */
  26. static private function hasStorageEngine($engineName)
  27. {
  28. $db = Zend_Registry::get('db');
  29. $allEngines = $db->fetchAssoc('SHOW ENGINES');
  30. if(key_exists($engineName, $allEngines))
  31. {
  32. $support = $allEngines[$engineName]['Support'];
  33. return $support == 'DEFAULT' || $support == 'YES';
  34. }
  35. return false;
  36. }
  37. /**
  38. * Is this schema available?
  39. *
  40. * @return bool True if schema is available; false otherwise
  41. */
  42. static public function isAvailable()
  43. {
  44. return self::hasStorageEngine('MyISAM');
  45. }
  46. /**
  47. * Get the SQL to create Piwik tables
  48. *
  49. * @return array of strings containing SQL
  50. */
  51. public function getTablesCreateSql()
  52. {
  53. $config = Zend_Registry::get('config');
  54. $prefixTables = $config->database->tables_prefix;
  55. $tables = array(
  56. 'user' => "CREATE TABLE {$prefixTables}user (
  57. login VARCHAR(100) NOT NULL,
  58. password CHAR(32) NOT NULL,
  59. alias VARCHAR(45) NOT NULL,
  60. email VARCHAR(100) NOT NULL,
  61. token_auth CHAR(32) NOT NULL,
  62. date_registered TIMESTAMP NULL,
  63. PRIMARY KEY(login),
  64. UNIQUE KEY uniq_keytoken(token_auth)
  65. ) DEFAULT CHARSET=utf8
  66. ",
  67. 'access' => "CREATE TABLE {$prefixTables}access (
  68. login VARCHAR(100) NOT NULL,
  69. idsite INTEGER UNSIGNED NOT NULL,
  70. access VARCHAR(10) NULL,
  71. PRIMARY KEY(login, idsite)
  72. ) DEFAULT CHARSET=utf8
  73. ",
  74. 'site' => "CREATE TABLE {$prefixTables}site (
  75. idsite INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  76. name VARCHAR(90) NOT NULL,
  77. main_url VARCHAR(255) NOT NULL,
  78. ts_created TIMESTAMP NULL,
  79. ecommerce TINYINT DEFAULT 0,
  80. timezone VARCHAR( 50 ) NOT NULL,
  81. currency CHAR( 3 ) NOT NULL,
  82. excluded_ips TEXT NOT NULL,
  83. excluded_parameters VARCHAR ( 255 ) NOT NULL,
  84. `group` VARCHAR(250) NOT NULL,
  85. PRIMARY KEY(idsite)
  86. ) DEFAULT CHARSET=utf8
  87. ",
  88. 'site_url' => "CREATE TABLE {$prefixTables}site_url (
  89. idsite INTEGER(10) UNSIGNED NOT NULL,
  90. url VARCHAR(255) NOT NULL,
  91. PRIMARY KEY(idsite, url)
  92. ) DEFAULT CHARSET=utf8
  93. ",
  94. 'goal' => " CREATE TABLE `{$prefixTables}goal` (
  95. `idsite` int(11) NOT NULL,
  96. `idgoal` int(11) NOT NULL,
  97. `name` varchar(50) NOT NULL,
  98. `match_attribute` varchar(20) NOT NULL,
  99. `pattern` varchar(255) NOT NULL,
  100. `pattern_type` varchar(10) NOT NULL,
  101. `case_sensitive` tinyint(4) NOT NULL,
  102. `allow_multiple` tinyint(4) NOT NULL,
  103. `revenue` float NOT NULL,
  104. `deleted` tinyint(4) NOT NULL default '0',
  105. PRIMARY KEY (`idsite`,`idgoal`)
  106. ) DEFAULT CHARSET=utf8
  107. ",
  108. 'logger_message' => "CREATE TABLE {$prefixTables}logger_message (
  109. idlogger_message INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  110. timestamp TIMESTAMP NULL,
  111. message TEXT NULL,
  112. PRIMARY KEY(idlogger_message)
  113. ) DEFAULT CHARSET=utf8
  114. ",
  115. 'logger_api_call' => "CREATE TABLE {$prefixTables}logger_api_call (
  116. idlogger_api_call INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  117. class_name VARCHAR(255) NULL,
  118. method_name VARCHAR(255) NULL,
  119. parameter_names_default_values TEXT NULL,
  120. parameter_values TEXT NULL,
  121. execution_time FLOAT NULL,
  122. caller_ip VARBINARY(16) NOT NULL,
  123. timestamp TIMESTAMP NULL,
  124. returned_value TEXT NULL,
  125. PRIMARY KEY(idlogger_api_call)
  126. ) DEFAULT CHARSET=utf8
  127. ",
  128. 'logger_error' => "CREATE TABLE {$prefixTables}logger_error (
  129. idlogger_error INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  130. timestamp TIMESTAMP NULL,
  131. message TEXT NULL,
  132. errno INTEGER UNSIGNED NULL,
  133. errline INTEGER UNSIGNED NULL,
  134. errfile VARCHAR(255) NULL,
  135. backtrace TEXT NULL,
  136. PRIMARY KEY(idlogger_error)
  137. ) DEFAULT CHARSET=utf8
  138. ",
  139. 'logger_exception' => "CREATE TABLE {$prefixTables}logger_exception (
  140. idlogger_exception INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  141. timestamp TIMESTAMP NULL,
  142. message TEXT NULL,
  143. errno INTEGER UNSIGNED NULL,
  144. errline INTEGER UNSIGNED NULL,
  145. errfile VARCHAR(255) NULL,
  146. backtrace TEXT NULL,
  147. PRIMARY KEY(idlogger_exception)
  148. ) DEFAULT CHARSET=utf8
  149. ",
  150. 'log_action' => "CREATE TABLE {$prefixTables}log_action (
  151. idaction INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  152. name TEXT,
  153. hash INTEGER(10) UNSIGNED NOT NULL,
  154. type TINYINT UNSIGNED NULL,
  155. PRIMARY KEY(idaction),
  156. INDEX index_type_hash (type, hash)
  157. ) DEFAULT CHARSET=utf8
  158. ",
  159. 'log_visit' => "CREATE TABLE {$prefixTables}log_visit (
  160. idvisit INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  161. idsite INTEGER(10) UNSIGNED NOT NULL,
  162. idvisitor BINARY(8) NOT NULL,
  163. visitor_localtime TIME NOT NULL,
  164. visitor_returning TINYINT(1) NOT NULL,
  165. visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL,
  166. visitor_days_since_last SMALLINT(5) UNSIGNED NOT NULL,
  167. visitor_days_since_order SMALLINT(5) UNSIGNED NOT NULL,
  168. visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL,
  169. visit_first_action_time DATETIME NOT NULL,
  170. visit_last_action_time DATETIME NOT NULL,
  171. visit_exit_idaction_url INTEGER(11) UNSIGNED NOT NULL,
  172. visit_exit_idaction_name INTEGER(11) UNSIGNED NOT NULL,
  173. visit_entry_idaction_url INTEGER(11) UNSIGNED NOT NULL,
  174. visit_entry_idaction_name INTEGER(11) UNSIGNED NOT NULL,
  175. visit_total_actions SMALLINT(5) UNSIGNED NOT NULL,
  176. visit_total_time SMALLINT(5) UNSIGNED NOT NULL,
  177. visit_goal_converted TINYINT(1) NOT NULL,
  178. visit_goal_buyer TINYINT(1) NOT NULL,
  179. referer_type TINYINT(1) UNSIGNED NULL,
  180. referer_name VARCHAR(70) NULL,
  181. referer_url TEXT NOT NULL,
  182. referer_keyword VARCHAR(255) NULL,
  183. config_id BINARY(8) NOT NULL,
  184. config_os CHAR(3) NOT NULL,
  185. config_browser_name VARCHAR(10) NOT NULL,
  186. config_browser_version VARCHAR(20) NOT NULL,
  187. config_resolution VARCHAR(9) NOT NULL,
  188. config_pdf TINYINT(1) NOT NULL,
  189. config_flash TINYINT(1) NOT NULL,
  190. config_java TINYINT(1) NOT NULL,
  191. config_director TINYINT(1) NOT NULL,
  192. config_quicktime TINYINT(1) NOT NULL,
  193. config_realplayer TINYINT(1) NOT NULL,
  194. config_windowsmedia TINYINT(1) NOT NULL,
  195. config_gears TINYINT(1) NOT NULL,
  196. config_silverlight TINYINT(1) NOT NULL,
  197. config_cookie TINYINT(1) NOT NULL,
  198. location_ip VARBINARY(16) NOT NULL,
  199. location_browser_lang VARCHAR(20) NOT NULL,
  200. location_country CHAR(3) NOT NULL,
  201. location_continent CHAR(3) NOT NULL,
  202. custom_var_k1 VARCHAR(200) DEFAULT NULL,
  203. custom_var_v1 VARCHAR(200) DEFAULT NULL,
  204. custom_var_k2 VARCHAR(200) DEFAULT NULL,
  205. custom_var_v2 VARCHAR(200) DEFAULT NULL,
  206. custom_var_k3 VARCHAR(200) DEFAULT NULL,
  207. custom_var_v3 VARCHAR(200) DEFAULT NULL,
  208. custom_var_k4 VARCHAR(200) DEFAULT NULL,
  209. custom_var_v4 VARCHAR(200) DEFAULT NULL,
  210. custom_var_k5 VARCHAR(200) DEFAULT NULL,
  211. custom_var_v5 VARCHAR(200) DEFAULT NULL,
  212. PRIMARY KEY(idvisit),
  213. INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time),
  214. INDEX index_idsite_datetime (idsite, visit_last_action_time),
  215. INDEX index_idsite_idvisitor (idsite, idvisitor)
  216. ) DEFAULT CHARSET=utf8
  217. ",
  218. 'log_conversion_item' => "CREATE TABLE `{$prefixTables}log_conversion_item` (
  219. idsite int(10) UNSIGNED NOT NULL,
  220. idvisitor BINARY(8) NOT NULL,
  221. server_time DATETIME NOT NULL,
  222. idvisit INTEGER(10) UNSIGNED NOT NULL,
  223. idorder varchar(100) NOT NULL,
  224. idaction_sku INTEGER(10) UNSIGNED NOT NULL,
  225. idaction_name INTEGER(10) UNSIGNED NOT NULL,
  226. idaction_category INTEGER(10) UNSIGNED NOT NULL,
  227. idaction_category2 INTEGER(10) UNSIGNED NOT NULL,
  228. idaction_category3 INTEGER(10) UNSIGNED NOT NULL,
  229. idaction_category4 INTEGER(10) UNSIGNED NOT NULL,
  230. idaction_category5 INTEGER(10) UNSIGNED NOT NULL,
  231. price FLOAT NOT NULL,
  232. quantity INTEGER(10) UNSIGNED NOT NULL,
  233. deleted TINYINT(1) UNSIGNED NOT NULL,
  234. PRIMARY KEY(idvisit, idorder, idaction_sku),
  235. INDEX index_idsite_servertime ( idsite, server_time )
  236. ) DEFAULT CHARSET=utf8
  237. ",
  238. 'log_conversion' => "CREATE TABLE `{$prefixTables}log_conversion` (
  239. idvisit int(10) unsigned NOT NULL,
  240. idsite int(10) unsigned NOT NULL,
  241. idvisitor BINARY(8) NOT NULL,
  242. server_time datetime NOT NULL,
  243. idaction_url int(11) default NULL,
  244. idlink_va int(11) default NULL,
  245. referer_visit_server_date date default NULL,
  246. referer_type int(10) unsigned default NULL,
  247. referer_name varchar(70) default NULL,
  248. referer_keyword varchar(255) default NULL,
  249. visitor_returning tinyint(1) NOT NULL,
  250. visitor_count_visits SMALLINT(5) UNSIGNED NOT NULL,
  251. visitor_days_since_first SMALLINT(5) UNSIGNED NOT NULL,
  252. visitor_days_since_order SMALLINT(5) UNSIGNED NOT NULL,
  253. location_country char(3) NOT NULL,
  254. location_continent char(3) NOT NULL,
  255. url text NOT NULL,
  256. idgoal int(10) NOT NULL,
  257. buster int unsigned NOT NULL,
  258. idorder varchar(100) default NULL,
  259. items SMALLINT UNSIGNED DEFAULT NULL,
  260. revenue float default NULL,
  261. revenue_subtotal float default NULL,
  262. revenue_tax float default NULL,
  263. revenue_shipping float default NULL,
  264. revenue_discount float default NULL,
  265. custom_var_k1 VARCHAR(200) DEFAULT NULL,
  266. custom_var_v1 VARCHAR(200) DEFAULT NULL,
  267. custom_var_k2 VARCHAR(200) DEFAULT NULL,
  268. custom_var_v2 VARCHAR(200) DEFAULT NULL,
  269. custom_var_k3 VARCHAR(200) DEFAULT NULL,
  270. custom_var_v3 VARCHAR(200) DEFAULT NULL,
  271. custom_var_k4 VARCHAR(200) DEFAULT NULL,
  272. custom_var_v4 VARCHAR(200) DEFAULT NULL,
  273. custom_var_k5 VARCHAR(200) DEFAULT NULL,
  274. custom_var_v5 VARCHAR(200) DEFAULT NULL,
  275. PRIMARY KEY (idvisit, idgoal, buster),
  276. UNIQUE KEY unique_idsite_idorder (idsite, idorder),
  277. INDEX index_idsite_datetime ( idsite, server_time )
  278. ) DEFAULT CHARSET=utf8
  279. ",
  280. 'log_link_visit_action' => "CREATE TABLE {$prefixTables}log_link_visit_action (
  281. idlink_va INTEGER(11) NOT NULL AUTO_INCREMENT,
  282. idsite int(10) UNSIGNED NOT NULL,
  283. idvisitor BINARY(8) NOT NULL,
  284. server_time DATETIME NOT NULL,
  285. idvisit INTEGER(10) UNSIGNED NOT NULL,
  286. idaction_url INTEGER(10) UNSIGNED NOT NULL,
  287. idaction_url_ref INTEGER(10) UNSIGNED NOT NULL,
  288. idaction_name INTEGER(10) UNSIGNED,
  289. idaction_name_ref INTEGER(10) UNSIGNED NOT NULL,
  290. time_spent_ref_action INTEGER(10) UNSIGNED NOT NULL,
  291. custom_var_k1 VARCHAR(200) DEFAULT NULL,
  292. custom_var_v1 VARCHAR(200) DEFAULT NULL,
  293. custom_var_k2 VARCHAR(200) DEFAULT NULL,
  294. custom_var_v2 VARCHAR(200) DEFAULT NULL,
  295. custom_var_k3 VARCHAR(200) DEFAULT NULL,
  296. custom_var_v3 VARCHAR(200) DEFAULT NULL,
  297. custom_var_k4 VARCHAR(200) DEFAULT NULL,
  298. custom_var_v4 VARCHAR(200) DEFAULT NULL,
  299. custom_var_k5 VARCHAR(200) DEFAULT NULL,
  300. custom_var_v5 VARCHAR(200) DEFAULT NULL,
  301. PRIMARY KEY(idlink_va),
  302. INDEX index_idvisit(idvisit),
  303. INDEX index_idsite_servertime ( idsite, server_time )
  304. ) DEFAULT CHARSET=utf8
  305. ",
  306. 'log_profiling' => "CREATE TABLE {$prefixTables}log_profiling (
  307. query TEXT NOT NULL,
  308. count INTEGER UNSIGNED NULL,
  309. sum_time_ms FLOAT NULL,
  310. UNIQUE KEY query(query(100))
  311. ) DEFAULT CHARSET=utf8
  312. ",
  313. 'option' => "CREATE TABLE `{$prefixTables}option` (
  314. option_name VARCHAR( 255 ) NOT NULL,
  315. option_value LONGTEXT NOT NULL,
  316. autoload TINYINT NOT NULL DEFAULT '1',
  317. PRIMARY KEY ( option_name ),
  318. INDEX autoload( autoload )
  319. ) DEFAULT CHARSET=utf8
  320. ",
  321. 'session' => "CREATE TABLE {$prefixTables}session (
  322. id CHAR(32) NOT NULL,
  323. modified INTEGER,
  324. lifetime INTEGER,
  325. data TEXT,
  326. PRIMARY KEY ( id )
  327. ) DEFAULT CHARSET=utf8
  328. ",
  329. 'archive_numeric' => "CREATE TABLE {$prefixTables}archive_numeric (
  330. idarchive INTEGER UNSIGNED NOT NULL,
  331. name VARCHAR(255) NOT NULL,
  332. idsite INTEGER UNSIGNED NULL,
  333. date1 DATE NULL,
  334. date2 DATE NULL,
  335. period TINYINT UNSIGNED NULL,
  336. ts_archived DATETIME NULL,
  337. value FLOAT NULL,
  338. PRIMARY KEY(idarchive, name),
  339. INDEX index_idsite_dates_period(idsite, date1, date2, period, ts_archived),
  340. INDEX index_period_archived(period, ts_archived)
  341. ) DEFAULT CHARSET=utf8
  342. ",
  343. 'archive_blob' => "CREATE TABLE {$prefixTables}archive_blob (
  344. idarchive INTEGER UNSIGNED NOT NULL,
  345. name VARCHAR(255) NOT NULL,
  346. idsite INTEGER UNSIGNED NULL,
  347. date1 DATE NULL,
  348. date2 DATE NULL,
  349. period TINYINT UNSIGNED NULL,
  350. ts_archived DATETIME NULL,
  351. value MEDIUMBLOB NULL,
  352. PRIMARY KEY(idarchive, name),
  353. INDEX index_period_archived(period, ts_archived)
  354. ) DEFAULT CHARSET=utf8
  355. ",
  356. );
  357. return $tables;
  358. }
  359. /**
  360. * Get the SQL to create a specific Piwik table
  361. *
  362. * @param string $tableName
  363. * @return string SQL
  364. */
  365. public function getTableCreateSql( $tableName )
  366. {
  367. $tables = Piwik::getTablesCreateSql();
  368. if(!isset($tables[$tableName]))
  369. {
  370. throw new Exception("The table '$tableName' SQL creation code couldn't be found.");
  371. }
  372. return $tables[$tableName];
  373. }
  374. /**
  375. * Names of all the prefixed tables in piwik
  376. * Doesn't use the DB
  377. *
  378. * @return array Table names
  379. */
  380. public function getTablesNames()
  381. {
  382. $aTables = array_keys($this->getTablesCreateSql());
  383. $config = Zend_Registry::get('config');
  384. $prefixTables = $config->database->tables_prefix;
  385. $return = array();
  386. foreach($aTables as $table)
  387. {
  388. $return[] = $prefixTables.$table;
  389. }
  390. return $return;
  391. }
  392. private $tablesInstalled = null;
  393. /**
  394. * Get list of tables installed
  395. *
  396. * @param bool $forceReload Invalidate cache
  397. * @param string $idSite
  398. * @return array Tables installed
  399. */
  400. public function getTablesInstalled($forceReload = true)
  401. {
  402. if(is_null($this->tablesInstalled)
  403. || $forceReload === true)
  404. {
  405. $db = Zend_Registry::get('db');
  406. $config = Zend_Registry::get('config');
  407. $prefixTables = $config->database->tables_prefix;
  408. // '_' matches any character; force it to be literal
  409. $prefixTables = str_replace('_', '\_', $prefixTables);
  410. $allTables = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."%'");
  411. // all the tables to be installed
  412. $allMyTables = $this->getTablesNames();
  413. // we get the intersection between all the tables in the DB and the tables to be installed
  414. $tablesInstalled = array_intersect($allMyTables, $allTables);
  415. // at this point we have only the piwik tables which is good
  416. // but we still miss the piwik generated tables (using the class Piwik_TablePartitioning)
  417. $allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_numeric%'");
  418. $allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_blob%'");
  419. $allTablesReallyInstalled = array_merge($tablesInstalled, $allArchiveNumeric, $allArchiveBlob);
  420. $this->tablesInstalled = $allTablesReallyInstalled;
  421. }
  422. return $this->tablesInstalled;
  423. }
  424. /**
  425. * Do tables exist?
  426. *
  427. * @return bool True if tables exist; false otherwise
  428. */
  429. public function hasTables()
  430. {
  431. return count($this->getTablesInstalled()) != 0;
  432. }
  433. /**
  434. * Create database
  435. *
  436. * @param string $dbName
  437. */
  438. public function createDatabase( $dbName = null )
  439. {
  440. if(is_null($dbName))
  441. {
  442. $dbName = Zend_Registry::get('config')->database->dbname;
  443. }
  444. Piwik_Exec("CREATE DATABASE IF NOT EXISTS ".$dbName." DEFAULT CHARACTER SET utf8");
  445. }
  446. /**
  447. * Drop database
  448. */
  449. public function dropDatabase()
  450. {
  451. $dbName = Zend_Registry::get('config')->database->dbname;
  452. Piwik_Exec("DROP DATABASE IF EXISTS " . $dbName);
  453. }
  454. /**
  455. * Create all tables
  456. */
  457. public function createTables()
  458. {
  459. $db = Zend_Registry::get('db');
  460. $config = Zend_Registry::get('config');
  461. $prefixTables = $config->database->tables_prefix;
  462. $tablesAlreadyInstalled = $this->getTablesInstalled();
  463. $tablesToCreate = $this->getTablesCreateSql();
  464. unset($tablesToCreate['archive_blob']);
  465. unset($tablesToCreate['archive_numeric']);
  466. foreach($tablesToCreate as $tableName => $tableSql)
  467. {
  468. $tableName = $prefixTables . $tableName;
  469. if(!in_array($tableName, $tablesAlreadyInstalled))
  470. {
  471. $db->query( $tableSql );
  472. }
  473. }
  474. }
  475. /**
  476. * Creates an entry in the User table for the "anonymous" user.
  477. */
  478. public function createAnonymousUser()
  479. {
  480. // The anonymous user is the user that is assigned by default
  481. // note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
  482. $db = Zend_Registry::get('db');
  483. $db->query("INSERT INTO ". Piwik_Common::prefixTable("user") . "
  484. VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', 'anonymous', '".Piwik_Date::factory('now')->getDatetime()."' );" );
  485. }
  486. /**
  487. * Truncate all tables
  488. */
  489. public function truncateAllTables()
  490. {
  491. $tablesAlreadyInstalled = $this->getTablesInstalled($forceReload = true);
  492. foreach($tablesAlreadyInstalled as $table)
  493. {
  494. Piwik_Query("TRUNCATE `$table`");
  495. }
  496. }
  497. /**
  498. * Drop specific tables
  499. *
  500. * @param array $doNotDelete Names of tables to not delete
  501. */
  502. public function dropTables( $doNotDelete = array() )
  503. {
  504. $tablesAlreadyInstalled = $this->getTablesInstalled();
  505. $db = Zend_Registry::get('db');
  506. $doNotDeletePattern = '/('.implode('|',$doNotDelete).')/';
  507. foreach($tablesAlreadyInstalled as $tableName)
  508. {
  509. if( count($doNotDelete) == 0
  510. || (!in_array($tableName,$doNotDelete)
  511. && !preg_match($doNotDeletePattern,$tableName)
  512. )
  513. )
  514. {
  515. $db->query("DROP TABLE `$tableName`");
  516. }
  517. }
  518. }
  519. }