From: Nik Okuntseff Date: Fri, 30 Nov 2018 13:22:19 +0000 (+0000) Subject: Ongoing refactoring, replacing the method to obtain last insert ids. X-Git-Tag: timetracker_1.19-1~521 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=cbc2ae6c2e83edfe7b4242b7dd2f9bfb1359820e;p=timetracker.git Ongoing refactoring, replacing the method to obtain last insert ids. --- diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 24d00d23..3dc60bdb 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -189,12 +189,7 @@ class ttClientHelper { if (is_a($affected, 'PEAR_Error')) return false; - $last_id = 0; - $sql = "select last_insert_id() as last_insert_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_insert_id']; - + $last_id = $mdb2->lastInsertID('tt_clients', 'id'); if (count($projects) > 0) foreach ($projects as $p_id) { $sql = "insert into tt_client_project_binds (client_id, project_id, group_id, org_id) values($last_id, $p_id, $group_id, $org_id)"; diff --git a/WEB-INF/lib/ttCustomFieldHelper.class.php b/WEB-INF/lib/ttCustomFieldHelper.class.php deleted file mode 100644 index 15c7ca05..00000000 --- a/WEB-INF/lib/ttCustomFieldHelper.class.php +++ /dev/null @@ -1,100 +0,0 @@ -quote($label).", $required, ".$mdb2->quote($status).")"; - - $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; - - $last_id = 0; - $sql = "select last_insert_id() as last_insert_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_insert_id']; - - return $last_id; - } - - // The insertOption function inserts a new custom field option in database. - static function insertOption($fields) - { - $mdb2 = getConnection(); - - $field_id = (int) $fields['field_id']; - $value = $fields['value']; - - $sql = "insert into tt_custom_field_options (field_id, value) - values ($field_id, ".$mdb2->quote($value).")"; - - $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; - - $last_id = 0; - $sql = "select last_insert_id() as last_insert_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_insert_id']; - - return $last_id; - } - - // The insertLogEntry function inserts a new custom field log entry in database. - static function insertLogEntry($fields) - { - $mdb2 = getConnection(); - - $log_id = (int) $fields['log_id']; - $field_id = (int) $fields['field_id']; - $option_id = $fields['option_id']; - $value = $fields['value']; - $status = $fields['status']; - - $sql = "insert into tt_custom_field_log (log_id, field_id, option_id, value, status) - values ($log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")"; - - $affected = $mdb2->exec($sql); - return (!is_a($affected, 'PEAR_Error')); - } -} diff --git a/WEB-INF/lib/ttUserHelper.class.php b/WEB-INF/lib/ttUserHelper.class.php index 2ff774ff..42d7c910 100644 --- a/WEB-INF/lib/ttUserHelper.class.php +++ b/WEB-INF/lib/ttUserHelper.class.php @@ -120,11 +120,7 @@ class ttUserHelper { // Now deal with project assignment. if (!is_a($affected, 'PEAR_Error')) { - $sql = "SELECT LAST_INSERT_ID() AS last_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_id']; - + $last_id = $mdb2->lastInsertID('tt_users', 'id'); $projects = isset($fields['projects']) ? $fields['projects'] : array(); if (count($projects) > 0) { // We have at least one project assigned. Insert corresponding entries in tt_user_project_binds table. diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 9f251f40..501ebf76 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4543 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4544 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve}