/**
  * Called after record successfully created
  */
 public function postCreate()
 {
     // Check if we should store creations in our revision history
     // Set this value to true in your model if you want to
     if (empty($this->revisionCreationsEnabled)) {
         // We should not store creations.
         return false;
     }
     if (!isset($this->revisionEnabled) || $this->revisionEnabled) {
         $revisions[] = array('revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => 'created_at', 'old_value' => null, 'new_value' => $this->created_at, 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime());
         $revision = new Revision();
         \DB::table($revision->getTable())->insert($revisions);
     }
 }
示例#2
0
 /**
  * Insert revisions in database.
  *
  * We use the database query builder instead of Eloquent to make insert
  * queries spanning multiple records more effecient.
  *
  * @param  array $revisions
  *
  * @return void
  */
 protected function dbInsert(array $revisions)
 {
     $revision = new Revision();
     $table = $revision->getTable();
     DB::table($table)->insert($revisions);
 }
 /**
  * Called after a model is successfully saved.
  *
  * @return void
  */
 public function postSave()
 {
     // check if the model already exists
     if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->updating) {
         // if it does, it means we're updating
         $changes_to_record = $this->changedRevisionableFields();
         $revisions = array();
         foreach ($changes_to_record as $key => $change) {
             $revisions[] = array('revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => $key, 'old_value' => array_get($this->originalData, $key), 'new_value' => $this->updatedData[$key], 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime());
         }
         if (count($revisions) > 0) {
             $revision = new Revision();
             \DB::table($revision->getTable())->insert($revisions);
         }
     }
 }
 private function storeRevisions($revisions)
 {
     if (isset($this->historyLimit) && $this->revisionHistory()->count() >= $this->historyLimit && !$this->isPersistenceModeEnabled()) {
         $LimitReached = true;
     } else {
         $LimitReached = false;
     }
     if (isset($this->revisionCleanup)) {
         $RevisionCleanup = $this->revisionCleanup;
     } else {
         $RevisionCleanup = false;
     }
     if (count($revisions) > 0) {
         if ($LimitReached && $RevisionCleanup) {
             $toDelete = $this->revisionHistory()->orderBy('id', 'asc')->limit(count($revisions))->get();
             foreach ($toDelete as $delete) {
                 $delete->delete();
             }
         }
         $revision = new Revision();
         \DB::table($revision->getTable())->insert($revisions);
     }
 }