Changeset 574110
- Timestamp:
- 07/18/2012 02:05:12 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cibul-event-rendering/trunk/CibulPluginCache.class.php
r572928 r574110 3 3 class CibulPluginCache 4 4 { 5 public function __construct($ options)5 public function __construct($tableName, $dbHandler) 6 6 { 7 $this->options = $options; 7 $this->tableName = $tableName; 8 9 $this->dbHandler = $dbHandler; 8 10 } 9 11 10 12 public function getRendersByLink($links, $type = '') 11 13 { 12 global $wpdb;13 14 14 if (!is_array($links)) $links = array($links); 15 15 16 16 if (empty($links)) return array(); 17 17 18 $result = $ wpdb->get_results("SELECT link, html FROM " . $this->options['cacheTableName'] . "WHERE link IN ('" . implode("','", $links) . "') AND type = '$type'");18 $result = $this->dbHandler->getQueryResults("SELECT link, html FROM {$this->tableName} WHERE link IN ('" . implode("','", $links) . "') AND type = '$type'"); 19 19 20 20 $rendersByLink = array(); … … 22 22 if (!empty($result)) foreach ($result as $row) 23 23 { 24 $rendersByLink[$row->link] = $row->html;24 if ($row['html']) $rendersByLink[$row['link']] = $row['html']; 25 25 } 26 26 … … 30 30 public function loadRendersByLink($rendersByLink, $type = '') 31 31 { 32 global $wpdb;33 34 32 // update pre-existing renders 35 33 36 $rendersByLinkToUpdate = array_intersect_key($this->getRendersByLink($rendersByLink, $type), $rendersByLink); 34 $fromDb = $this->getRendersByLink(array_keys($rendersByLink), $type); 35 36 $rendersByLinkToUpdate = array_intersect_key($fromDb, $rendersByLink); 37 37 38 38 foreach ($rendersByLinkToUpdate as $link => $renderToUpdate) 39 39 { 40 $ wpdb->query('UPDATE ' . $this->options['cacheTableName'] . ' SET html = ' . $renderToUpdate . ' WHERE link = ' . $link . ' AND type = ' . $type);40 $this->dbHandler->query("UPDATE {$this->tableName} SET html = $renderToUpdate WHERE link = $link AND type = $type"); 41 41 } 42 42 … … 49 49 foreach ($rendersByLinkToInsert as $link => $renderToInsert) 50 50 { 51 $ wpdb->insert($this->options['cacheTableName'], array('html' => $renderToInsert, 'link' => $link, 'type' => $type, 'created_at' => $now->format("Y-m-d H:i:s")));51 $this->dbHandler->insert($this->tableName, array('html' => $renderToInsert, 'link' => $link, 'type' => $type, 'created_at' => $now->format("Y-m-d H:i:s"))); 52 52 } 53 53 } … … 55 55 public function createTable() 56 56 { 57 global $wpdb; 58 59 $tableName = $this->options['cacheTableName']; 60 61 $sql = "CREATE TABLE $tableName (id mediumint(9) NOT NULL AUTO_INCREMENT, created_at datetime NOT NULL, link VARCHAR(255) NOT NULL, type VARCHAR(32), html text NOT NULL, UNIQUE KEY id (id) );"; 62 63 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 64 65 dbDelta($sql); 57 $this->dbHandler->create("CREATE TABLE {$this->tableName} (id mediumint(9) NOT NULL AUTO_INCREMENT, created_at datetime NOT NULL, link VARCHAR(255) NOT NULL, type VARCHAR(32), html text NOT NULL, UNIQUE KEY id (id) );"); 66 58 } 59 67 60 68 61 public function clear() 69 62 { 70 global $wpdb; 71 72 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 73 74 $wpdb->query("DROP TABLE " . $this->options['cacheTableName']); 63 $this->dbHandler->query("DROP TABLE $this->tableName "); 75 64 76 65 $this->createTable();
Note: See TracChangeset
for help on using the changeset viewer.