-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcs_app_model.php
52 lines (44 loc) · 1.39 KB
/
vcs_app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class VcsAppModel extends AppModel {
public function switchLive() {
$this->table = $this->tableLive;
$this->useTable = $this->tableLive;
}
public function switchDev() {
$this->table = $this->tableDev;
$this->useTable = $this->tableDev;
}
function revision($id, $user_id, $a, $b, $commited_data, $remark='') {
$a = explode("\n", $a);
$b = explode("\n", $b);
// require_once dirname(__FILE__).'/../lib/Diff.php';
App::import('Vendor', 'Cvs.Diff', array('file' => 'php_diff'.DS.'lib'.DS.'Diff.php'));
$diff = new Diff($a, $b);
// require_once dirname(__FILE__).'/../lib/Diff/Renderer/Html/Inline.php';
App::import('Vendor', 'Cvs.Inline', array('file' => 'php_diff'.DS.'lib'.DS.'Diff'.DS.'Renderer'.DS.'Html'.DS.'Inline.php'));
$renderer = new Diff_Renderer_Html_Inline;
$output = $diff->render($renderer);
//pr($output); die();
$Revision = ClassRegistry::init('Vcs.VcsRevision');
$data = array(
'model' => $this->alias,
'model_id' => $id,
'diff' => $output,
'remark' => $remark,
'user_id' => $user_id,
'data' => serialize($commited_data),
'commit_id' => $_SESSION['Auth']['User']['id'],
);
$Revision->create();
$Revision->save($data);
}
function dataToStr($data) {
$str = '';
foreach ($data as $key=>$value) {
$str .= str_pad(('*****' . $key), 40, '*', STR_PAD_RIGHT) . "\n";
$str .= $value . "\n";
}
return $str;
}
}
?>