1 |
bareface |
1.1 |
<?php |
2 |
|
|
/* |
3 |
|
|
|
4 |
|
|
YakkaMySqlPageAdapter |
5 |
|
|
|
6 |
|
|
Default implementation of a YakkaPageStorage. |
7 |
|
|
|
8 |
|
|
This is the reference implementation of a YakkaPageStorage enabling access to a mysql-based storage-provider. |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
require_once("YakkaMySqlDatabase.php"); |
12 |
|
|
require_once("library/YakkaPage.php"); |
13 |
|
|
|
14 |
|
|
class YakkaMySqlPageAdapter extends YakkaMySqlDatabase { |
15 |
|
|
var $table; |
16 |
|
|
|
17 |
|
|
function YakkaMySqlPageAdapter($parameters = null) { |
18 |
|
|
$this->YakkaMySqlDatabase(); |
19 |
|
|
|
20 |
|
|
if ($parameters) |
21 |
|
|
$this->connect($parameters["host"], $parameters["database"], $parameters["user"], $parameters["password"]); |
22 |
|
|
|
23 |
|
|
if (!$prefix = $parameters["table-prefix"]) |
24 |
|
|
$this->table = "pages"; |
25 |
|
|
else |
26 |
|
|
$this->table = $prefix."pages"; |
27 |
|
|
|
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
function hasPage($id) { |
31 |
|
|
$sql = "select page_id from $this->table where page_tag = '".$this->escapeString($id)."' and page_is_latest_flag = 'Y' limit 1"; |
32 |
|
|
return $this->queryRecord($sql) ? true : false; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
function loadPage($id) { |
36 |
|
|
$id = $this->escapeString($id); |
37 |
|
|
$sql = |
38 |
|
|
<<<MYSQL |
39 |
|
|
SELECT |
40 |
|
|
page_tag, |
41 |
|
|
page_name, |
42 |
|
|
page_source, |
43 |
|
|
page_comment, |
44 |
|
|
page_version, |
45 |
|
|
page_is_latest_flag, |
46 |
|
|
page_create_user_tag, |
47 |
|
|
page_modify_user_tag, |
48 |
|
|
unix_timestamp(page_create_date) AS page_create_timestamp, |
49 |
|
|
unix_timestamp(page_modify_date) AS page_modify_timestamp |
50 |
|
|
FROM |
51 |
|
|
$this->table |
52 |
|
|
WHERE |
53 |
|
|
page_tag = '$id' |
54 |
|
|
AND |
55 |
|
|
page_is_latest_flag = 'Y' |
56 |
|
|
LIMIT 1 |
57 |
|
|
MYSQL; |
58 |
|
|
|
59 |
|
|
if ($result = $this->queryRecord($sql)) |
60 |
|
|
return array( |
61 |
|
|
"id" => $result["page_tag"], |
62 |
|
|
"name" => $result["page_name"], |
63 |
|
|
"source" => $result["page_source"], |
64 |
|
|
"version" => $result["page_version"], |
65 |
|
|
"comment" => $result["page_comment"], |
66 |
|
|
"islatest" => ($result["page_is_latest_flag"] == 'Y' ? true : false), |
67 |
|
|
"createuserid" => $result["page_create_user_tag"], |
68 |
|
|
"modifyuserid" => $result["page_modify_user_tag"], |
69 |
|
|
"createtimestamp" => $result["page_create_timestamp"], |
70 |
|
|
"modifytimestamp" => $result["page_modify_timestamp"] |
71 |
|
|
); |
72 |
|
|
|
73 |
|
|
return null; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
function savePage($tag, $name, $source, $version, $comment = null, $createUserId = null, $modifyUserId = null, $createTimestamp = null, $modifyTimestamp = null) { |
77 |
|
|
$tag = $this->escapeString($tag); |
78 |
|
|
$name = $this->escapeString($name); |
79 |
|
|
$source = $this->escapeString(trim($source)); |
80 |
|
|
$version = $this->escapeString($version); |
81 |
|
|
if ($comment) |
82 |
|
|
$comment = $this->escapeString($comment); |
83 |
|
|
|
84 |
|
|
$createDate = $createTimestamp ? date("Y-m-d H:i:s", $createTimestamp) : date("Y-m-d H:i:s"); |
85 |
|
|
$modifyDate = $modifyTimestamp ? date("Y-m-d H:i:s", $modifyTimestamp) : date("Y-m-d H:i:s"); |
86 |
|
|
|
87 |
|
|
$update = |
88 |
|
|
<<<MYSQL |
89 |
|
|
UPDATE |
90 |
|
|
$this->table |
91 |
|
|
SET |
92 |
|
|
page_is_latest_flag = 'N' |
93 |
|
|
WHERE |
94 |
|
|
page_tag = '$tag' |
95 |
|
|
AND |
96 |
|
|
page_is_latest_flag = 'Y' |
97 |
|
|
MYSQL; |
98 |
|
|
|
99 |
|
|
$insert = |
100 |
|
|
<<<MYSQL |
101 |
|
|
INSERT INTO |
102 |
|
|
$this->table |
103 |
|
|
SET |
104 |
|
|
page_tag = '$tag', |
105 |
|
|
page_name = '$name', |
106 |
|
|
page_source = '$source', |
107 |
|
|
page_version = '$version', |
108 |
|
|
MYSQL; |
109 |
|
|
|
110 |
|
|
if ($comment) |
111 |
|
|
$insert .= "page_comment = '$comment',"; |
112 |
|
|
|
113 |
|
|
if ($createUserId) |
114 |
|
|
$insert .= "page_create_user_tag = '$createUserId',"; |
115 |
|
|
|
116 |
|
|
if ($modifyUserId) |
117 |
|
|
$insert .= "page_modify_user_tag = '$modifyUserId',"; |
118 |
|
|
|
119 |
|
|
$insert .= |
120 |
|
|
<<<MYSQL |
121 |
|
|
page_create_date = '$createDate', |
122 |
|
|
page_modify_date = '$modifyDate', |
123 |
|
|
page_is_latest_flag = 'Y' |
124 |
|
|
MYSQL; |
125 |
|
|
|
126 |
|
|
return $this->execute($update) && $this->execute($insert); |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
?> |