@@ -267,7 +267,8 @@ public function delete($attachmentID, $removeFile = true)
267267 $ sql = sprintf (
268268 "SELECT
269269 directory_name AS directoryName,
270- stored_filename AS storedFileName
270+ stored_filename AS storedFileName,
271+ content_type AS contentType
271272 FROM
272273 attachment
273274 WHERE
@@ -276,6 +277,11 @@ public function delete($attachmentID, $removeFile = true)
276277 );
277278 $ rs = $ this ->_db ->getAssoc ($ sql );
278279
280+ if (($ rs ['contentType ' ] ?? null ) === 'catsbackup ' && !self ::canDeleteBackup ())
281+ {
282+ return false ;
283+ }
284+
279285 $ this ->forceRemoteDeleteAttachment ($ attachmentID );
280286
281287 $ sql = sprintf (
@@ -327,6 +333,11 @@ public function delete($attachmentID, $removeFile = true)
327333 */
328334 public function deleteAll ($ dataItemType , $ dataItemID , $ criteria = '' )
329335 {
336+ if (!self ::canDeleteBackup ())
337+ {
338+ $ criteria .= " AND (content_type IS NULL OR content_type <> 'catsbackup') " ;
339+ }
340+
330341 /* Get all attachment IDs for the Data Item. */
331342 $ sql = sprintf (
332343 "SELECT
@@ -355,7 +366,7 @@ public function deleteAll($dataItemType, $dataItemID, $criteria = '')
355366 {
356367 /* Sanity check. Don't delete the whole attachments directory. */
357368 $ directoryName = trim ($ row ['directoryName ' ]);
358- if (empty ($ directoryName ) || $ directoryName = '. ' )
369+ if (empty ($ directoryName ) || $ directoryName === '. ' )
359370 {
360371 continue ;
361372 }
@@ -384,6 +395,12 @@ public function deleteAll($dataItemType, $dataItemID, $criteria = '')
384395 $ this ->_db ->query ($ sql );
385396 }
386397
398+ private static function canDeleteBackup ()
399+ {
400+ return isset ($ _SESSION ['CATS ' ]) &&
401+ $ _SESSION ['CATS ' ]->getAccessLevel ('settings.deleteBackup ' ) >= ACCESS_LEVEL_SA ;
402+ }
403+
387404 /**
388405 * Removes all profile image attachments for the specified Data Item ID.
389406 *
@@ -446,11 +463,18 @@ public function setDirectoryName($attachmentID, $directoryName)
446463 *
447464 * @param flag Data Item type.
448465 * @param integer Data Item ID.
466+ * @param bool|null Whether to select only backups, exclude them, or include both.
449467 * @return array Multi-dimensional associative array of attachments data, or
450468 * array() if no records are present.
451469 */
452- public function getAll ($ dataItemType , $ dataItemID )
470+ public function getAll ($ dataItemType , $ dataItemID, ? bool $ backups = null )
453471 {
472+ $ criteria = match ($ backups ) {
473+ true => " AND content_type = 'catsbackup' " ,
474+ false => " AND (content_type IS NULL OR content_type <> 'catsbackup') " ,
475+ null => ''
476+ };
477+
454478 $ sql = sprintf (
455479 "SELECT
456480 IF(ISNULL(text), 0, 1) AS hasText,
@@ -471,9 +495,11 @@ public function getAll($dataItemType, $dataItemID)
471495 WHERE
472496 data_item_id = %s
473497 AND
474- data_item_type = %s " ,
498+ data_item_type = %s
499+ %s " ,
475500 $ this ->_db ->makeQueryInteger ($ dataItemID ),
476- $ this ->_db ->makeQueryInteger ($ dataItemType )
501+ $ this ->_db ->makeQueryInteger ($ dataItemType ),
502+ $ criteria
477503 );
478504 $ rs = $ this ->_db ->getAllAssoc ($ sql );
479505
0 commit comments