_a['table'] = 'idf_wikiresourcerevs'; $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, ), 'wikiresource' => array( 'type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'IDF_Wiki_Resource', 'blank' => false, 'verbose' => __('resource'), 'relate_name' => 'revisions', ), 'is_head' => array( 'type' => 'Pluf_DB_Field_Boolean', 'blank' => false, 'default' => false, 'help_text' => 'If this revision is the latest, we mark it as being the head revision.', 'index' => true, ), 'summary' => array( 'type' => 'Pluf_DB_Field_Varchar', 'blank' => false, 'size' => 250, 'verbose' => __('summary'), 'help_text' => __('A one line description of the changes.'), ), 'filesize' => array( 'type' => 'Pluf_DB_Field_Integer', 'blank' => false, 'default' => 0, 'verbose' => __('file size in bytes'), ), 'submitter' => array( 'type' => 'Pluf_DB_Field_Foreignkey', 'model' => 'Pluf_User', 'blank' => false, 'verbose' => __('submitter'), 'relate_name' => 'submitted_downloads', ), 'pageusage' => array( 'type' => 'Pluf_DB_Field_Manytomany', 'model' => 'IDF_Wiki_PageRevision', 'blank' => true, 'verbose' => __('page usage'), 'help_text' => 'Records on which pages this resource revision is used.', ), 'creation_dtime' => array( 'type' => 'Pluf_DB_Field_Datetime', 'blank' => true, 'verbose' => __('creation date'), ), ); } function __toString() { return sprintf(__('id %d: %s'), $this->id, $this->summary); } function _toIndex() { return ''; } function preSave($create=false) { if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); $this->is_head = true; } } function postSave($create=false) { if ($create) { $sql = new Pluf_SQL('wikiresource=%s', array($this->wikiresource)); $rev = Pluf::factory('IDF_Wiki_ResourceRevision')->getList(array('filter'=>$sql->gen())); if ($rev->count() > 1) { foreach ($rev as $r) { if ($r->id != $this->id and $r->is_head) { $r->is_head = false; $r->update(); } } } // update the modification timestamp $resource = $this->get_wikiresource(); $resource->update(); } } function getFilePath() { return sprintf(Pluf::f('upload_path').'/'.$this->get_wikiresource()->get_project()->shortname.'/wiki/res/%d/%d.%s', $this->get_wikiresource()->id, $this->id, $this->get_wikiresource()->orig_file_ext); } function preDelete() { @unlink($this->getFilePath()); } }