project = $this->_project; $cache->githash = $blob->hash; $blob->title = IDF_Commit::toUTF8($blob->title); $cache->content = IDF_Commit::toUTF8($blob->date) . chr(31) . IDF_Commit::toUTF8($blob->author) . chr(31) . IDF_Commit::toUTF8($blob->title); $sql = new Pluf_SQL('project=%s AND githash=%s', array($this->_project->id, $blob->hash)); if (0 == Pluf::factory(__CLASS__)->getCount(array('filter' => $sql->gen()))) { $cache->create(); } } } /** * Get for the given hashes the corresponding date, title and * author. * * It returns an hash indexed array with the info. If an hash is * not in the db, the key is not set. * * Note that the hashes must always come from internal tools. * * @param array Hashes to get info * @return array Blob infos */ public function retrieve($hashes) { $res = array(); $db = $this->getDbConnection(); $hashes = array_map(array($db, 'esc'), $hashes); $sql = new Pluf_SQL('project=%s AND githash IN ('.implode(', ', $hashes).')', array($this->_project->id)); foreach (Pluf::factory(__CLASS__)->getList(array('filter' => $sql->gen())) as $blob) { $tmp = explode(chr(31), $blob->content, 3); // sometimes the title might be empty if (!isset($tmp[2])) $tmp[2] = ''; $res[$blob->githash] = (object) array( 'hash' => $blob->githash, 'date' => $tmp[0], 'title' => $tmp[2], 'author' => $tmp[1], ); } return $res; } /** * The storage is composed of 4 columns, id, project, hash and the * raw data. */ function init() { $this->_a['table'] = 'idf_scm_cache_git'; $this->_a['model'] = __CLASS__; $this->_a['cols'] = array( // It is mandatory to have an "id" column. 'id' => array( 'type' => 'Pluf_DB_Field_Sequence', 'blank' => true, ), 'project' => array( 'type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'IDF_Project', 'blank' => false, ), 'githash' => array( 'type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 40, 'index' => true, ), 'content' => array( 'type' => 'Pluf_DB_Field_Text', 'blank' => false, ), ); } }