summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-07-23 11:46:54 +0200
committermsquare <msquare@notrademark.de>2017-07-23 11:46:54 +0200
commita157004f4aefaa5e2265f852f9432becedee1d66 (patch)
treec47915a311371afa7aa962655fd5ff1ff2ab5e64 /includes/model
parent36446dd644ff865d1d63aab0ba4c670ce2b277d1 (diff)
handle failed db queries in Db class
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/AngelType_model.php14
-rw-r--r--includes/model/EventConfig_model.php2
-rw-r--r--includes/model/NeededAngelTypes_model.php5
-rw-r--r--includes/model/Room_model.php5
-rw-r--r--includes/model/ShiftEntry_model.php3
-rw-r--r--includes/model/ShiftTypes_model.php9
-rw-r--r--includes/model/Shifts_model.php4
-rw-r--r--includes/model/UserAngelTypes_model.php28
-rw-r--r--includes/model/UserDriverLicenses_model.php10
-rw-r--r--includes/model/User_model.php12
10 files changed, 15 insertions, 77 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index d437f526..af213432 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -97,11 +97,10 @@ function AngelType_delete($angeltype)
* Update Angeltype.
*
* @param array $angeltype The angeltype
- * @return bool
*/
function AngelType_update($angeltype)
{
- $result = DB::update('
+ DB::update('
UPDATE `AngelTypes` SET
`name` = ?,
`restricted` = ?,
@@ -126,15 +125,12 @@ function AngelType_update($angeltype)
$angeltype['id'],
]
);
- if (is_null($result)) {
- engelsystem_error('Unable to update angeltype.');
- }
+
engelsystem_log(
'Updated angeltype: ' . $angeltype['name'] . ($angeltype['restricted'] ? ', restricted' : '')
. ($angeltype['no_self_signup'] ? ', no_self_signup' : '')
. ($angeltype['requires_driver_license'] ? ', requires driver license' : '')
);
- return true;
}
/**
@@ -145,7 +141,7 @@ function AngelType_update($angeltype)
*/
function AngelType_create($angeltype)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `AngelTypes` (
`name`,
`restricted`,
@@ -171,9 +167,7 @@ function AngelType_create($angeltype)
$angeltype['contact_email'],
]
);
- if (is_null($result)) {
- engelsystem_error('Unable to create angeltype.');
- }
+
$angeltype['id'] = DB::getPdo()->lastInsertId();
engelsystem_log(
'Created angeltype: ' . $angeltype['name']
diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php
index 112ad457..b5d3cc73 100644
--- a/includes/model/EventConfig_model.php
+++ b/includes/model/EventConfig_model.php
@@ -31,7 +31,7 @@ function EventConfig()
* @param int $event_end_date
* @param int $teardown_end_date
* @param string $event_welcome_msg
- * @return bool
+ * @return int Rows updated
*/
function EventConfig_update(
$event_name,
diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php
index 97b085f0..e77c715f 100644
--- a/includes/model/NeededAngelTypes_model.php
+++ b/includes/model/NeededAngelTypes_model.php
@@ -17,7 +17,7 @@ use Engelsystem\Database\DB;
*/
function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `NeededAngelTypes` ( `shift_id`, `angel_type_id`, `room_id`, `count`)
VALUES (?, ?, ?, ?)
',
@@ -27,9 +27,6 @@ function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count)
$room_id,
$count,
]);
- if ($result === false) {
- return false;
- }
return DB::getPdo()->lastInsertId();
}
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 17617b39..fdd9dddc 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -35,7 +35,7 @@ function Room_delete($room_id)
*/
function Room_create($name, $from_frab, $public, $number = null)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `Room` (`Name`, `FromPentabarf`, `show`, `Number`)
VALUES (?, ?, ?, ?)
',
@@ -46,9 +46,6 @@ function Room_create($name, $from_frab, $public, $number = null)
(int)$number,
]
);
- if (!$result) {
- return false;
- }
return DB::getPdo()->lastInsertId();
}
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index d7810feb..3a282efc 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -102,7 +102,6 @@ function ShiftEntry_create($shift_entry)
* Update a shift entry.
*
* @param array $shift_entry
- * @return bool
*/
function ShiftEntry_update($shift_entry)
{
@@ -120,8 +119,6 @@ function ShiftEntry_update($shift_entry)
$shift_entry['id']
]
);
-
- return (DB::getStm()->errorCode() == '00000');
}
/**
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php
index 96a823d4..12fe38be 100644
--- a/includes/model/ShiftTypes_model.php
+++ b/includes/model/ShiftTypes_model.php
@@ -20,7 +20,6 @@ function ShiftType_delete($shifttype_id)
* @param string $name
* @param int $angeltype_id
* @param string $description
- * @return bool
*/
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
{
@@ -38,8 +37,6 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
$shifttype_id,
]
);
-
- return DB::getStm()->errorCode() == '00000';
}
/**
@@ -52,7 +49,7 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
*/
function ShiftType_create($name, $angeltype_id, $description)
{
- $result = DB::insert('
+ DB::insert('
INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`)
VALUES(?, ?, ?)
',
@@ -63,10 +60,6 @@ function ShiftType_create($name, $angeltype_id, $description)
]
);
- if ($result === false) {
- return false;
- }
-
return DB::getPdo()->lastInsertId();
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 21abc888..6e69fe35 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -436,7 +436,7 @@ function Shift_delete($shift_id)
* Update a shift.
*
* @param array $shift
- * @return bool
+ * @return int Updated row count
*/
function Shift_update($shift)
{
@@ -444,7 +444,7 @@ function Shift_update($shift)
$shift['name'] = ShiftType($shift['shifttype_id'])['name'];
mail_shift_change(Shift($shift['SID']), $shift);
- return (bool)DB::update('
+ return DB::update('
UPDATE `Shifts` SET
`shifttype_id` = ?,
`start` = ?,
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index 82f390ee..f8277fd9 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -110,22 +110,15 @@ function User_is_AngelType_supporter(&$user, $angeltype)
*
* @param int $user_angeltype_id
* @param bool $supporter
- * @return int
*/
function UserAngelType_update($user_angeltype_id, $supporter)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `supporter`=?
WHERE `id`=?
LIMIT 1
', [$supporter, $user_angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to update supporter rights.');
- }
-
- return $result;
}
/**
@@ -154,22 +147,15 @@ function UserAngelTypes_delete_all($angeltype_id)
*
* @param int $angeltype_id
* @param array $confirm_user
- * @return bool
*/
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `angeltype_id`=?
AND `confirm_user_id` IS NULL
', [$confirm_user['UID'], $angeltype_id]);
-
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to confirm all users.');
- }
-
- return (bool)$result;
}
/**
@@ -181,15 +167,11 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user)
*/
function UserAngelType_confirm($user_angeltype_id, $confirm_user)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserAngelTypes`
SET `confirm_user_id`=?
WHERE `id`=?
LIMIT 1', [$confirm_user['UID'], $user_angeltype_id]);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to confirm user angeltype.');
- }
- return (bool)$result;
}
/**
@@ -225,10 +207,6 @@ function UserAngelType_create($user, $angeltype)
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to create user angeltype.');
- }
-
return DB::getPdo()->lastInsertId();
}
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index 525d2016..ee93ac95 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -94,9 +94,6 @@ function UserDriverLicenses_create($user_driver_license, $user)
(bool)$user_driver_license['has_license_forklift'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to create user driver license');
- }
return $user_driver_license;
}
@@ -105,11 +102,10 @@ function UserDriverLicenses_create($user_driver_license, $user)
* Update a user's driver license entry
*
* @param array $user_driver_license The UserDriverLicense to update
- * @return bool
*/
function UserDriverLicenses_update($user_driver_license)
{
- $result = DB::update('
+ DB::update('
UPDATE `UserDriverLicenses`
SET
`has_car`=?,
@@ -130,10 +126,6 @@ function UserDriverLicenses_update($user_driver_license)
$user_driver_license['user_id'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to update user driver license information');
- }
- return $result;
}
/**
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 2913c1a1..9f767b74 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -24,11 +24,10 @@ function User_delete($user_id)
* Update user.
*
* @param array $user
- * @return bool
*/
function User_update($user)
{
- return (bool)DB::update('
+ DB::update('
UPDATE `User` SET
`Nick`=?,
`Name`=?,
@@ -481,7 +480,6 @@ function User_by_password_recovery_token($token)
*
* @param array $user
* @param bool $log
- * @return bool
*/
function User_reset_api_key(&$user, $log = true)
{
@@ -497,15 +495,10 @@ function User_reset_api_key(&$user, $log = true)
$user['UID']
]
);
- if (DB::getStm()->errorCode() != '00000') {
- return false;
- }
if ($log) {
engelsystem_log(sprintf('API key resetted (%s).', User_Nick_render($user)));
}
-
- return true;
}
/**
@@ -528,9 +521,6 @@ function User_generate_password_recovery_token(&$user)
$user['UID'],
]
);
- if (DB::getStm()->errorCode() != '00000') {
- engelsystem_error('Unable to generate password recovery token.');
- }
engelsystem_log('Password recovery for ' . User_Nick_render($user) . ' started.');
return $user['password_recovery_token'];
}