]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Improve updating asset files after upgrade
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 6 Feb 2021 20:29:05 +0000 (21:29 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 6 Feb 2021 20:29:05 +0000 (21:29 +0100)
gui/baculum/protected/Common/Class/BAssetManager.php [new file with mode: 0644]
gui/baculum/protected/application.xml

diff --git a/gui/baculum/protected/Common/Class/BAssetManager.php b/gui/baculum/protected/Common/Class/BAssetManager.php
new file mode 100644 (file)
index 0000000..1457771
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+Prado::using('System.Web.TAssetManager');
+
+/**
+ * Baculum asset manager.
+ * This additional asset manager layer is required to avoid issue with updating
+ * asset directory. It bases on two framework methods responsible for copying
+ * files and directories which instead of checking if:
+ *
+ *   asset file MTIME < original file MTIME
+ *
+ * here do copying assets everytime if:
+ *
+ *   asset file MTIME != original file MTIME
+ *
+ * This behavior is specially useful for upgrades when can be case for which:
+ *
+ *   asset file MTIME > original file MTIME
+ *
+ * and in real the original file MTIME has newer content than that one in
+ * asset directory. It is because copy() changes MTIME of destination file.
+ *
+ * @category Client Script
+ * @package Baculum Common
+ */
+class BAssetManager extends TAssetManager {
+
+       protected function copyFile($src, $dst) {
+               if (!is_dir($dst)) {
+                       @mkdir($dst);
+                       @chmod($dst, PRADO_CHMOD);
+               }
+               $dst_file = $dst . DIRECTORY_SEPARATOR . basename($src);
+               $src_mtime = @filemtime($src);
+               if (@filemtime($dst_file) !== $src_mtime) {
+                       @copy($src, $dst_file);
+                       if ($src_mtime !== false) {
+                               @touch($dst_file, $src_mtime);
+                       }
+               }
+       }
+
+       public function copyDirectory($src, $dst) {
+               if (!is_dir($dst)) {
+                       @mkdir($dst);
+                       @chmod($dst, PRADO_CHMOD);
+               }
+               if ($folder = @opendir($src)) {
+                       while ($file = @readdir($folder)) {
+                               $src_file = $src . DIRECTORY_SEPARATOR . $file;
+                               $dst_file = $dst . DIRECTORY_SEPARATOR . $file;
+                               if ($file === '.' || $file === '..') {
+                                       continue;
+                               } elseif (is_file($src_file)) {
+                                       $src_mtime = @filemtime($src_file);
+                                       if (@filemtime($dst_file) !== $src_mtime) {
+                                               @copy($src_file, $dst_file);
+                                               if ($src_mtime !== false) {
+                                                       @touch($dst_file, $src_mtime);
+                                               }
+                                               @chmod($dst_file, PRADO_CHMOD);
+                                       }
+                               } else {
+                                       $this->copyDirectory($src_file, $dst_file);
+                               }
+                       }
+                       closedir($folder);
+               } else {
+                       throw new TInvalidDataValueException('assetmanager_source_directory_invalid', $src);
+               }
+       }
+}
+?>
index ff55430f3c235623ff72db00049383f0b4a1d475..15ffd6680c349cc3ae528e0f8c32594fe1cfabc4 100644 (file)
@@ -8,6 +8,7 @@
        </paths>
        <modules>
                <!-- generic common modules -->
+               <module id="asset" class="Application.Common.Class.BAssetManager" />
                <module id="logging" class="Application.Common.Class.Logging" />
                <module id="misc" class="Application.Common.Class.Miscellaneous" />
                <module id="config_ini" class="Application.Common.Class.ConfigIni" />