From eefd91f5c5c8f568ad794da4c3e5b1d4a17540a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Fri, 3 Sep 2010 09:04:08 +0000
Subject: [PATCH] add a tab which allows to reload a Product on a running
 instance

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38134 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Tool/ClassTool.py           | 27 +++++++++++++++++
 product/ERP5Type/dtml/viewProductReload.dtml | 32 ++++++++++++++++++++
 2 files changed, 59 insertions(+)
 create mode 100644 product/ERP5Type/dtml/viewProductReload.dtml

diff --git a/product/ERP5Type/Tool/ClassTool.py b/product/ERP5Type/Tool/ClassTool.py
index 08cb53a5a9..aef429bebe 100644
--- a/product/ERP5Type/Tool/ClassTool.py
+++ b/product/ERP5Type/Tool/ClassTool.py
@@ -43,6 +43,7 @@ from Acquisition import Implicit
 from AccessControl import ClassSecurityInfo
 from Products.ERP5Type.Globals import InitializeClass, DTMLFile
 from App.config import getConfiguration
+from App import RefreshFuncs
 from Shared.DC.ZRDB.TM import TM
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
@@ -328,6 +329,9 @@ if allowClassTool():
                           ,{ 'label'      : 'Tests'
                           , 'action'     : 'manage_viewTestList'
                           }
+                          ,{ 'label'      : 'Reload Product'
+                          , 'action'     : 'manage_viewProductReload'
+                          }
                           ,{ 'label'      : 'Product Generation'
                           , 'action'     : 'manage_viewProductGeneration'
                           }
@@ -374,6 +378,9 @@ if allowClassTool():
       security.declareProtected( Permissions.ManagePortal, 'manage_viewProductGeneration' )
       manage_viewProductGeneration = DTMLFile( 'viewProductGeneration', _dtmldir )
 
+      security.declareProtected( Permissions.ManagePortal, 'manage_viewProductReload' )
+      manage_viewProductReload = DTMLFile( 'viewProductReload', _dtmldir )
+
       def _clearCache(self):
         """
           Clears the cache of all databases
@@ -1192,6 +1199,26 @@ def initialize( context ):
         path = os.path.join(getConfiguration().instancehome, 'tests')
         return runLiveTest(test_list, run_only=run_only, debug=debug, path=path)
 
+      def getProductList(self):
+        """ List all products """
+        return self.Control_Panel.Products.objectIds()
+
+      def reloadProduct(self, product_id, REQUEST=None):
+        """ Reload a given product """
+        product = self.Control_Panel.Products[product_id]
+        if product._readRefreshTxt() is None:
+            raise Unauthorized, 'refresh.txt not found'
+        message = None
+        if RefreshFuncs.performFullRefresh(product._p_jar, product.id):
+            from ZODB import Connection
+            Connection.resetCaches() # Clears cache in future connections.
+            message = 'Product refreshed.'
+        else:
+            message = 'An exception occurred. Check your log'
+
+        if REQUEST is not None:
+          REQUEST.RESPONSE.redirect('%s/manage_viewProductReload?manage_tabs_message=%s' % (self.absolute_url(), message))
+
 else:
 
   class ClassTool(BaseTool, ClassToolMixIn):
diff --git a/product/ERP5Type/dtml/viewProductReload.dtml b/product/ERP5Type/dtml/viewProductReload.dtml
new file mode 100644
index 0000000000..b9b3835f52
--- /dev/null
+++ b/product/ERP5Type/dtml/viewProductReload.dtml
@@ -0,0 +1,32 @@
+<dtml-var manage_page_header>
+<dtml-var manage_tabs>
+
+<div class="std-text"><p><strong>Reload Products</strong></p></div>
+
+<table width="100%">
+  <tr class="list-header">
+    <th>
+      Product
+    </th>
+    <th>
+      Action
+    </th>
+  <dtml-in getProductList>
+  <dtml-if sequence-odd>
+  <tr class="row-normal">
+  <dtml-else>
+  <tr class="row-hilite">
+  </dtml-if>
+    <td>
+      <div class="list-item"><dtml-var sequence-item></div>
+    </td>   
+    <td>
+      <div class="list-item"><a href="reloadProduct?product_id=<dtml-var sequence-item>">reload</a></div>
+    </td>   
+  </tr>    
+  </dtml-in>
+</table>
+
+<hr/>
+
+<dtml-var manage_page_footer>
-- 
2.30.9