| Conditions | 9 |
| Paths | 35 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | public static function update($baseTable, $field, $value, $id = 0, $replace = false, $addLive = false) |
||
|
|
|||
| 7 | { |
||
| 8 | $object = DataObject::get_one($baseTable); |
||
| 9 | if ($object) { |
||
| 10 | $tableArray = array($baseTable); |
||
| 11 | if ($object instanceof SiteTree) { |
||
| 12 | $tableArray[] = $baseTable."_Live"; |
||
| 13 | } |
||
| 14 | foreach ($tableArray as $table) { |
||
| 15 | $value = Convert::raw2sql($value); |
||
| 16 | $sql = "UPDATE \"$table\" SET \"$table\".\"$field\" = '$value'"; |
||
| 17 | $where = array(); |
||
| 18 | if ($id) { |
||
| 19 | $where[] = " \"$table\".\"ID\" = ".$id; |
||
| 20 | } |
||
| 21 | if (!$replace) { |
||
| 22 | $where[] = " \"$table\".\"$field\" IS NULL OR \"$table\".\"$field\" = '' OR \"$table\".\"$field\" = 0 "; |
||
| 23 | } |
||
| 24 | $wherePhrase = ''; |
||
| 25 | if (count($where)) { |
||
| 26 | $wherePhrase = " WHERE ( " . implode(") AND (", $where) . " )"; |
||
| 27 | } |
||
| 28 | $result = DB::query("SELECT COUNT(\"$table\".\"ID\") C FROM \"$table\" ".$wherePhrase); |
||
| 29 | if ($result && $result->value()) { |
||
| 30 | $sql .= $wherePhrase; |
||
| 31 | DB::query($sql); |
||
| 32 | DB::alteration_message("Updated $field in $table to $value ", "added"); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.