/** * Insert a new revision * * @param string $status The row status * @return void */ protected function _insertRevision() { $table = $this->getTable(); // Get the row data if ($this->getStatus() == Library\Database::STATUS_UPDATED) { $data = $this->getData(true); } else { $data = $this->getData(); } //Get the row status $status = $this->getStatus(); if ($status == Library\Database::STATUS_LOADED) { $status = Library\Database::STATUS_CREATED; } // Create the new revision $revision = $this->_table->getRow(); $revision->table = $table->getBase(); $revision->row = $this->id; $revision->status = $status; $revision->data = (object) $table->filter($data); // Set the created_on and created_by information based on the creatable or modifiable data in the row if ($this->isCreatable()) { if (isset($this->created_by) && !empty($this->created_by)) { $revision->created_by = $this->created_by; } if (isset($this->created_on) && $this->created_on != $table->getDefault('created_on')) { $revision->created_on = $this->created_on; } } if ($this->isModifiable()) { if (isset($this->modified_by) && !empty($this->modified_by)) { $revision->created_by = $this->modified_by; } if (isset($this->modified_on) && $this->modified_on != $table->getDefault('modified_on')) { $revision->created_on = $this->modified_on; } } // Set revision number. if ($status == Library\Database::STATUS_UPDATED || $status == Library\Database::STATUS_DELETED) { $query = $this->getObject('lib:database.query.select')->where('table = :table')->where('row = :row')->order('revision', 'DESC')->bind(array('table' => $table->getBase(), 'row' => $this->id)); $revision->revision = $this->_table->select($query, Library\Database::FETCH_ROW)->revision + 1; } // Store the revision return $revision->save(); }