Skip to content

Commit f2b36d7

Browse files
committed
Merged branch Hotfix-1.4.1 into master
2 parents bbb6ed4 + e5f1078 commit f2b36d7

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

admin/classes/common/DBService.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,67 @@ public function processQuery($sql, $type = NULL) {
9393
return $data;
9494
}
9595

96+
/**
97+
* Version of processQuery() that deals with prepared statements. As prepared
98+
* statements use variadic functions, much of this function's complexity
99+
* comes from wrapping a variadic function in a PHP 5.5 compatible way.
100+
*
101+
* @param string $query Same format as mysqli::prepare(), with usually one
102+
* or more "?" inside it.
103+
*
104+
* @param string $type Must be "num" or "assoc". Contrary to processQuery(),
105+
* it's not an optionnal argument. Due to this function being variadic.
106+
*
107+
* @param mixed ...$paramsToBind Same format as mysqli_stmt::bind_param()
108+
* It's a variadic function based on this PHP 5.5 compatible implementation
109+
* https://wiki.php.net/rfc/variadics#introduction
110+
* We will be able to simplify this once we require PHP 5.6
111+
* https://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.variadics
112+
*/
113+
public function processPreparedQuery($query, $type) {
114+
$paramsToBind = array_slice(func_get_args(), 2); // additional arguments
115+
// prepared statements specific code
116+
$statement = $this->db->prepare($query);
117+
$this->checkForError();
118+
// The following is an implementation of the splat operator. This
119+
// will be simpler with PHP 5.6
120+
// https://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.splat
121+
// We need to pass references to bind_param(), hence the use of refValues()
122+
call_user_func_array([$statement, "bind_param"], self::refValues($paramsToBind)) ;
123+
$statement->execute();
124+
$result = $statement->get_result();
125+
126+
// same as processQuery()
127+
$this->checkForError();
128+
$data = array();
129+
130+
if ($result instanceof mysqli_result) {
131+
$resultType = MYSQLI_NUM;
132+
if ($type == 'assoc') {
133+
$resultType = MYSQLI_ASSOC;
134+
}
135+
while ($row = $result->fetch_array($resultType)) {
136+
if ($this->db->affected_rows > 1) {
137+
array_push($data, $row);
138+
} else {
139+
$data = $row;
140+
}
141+
}
142+
$result->free();
143+
} else if ($result) {
144+
$data = $this->db->insert_id;
145+
}
146+
147+
return $data;
148+
}
149+
150+
private static function refValues($arr){
151+
$refs = array();
152+
foreach($arr as $key => $value) {
153+
$refs[$key] = &$arr[$key];
154+
}
155+
return $refs;
156+
}
96157
}
97158

98159
?>

admin/classes/common/DatabaseObject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ public function allAsArray() {
282282
public function load() {
283283
//if exists in the database
284284
if (isset($this->primaryKey)) {
285-
$query = "SELECT * FROM `$this->tableName` WHERE `$this->primaryKeyName` = '$this->primaryKey'";
286-
$result = $this->db->processQuery($query, 'assoc');
285+
$query = "SELECT * FROM `$this->tableName` WHERE `$this->primaryKeyName` = ?";
286+
$result = $this->db->processPreparedQuery($query, "assoc",
287+
"s",
288+
$this->primaryKey);
287289

288290
foreach (array_keys($result) as $attributeName) {
289291
$this->addAttribute($attributeName);

install/UPGRADE_README.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.4.1 The 1.4.1 update is a security fix
2+
3+
- No database changes.
4+
15
1.4 The 1.4 update to the CORAL Resources module includes the following enhancements:
26

37
-Added Issue tracker feature that allows tracking of down resources.

templates/footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
<div class="push">&nbsp;</div>
2929
</div>
3030

31-
<div class="footer">Copyright &copy; 2015. Resources Module version 1.4<br/><a href="http://coral-erm.org/">CORAL Project Website</a> | <a href="https://github.com/ndlibersa/resources">GitHub Site</a></div>
31+
<div class="footer">Copyright &copy; 2015. Resources Module version 1.4.1<br/><a href="http://coral-erm.org/">CORAL Project Website</a> | <a href="https://github.com/ndlibersa/resources">GitHub Site</a></div>
3232
</body>
3333
</html>

0 commit comments

Comments
 (0)