Browse Source

Maintenance: Support zammad packages in package installations.

Rolf Schmidt 1 year ago
parent
commit
63fdfc734b

+ 2 - 1
app/assets/javascripts/app/views/package.jst.eco

@@ -14,7 +14,8 @@
     <% if @package_installation: %>
       <% if @local_gemfiles: %>
       <li><code>root> zammad config:set BUNDLE_DEPLOYMENT=0</code></li>
-      <li><code>root> zammad run bundle install --no-deployment</code></li>
+      <li><code>root> zammad run bundle config set --local deployment 'false'</code></li>
+      <li><code>root> zammad run bundle install</code></li>
       <% end %>
       <li><code>root> zammad run rake zammad:package:migrate</code></strong></li>
       <li><code>root> zammad run rake assets:precompile</code></strong></li>

+ 33 - 2
contrib/packager.io/functions

@@ -274,16 +274,47 @@ function elasticsearch_searchindex_rebuild () {
   fi
 }
 
+function detect_local_gemfiles () {
+  if ls ${ZAMMAD_DIR}/Gemfile.local* 1> /dev/null 2>&1; then
+    zammad config:set BUNDLE_DEPLOYMENT=0
+    zammad run bundle config set --local deployment 'false'
+    zammad run bundle install
+  fi
+}
+
+function detect_zammad_packages () {
+  if [ "$(zammad run rails r 'puts Package.count.positive?')" == "true" ] && [ -n "$(which yarn 2> /dev/null)" ] ; then
+    echo "# Detected custom packages..."
+    ZAMMAD_PACKAGES="yes"
+  else
+    echo "# No custom packages detected..."
+    ZAMMAD_PACKAGES="no"
+  fi
+}
+
+function zammad_packages_reinstall_all () {
+  detect_zammad_packages
+
+  if [ "${ZAMMAD_PACKAGES}" == "yes" ]; then
+    echo "# Setup custom packages files..."
+    zammad run rake zammad:package:reinstall_all
+    detect_local_gemfiles
+    zammad run rake zammad:package:migrate
+    zammad run rake assets:precompile
+  fi
+}
+
 function update_or_install () {
 
   if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
-
     echo "# Clear cache..."
-    zammad run rails r Cache.clear
+    zammad run rails r Rails.cache.clear
 
     update_database
 
     update_translations
+
+    zammad_packages_reinstall_all
   else
     REBUILD_ES_SEARCHINDEX="yes"
     create_database_password

+ 20 - 1
contrib/packager.io/preinstall.sh

@@ -9,4 +9,23 @@
 #   which might come from a backup restore and/or a manual 'assets:precompile' command run.
 #   These duplicates can cause the application to fail, however.
 #
-rm -f /opt/zammad/public/assets/.sprockets-manifest-*.json || true
+rm -f /opt/zammad/public/assets/.sprockets-manifest-*.json || true
+
+# remove local files of the packages
+if [ -n "$(which zammad 2> /dev/null)" ]; then
+   PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin:
+
+   RAKE_TASKS=$(zammad run rake --tasks | grep "zammad:package:uninstall_all_files")
+
+   if [[ x$RAKE_TASKS == 'x' ]]; then
+      echo "# Code does not yet fit, skipping automatic package uninstall."
+      echo "... This is not an error and will work during your next upgrade ..."
+      exit 0
+   fi
+
+   if [ "$(zammad run rails r 'puts Package.count.positive?')" == "true" ] && [ -n "$(which yarn 2> /dev/null)" ] && [ -n "$(which node 2> /dev/null)" ]; then
+      echo "# Detected custom packages..."
+      echo "# Remove custom packages files temporarily..."
+      zammad run rake zammad:package:uninstall_all_files
+   fi
+fi

+ 4 - 0
lib/tasks/zammad/package/uninstall_all_files.rake

@@ -0,0 +1,4 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/package/uninstall_all_files.rb'
+Tasks::Zammad::Package::UninstallAllFiles.register_rake_task

+ 28 - 0
lib/tasks/zammad/package/uninstall_all_files.rb

@@ -0,0 +1,28 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/command.rb'
+
+module Tasks
+  module Zammad
+    module Package
+      class UninstallAllFiles < Tasks::Zammad::Command
+        def self.description
+          'Uninstall all package files in the filesystem only without executing migrations'
+        end
+
+        def self.task_handler
+          ::Package.all.pluck(:name, :version).each do |name, version|
+            puts "Removing files of Package '#{name}'..."
+
+            ::Package.uninstall(
+              name:               name,
+              version:            version,
+              migration_not_down: true,
+              reinstall:          true,
+            )
+          end
+        end
+      end
+    end
+  end
+end