private function audit($markerSite, $action) { Log::info("Auditing " . $markerSite->id . "for " . $action); $data = $this->getAuditData($markerSite); $data["action"] = $action; Audit::create($data); }
/** * Store a newly created audit in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Audit::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Audit::create($data); return Redirect::route('audits.index'); }
public function delete_page($args) { $page_id = array_shift($args); if ($page = R::load('page', $page_id)) { $old = clone $page; R::trash($page); Audit::create($old, NULL, 'Developer deleted page from system'); } $this->redirect(PACKAGE_URL); }
function crud($posttype, RedBeanPHP\OODBBean $post_object) { $fields = $this->get_fields($posttype, false); $view = new G2_TwigView('post_form'); $view->fields = $fields; $form = new G2_FormMagic($view->get_render()); if (!$form->is_posted() && $post_object->getID()) { $data = []; foreach ($post_object->ownPostdata as $postdata) { $data[$postdata->postmeta->fieldname] = $postdata->value; } $form->set_data($data); } if ($form->is_posted()) { $old = clone $post_object; //Save fields to correct db locations $postdatas = []; foreach ($form->data() as $field => $value) { // First Match the field with the correct postdata record from the current post unset($postdata); foreach ($post_object->ownPostdata as &$data) { if ($data->postmeta->fieldname == $field) { $postdata = $data; } } if (!isset($postdata)) { $postdata = R::dispense('postdata'); $postdata->postmeta = R::findOne('postmeta', 'fieldname = :field AND post_type = :type', ['type' => $posttype, 'field' => $field]); } $postdata->value = $value; R::store($postdata); $postdatas[] = $postdata; } $post_object->ownPostdata = $postdatas; $post_object->post_type = $posttype; if (!$post_object->getID()) { $post_object->date_created = date('Y-m-d H:i:s'); } $post_object->date_modified = date('Y-m-d H:i:s'); $files = $form->get_uploaded_files(); R::store($post_object); //Save files to Audit::create($old, $post_object, 'An Post was saved'); return true; } echo $form->parse(); }
function save_area() { G2_User::init(); if (G()->logged_in() && !empty($_POST)) { $content = $_POST['content']; $area_id = $_POST['area_id']; $area = R::findOne('area', 'id = :area', ['area' => $area_id]); $old = clone $area; $area->html = $content; R::store($area); Audit::create($old, $area, 'An Area was updated with new content'); echo json_encode(['success' => true, 'message' => 'Content Saved Successfully']); } else { echo json_encode(['success' => false, 'message' => 'Not Logged in']); } die; }
function remove($args) { $id = array_shift($args); if (is_numeric($id) && ($user = R::load('user', $id))) { Audit::create($user, null, 'User was removed from the system'); R::trash($user); } $this->redirect(PACKAGE_URL); }
/** * Update titles of pages in site * */ function update_titles() { echo 'Load Config <br>'; $config = new Zend_Config_Ini('meta.ini', APP_DEPLOY); $title = $config->meta->title->change; $pages_slugs = []; $this->filter($title, $pages_slugs); $pages = R::findAll('page'); $meta = new Meta_Generator($config); foreach ($pages as $page) { $old = clone $page; echo "{$page->title} ==== " . $meta->get_title($page->slug) . '<br>'; echo "{$page->description} ==== " . $meta->get_description($page->slug) . '<br>'; $page->title = $meta->get_title($page->slug); $page->description = $meta->get_description($page->slug); Audit::create($old, $page, "Script updated Meta Data"); R::store($page); } // foreach($pages_slugs as $slug => $title){ // $page = R::findOne('page','slug = :slug',['slug' => $slug]); // if($page){ // echo "$page->title => $title ==== $page->slug<br>"; // } else { // echo "$slug Page not Found <br>"; // } // } }
function restore($args) { $what = array_shift($args); $id = array_shift($args); if (!is_numeric($id) || !($audit = R::load('audit', $id))) { $this->redirect(PACKAGE_URL); } $audit = current(Audit::deserialize([$audit])); if ($what == 'new') { $bean = $audit->new_obj; } else { $bean = $audit->old_obj; } //Retrieve the current record $current = R::findOne($bean->getMeta('type'), 'id = :id', array('id' => $bean->id)); if (!$current) { // Record was removed. Thus record needs to be recreated //$bean = R::dup($bean); } $old = $current != null ? clone $current : null; if ($current == null) { $current = R::dispense($bean->getMeta('type')); } foreach ($bean as $field => $value) { $current->{$field} = $value; } R::store($current); Audit::create($old, $current, "restored to previous version changed on {$audit->date_logged}"); $this->redirect(PACKAGE_URL); }