Skip to content
Browse files

bug fixes

  • Loading branch information...
1 parent 9d3e04a commit 7a2e07fe078da6b95a1956bef0220d1d1b71466b @mstdokumaci committed
Showing with 11 additions and 12 deletions.
  1. +4 −6 lib/adb.php
  2. +1 −1 lib/db.php
  3. +6 −5 lib/item.php
View
10 lib/adb.php
@@ -141,12 +141,10 @@ function delete ($name, $id, $delete_belongings=false) {
$item=$this->load($name, $id);
foreach (array_filter($item_model['fields'], function ($el) {return $el['foreign']!==false;}) as $k=>$f) {
- try {
- $foreign_item=$this->load($f['foreign']['type'], intval($item[$k]));
- $foreign_item->delete_relation($f['foreign']['field'], $id);
- } catch (\Exception $e) {
- continue;
- }
+ $fid=intval($item[$k]);
+ if (!$fid) continue;
+ $foreign_item=$this->load($f['foreign']['type'], $fid);
+ $foreign_item->delete_relation($f['foreign']['field'], $id);
}
foreach ($item_model['has_many'] as $has_many) {
foreach ($item[$has_many['local_name']] as $foreign_id) {
View
2 lib/db.php
@@ -54,7 +54,7 @@ function select ($sql) {
function count ($sql) {
if (!$result=mysqli_query($this->conn, $sql))
throw new \Exception('MySQL select query error: ' . mysqli_error($this->conn));
- return mysqli_num_rows($result, MYSQLI_ASSOC);
+ return mysqli_num_rows($result);
}
function escape ($value) {
View
11 lib/item.php
@@ -82,14 +82,15 @@ function offsetset ($field, $value) {
$this->db->update($this->name, $update, "id='" . $this->id . "'");
if ($field_model['foreign']!==false) {
- try {
- $foreign_item=$this->adb->load($field_model['foreign']['type'], intval($this->data[$field]));
+ $fid=intval($this->data[$field]);
+ if ($fid) {
+ $foreign_item=$this->adb->load($field_model['foreign']['type'], $fid);
$foreign_item->delete_relation($field_model['foreign']['field'], $this->id);
- } catch (\Exception $e) {
}
- if ($value!=0) {
- $foreign_item=$this->adb->load($field_model['foreign']['type'], intval($value));
+ $fid=intval($value);
+ if ($fid) {
+ $foreign_item=$this->adb->load($field_model['foreign']['type'], $fid);
$foreign_item->add_relation($field_model['foreign']['field'], $this->id);
}
}

0 comments on commit 7a2e07f

Please sign in to comment.
Something went wrong with that request. Please try again.