/** * Copy all tags on an object to another object * * @param integer $oldtagid ID of tag to be copied * @param integer $newtagid ID of tag to copy to * @return boolean True if records copied */ public static function copyTo($oldtagid = null, $newtagid = null) { if (!$oldtagid || !$newtagid) { return false; } $rows = self::all()->whereEquals('tagid', $oldtagid)->rows(); if ($rows) { $entries = array(); foreach ($rows as $row) { $row->set('id', null)->set('tagid', $newtagid)->save(); $entries[] = $row->get('id'); } $data = new stdClass(); $data->old_id = $oldtagid; $data->new_id = $newtagid; $data->entries = $entries; $log = Log::blank(); $log->set(['tag_id' => $newtagid, 'action' => 'objects_copied', 'comments' => json_encode($data)]); $log->save(); } return true; }
/** * Save entry * * @return object */ public function save() { $action = $this->isNew() ? 'tag_created' : 'tag_edited'; $result = parent::save(); if ($result) { $log = Log::blank(); $log->set('tag_id', $this->get('id')); $log->set('action', $action); $log->set('comments', $this->toJson()); $log->save(); } $this->purgeCache(); return $result; }