public static function factory($id = null) { $instance = new FileRevision(); if (!empty($id)) { $instance->where('id', $id)->get(); } return $instance; }
public function revert($fid, $rid) { $file = File::factory()->get_by_id((int) $fid); $revision = FileRevision::factory()->get_by_id((int) $rid); $old_html = $file->contents(); $contents = $revision->contents; $old_editor = $file->editor_id; $old_ts = !empty($file->updated) ? $file->updated : $file->created; $succ = @file_put_contents($file->path, $contents); $file->editor_id = $this->user->id; if ($succ === FALSE) { $file->hash = md5($contents); $file->data = $contents; } else { $file->hash = md5_file($file->path); } $file->save(); //create revision $rev = new FileRevision(); $rev->contents = $old_html; $rev->user_id = $old_editor; $rev->created = $old_ts; $rev->save(array($file)); //$revision->delete(); $this->templatemanager->notify_next("Revision #{$revision->id} successfully reverted.", 'success'); redirect('administration/templates/edit/' . $file->path); }
public function prunerevs($months = 0) { error_reporting(E_ALL); if (empty($months)) { $months = (int) $this->input->post('age'); } $seconds = 3600 * 24 * 30 * $months; $ago = time() - $seconds; $contents = ContentRevision::factory()->where('created <', $ago)->get(); $contentsnum = $contents->result_count(); $contents->delete_all(); $files = FileRevision::factory()->where('created <', $ago)->get(); $filesnum = $files->result_count(); $files->delete_all(); if ($filesnum > 0 || $contentsnum > 0) { $this->templatemanager->notify_next("{$filesnum} file revision(s) and {$contentsnum} content revision(s) were removed successfully!", 'success'); } else { $this->templatemanager->notify_next("Nothing to remove older than {$months} month(s)!", 'information'); } redirect('administration/maintenance'); }
<div class="widget"> <div class="title"><img src="<?php echo $template->base_url(); ?> images/icons/dark/docs.png" alt="" class="titleIcon" /><h6>Revision history</h6></div> <table cellpadding="0" cellspacing="0" border="0" class="display revTable"> <thead> <tr> <th>#</th> <th>Created</th> <th>Actions</th> </tr> </thead> <tbody> <?php $revs = FileRevision::factory()->where_related_file('id', $file->id)->order_by('created DESC')->get(); foreach ($revs as $rev) { ?> <tr class="gradeA"> <td><?php echo $rev->id; ?> </td> <td><?php echo empty($rev->created) ? "—" : '<span class="tipN" title="' . date(Setting::value('datetime_format', 'F j, Y @ H:i'), $rev->created) . '">' . relative_time($rev->created) . '</span> ' . __('by %s', $rev->user->get()->name); ?> </td> <td class="actBtns2"> <a title="Compare with this version" href="<?php echo site_url('administration/templates/diff/' . $file->id . '/' . $rev->id); ?>