Esempio n. 1
0
 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);
 }