Browse Source

Update Smilies page

A file used for a smiley cannot be deleted.
Visman 2 years ago
parent
commit
a26eea864d
1 changed files with 16 additions and 1 deletions
  1. 16 1
      app/Models/Pages/Admin/Parser/Smilies.php

+ 16 - 1
app/Models/Pages/Admin/Parser/Smilies.php

@@ -340,6 +340,20 @@ class Smilies extends Parser
         return $form;
         return $form;
     }
     }
 
 
+    /**
+     * Проверят используется ли данный файл в смайлах
+     */
+    protected function fileIsBusy(string $name): bool
+    {
+        foreach ($this->c->smilies->list as $cur) {
+            if ($name === $cur['sm_image']) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
     /**
      * Удаляет смайл или изображение
      * Удаляет смайл или изображение
      */
      */
@@ -360,7 +374,8 @@ class Smilies extends Parser
             $file = $this->c->DIR_PUBLIC . '/img/sm/' . $args['name'];
             $file = $this->c->DIR_PUBLIC . '/img/sm/' . $args['name'];
 
 
             if (
             if (
-                \is_file($file)
+                ! $this->fileIsBusy($args['name'])
+                && \is_file($file)
                 && \unlink($file)
                 && \unlink($file)
             ) {
             ) {
                 $message = ['File %s deleted redirect', $args['name']];
                 $message = ['File %s deleted redirect', $args['name']];