Plugin Directory

Changeset 574110


Ignore:
Timestamp:
07/18/2012 02:05:12 PM (14 years ago)
Author:
kaore
Message:

nothing much

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cibul-event-rendering/trunk/CibulPluginCache.class.php

    r572928 r574110  
    33  class CibulPluginCache
    44  {
    5     public function __construct($options)
     5    public function __construct($tableName, $dbHandler)
    66    {
    7       $this->options = $options;
     7      $this->tableName = $tableName;
     8
     9      $this->dbHandler = $dbHandler;
    810    }
    911
    1012    public function getRendersByLink($links, $type = '')
    1113    {
    12       global $wpdb;
    13 
    1414      if (!is_array($links)) $links = array($links);
    1515
    1616      if (empty($links)) return array();
    1717
    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'");
    1919
    2020      $rendersByLink = array();
     
    2222      if (!empty($result)) foreach ($result as $row)
    2323      {
    24         $rendersByLink[$row->link] = $row->html;
     24        if ($row['html']) $rendersByLink[$row['link']] = $row['html'];
    2525      }
    2626
     
    3030    public function loadRendersByLink($rendersByLink, $type = '')
    3131    {
    32       global $wpdb;
    33 
    3432      // update pre-existing renders
    3533
    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);
    3737
    3838      foreach ($rendersByLinkToUpdate as $link => $renderToUpdate)
    3939      {
    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");
    4141      }
    4242
     
    4949      foreach ($rendersByLinkToInsert as $link => $renderToInsert)
    5050      {
    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")));
    5252      }
    5353    }
     
    5555    public function createTable()
    5656    {
    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) );");
    6658    }
     59   
    6760
    6861    public function clear()
    6962    {
    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 ");
    7564
    7665      $this->createTable();
Note: See TracChangeset for help on using the changeset viewer.