X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/6e47f5d25d117dda1c66e82476165d9abce91fc5..5c582eb5bacc8b3d9d2775ade454590c71b113ec:/WEB-INF/lib/ttFileHelper.class.php diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php index 45b5b237..61dd6028 100644 --- a/WEB-INF/lib/ttFileHelper.class.php +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -277,6 +277,9 @@ class ttFileHelper { // deleteEntityFiles - deletes all files associated with an entity. function deleteEntityFiles($entity_id, $entity_type) { + if (!$this->entityHasFiles($entity_id, $entity_type)) + return true; // No files to delete. + global $i18n; global $user; $mdb2 = getConnection(); @@ -349,6 +352,21 @@ class ttFileHelper { return true; } + // entityHasFiles determines if an entity has any files referenced in database. + private function entityHasFiles($entity_id, $entity_type) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_files where org_id = $org_id and group_id = $group_id". + " and entity_type = ".$mdb2->quote($entity_type)." and entity_id = $entity_id limit 1"; + $res = $mdb2->query($sql); + $val = $res->fetchRow(); + return $val['id'] > 0; + } + // getOrgKey obtains organization key from the database. private function getOrgKey() { global $user;