From c30bd94928988ff03ade10ca872968681456e12c Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 30 Nov 2018 14:31:27 +0000 Subject: [PATCH] Refactoring, finished with last insert ids. --- WEB-INF/lib/ttInvoiceHelper.class.php | 6 +--- WEB-INF/lib/ttOrgImportHelper.class.php | 38 +++++-------------------- WEB-INF/lib/ttProjectHelper.class.php | 8 ++---- WEB-INF/lib/ttRoleHelper.class.php | 5 +--- WEB-INF/lib/ttTaskHelper.class.php | 7 ++--- WEB-INF/templates/footer.tpl | 2 +- 6 files changed, 14 insertions(+), 52 deletions(-) diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index 41dace01..0867ee1e 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -332,11 +332,7 @@ class ttInvoiceHelper { if (is_a($affected, 'PEAR_Error')) return false; // Mark associated invoice items with invoice id. - $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_invoices', 'id'); // Our update sql is different depending on tracking mode. if (MODE_TIME == $user->getTrackingMode()) { diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 011f2081..328eabef 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -725,11 +725,7 @@ class ttOrgImportHelper { 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_projects', 'id'); // Insert binds into tt_project_task_binds table. if (is_array($tasks)) { @@ -764,10 +760,7 @@ class ttOrgImportHelper { if (is_a($affected, 'PEAR_Error')) return false; - $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_roles', 'id'); return $last_id; } @@ -796,11 +789,7 @@ class ttOrgImportHelper { 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) { @@ -844,13 +833,8 @@ class ttOrgImportHelper { if (is_a($affected, 'PEAR_Error')) return false; - $sql = "select last_insert_id() as last_id"; - $res = $mdb2->query($sql); - if (is_a($res, 'PEAR_Error')) - return false; - - $val = $res->fetchRow(); - return $val['last_id']; + $last_id = $mdb2->lastInsertID('tt_fav_reports', 'id'); + return $last_id; } // insertNotification function inserts a new notification into database. @@ -912,11 +896,7 @@ class ttOrgImportHelper { 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_custom_fields', 'id'); return $last_id; } @@ -935,11 +915,7 @@ class ttOrgImportHelper { 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_custom_field_options', 'id'); return $last_id; } diff --git a/WEB-INF/lib/ttProjectHelper.class.php b/WEB-INF/lib/ttProjectHelper.class.php index 2a439dd9..98d928f9 100644 --- a/WEB-INF/lib/ttProjectHelper.class.php +++ b/WEB-INF/lib/ttProjectHelper.class.php @@ -206,12 +206,8 @@ class ttProjectHelper { $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']; + + $last_id = $mdb2->lastInsertID('tt_projects', 'id'); // Bind the project to users. $active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true)); diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index c14bc970..0686b1cd 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -173,10 +173,7 @@ class ttRoleHelper { if (is_a($affected, 'PEAR_Error')) return false; - $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_roles', 'id'); return $last_id; } diff --git a/WEB-INF/lib/ttTaskHelper.class.php b/WEB-INF/lib/ttTaskHelper.class.php index 0d4d5eff..2987d278 100644 --- a/WEB-INF/lib/ttTaskHelper.class.php +++ b/WEB-INF/lib/ttTaskHelper.class.php @@ -153,11 +153,8 @@ class ttTaskHelper { if (is_a($affected, 'PEAR_Error')) return false; - $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_tasks', 'id'); + if (is_array($projects)) { foreach ($projects as $p_id) { // Insert task binds into tt_project_task_binds table. diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c1615800..0b4dd2b4 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4545 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4546 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1