From 1dbf92ee883bd27873f6fcc4c1114b26dff37c95 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Thu, 8 Mar 2007 18:12:28 +0000 Subject: [PATCH] Add a script to check the stock table. It checks that every object present in the stock table (and which is not an inventory) correspond to the in-ZODB document. It requires at least 1 site-specific script to be useable, because it highly relies on site configuration. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13297 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../erp5_core/Base_zGetAllFromStock.xml | 129 ++++++++ .../erp5_core/ERP5Site_checkStockTable.xml | 292 ++++++++++++++++++ product/ERP5/bootstrap/erp5_core/bt/revision | 2 +- 3 files changed, 422 insertions(+), 1 deletion(-) create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_zGetAllFromStock.xml create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_checkStockTable.xml diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_zGetAllFromStock.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_zGetAllFromStock.xml new file mode 100644 index 0000000000..61e20a00d1 --- /dev/null +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_zGetAllFromStock.xml @@ -0,0 +1,129 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.ZSQLMethods.SQL</string> + <string>SQL</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_arg</string> </key> + <value> + <object> + <klass> + <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_data</string> </key> + <value> + <dictionary> + <item> + <key> <string>limit</string> </key> + <value> + <dictionary/> + </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>_keys</string> </key> + <value> + <list> +<string>limit</string> + </list> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>arguments_src</string> </key> + <value> <string>limit</string> </value> + </item> + <item> + <key> <string>connection_id</string> </key> + <value> <string>erp5_sql_connection</string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>Base_zGetAllFromStock</string> </value> + </item> + <item> + <key> <string>src</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +select * from stock\n +LIMIT <dtml-var expr="limit[0]">, <dtml-var expr="limit[1]"> + +]]></string> </value> + </item> + <item> + <key> <string>template</string> </key> + <value> + <object> + <klass> + <global name="SQL" module="Shared.DC.ZRDB.DA"/> + </klass> + <none/> + <state> + <dictionary> + <item> + <key> <string>__name__</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +<string> + +]]></string> </value> + </item> + <item> + <key> <string>_vars</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>globals</string> </key> + <value> + <dictionary/> + </value> + </item> + <item> + <key> <string>raw</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +select * from stock\n +LIMIT <dtml-var expr="limit[0]">, <dtml-var expr="limit[1]"> + +]]></string> </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_checkStockTable.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_checkStockTable.xml new file mode 100644 index 0000000000..64ba600922 --- /dev/null +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/ERP5Site_checkStockTable.xml @@ -0,0 +1,292 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.PythonScripts.PythonScript</string> + <string>PythonScript</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Python_magic</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_container</string> </key> + <value> <string>container</string> </value> + </item> + <item> + <key> <string>name_context</string> </key> + <value> <string>context</string> </value> + </item> + <item> + <key> <string>name_m_self</string> </key> + <value> <string>script</string> </value> + </item> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_body</string> </key> + <value> <string encoding="cdata"><![CDATA[ + +"""\n + Check that catalog tables contain data which is coherent with actual objects.\n + Due to the number of objects to check, this function creates activites working\n + on, at maximum, bundle_object_count objects.\n +\n + bundle_object_count\n + Maximum number of objects to deal with in one transaction. \n + An activity is started after each successfull execution which\n + found bundle_object_count to work on.\n + bundle_offset\n + Offset the bundle, to allow walking along the catalog with\n + bundle_object_count increment.\n + property_override_method_id\n + Id of a method generating a property_override_dict as described below and\n + returning it.\n + property_override_dict (key: catalog column id, value: method id)\n + Defines custom methods to calculate reference column value.\n + None means that the column is not checked at all.\n + Otherwise, the function will be called on the object with no parameter\n + and must return the reference value for the column.\n +"""\n +MARKER = tuple()\n +bundle_object_count=int(bundle_object_count)\n +bundle_offset=int(bundle_offset)\n +null_value_list = (\'\', None, 0.0, 0) # Values which are all considered equal.\n +portal_catalog = context.getPortalObject().portal_catalog\n +\n +if property_override_method_id is None:\n + property_override_dict = {}\n +else:\n + property_override_dict = getattr(context, property_override_method_id)()\n +\n +if active_process is not None:\n + from Products.CMFActivity.ActiveResult import ActiveResult\n + result_list = []\n +\n +stock_line_list = context.Base_zGetAllFromStock(limit=(bundle_offset, bundle_object_count))\n +attribute_id_list = stock_line_list.names()\n +for stock_line in stock_line_list:\n + object_candidate_list = portal_catalog(uid=stock_line[\'uid\'])\n + if len(object_candidate_list) != 1:\n + raise Exception, \'There are %s object catalogged with uid %s, 1 was expected.\' % (len(object_candidate_list), repr(stock_line[\'uid\']))\n + actual_object = object_candidate_list[0].getObject()\n + if actual_object.getPortalType().endswith(\' Inventory\'):\n + continue\n + for attribute_id in attribute_id_list:\n + override_method_id = property_override_dict.get(attribute_id, MARKER)\n + if override_method_id is None:\n + continue\n + elif override_method_id is MARKER:\n + reference_value = actual_object.getProperty(key=attribute_id)\n + elif same_type(override_method_id, \'\'):\n + reference_value = getattr(actual_object, override_method_id)()\n + else:\n + reference_value = override_method_id(instance=actual_object)\n + catalog_value = stock_line[attribute_id]\n + reference_can_be_null_value = False\n + if same_type(reference_value, tuple()) or same_type(reference_value, list()):\n + for reference_value_item in reference_value:\n + if reference_value_item in null_value_list:\n + reference_can_be_null_value = True\n + break\n + else:\n + if reference_value in null_value_list:\n + reference_can_be_null_value = True\n + if reference_can_be_null_value and catalog_value in null_value_list:\n + continue\n + elif same_type(reference_value, ()):\n + if catalog_value not in reference_value:\n + message = \'%s.%s has candidate list %s, but catalog contains %s\' % (actual_object.getRelativeUrl(), attribute_id, repr(reference_value), repr(catalog_value))\n + if active_process is None:\n + print \'%s<br/>\' % (message, )\n + else:\n + result_list.append(message)\n + elif reference_value != catalog_value:\n + message = \'%s.%s = %s, but catalog contains %s\' % (actual_object.getRelativeUrl(), attribute_id, repr(reference_value), repr(catalog_value))\n + if active_process is None:\n + print \'%s<br/>\' % (message, )\n + else:\n + result_list.append(message)\n +\n +if len(stock_line_list) == bundle_object_count:\n + if active_process is None:\n + print \'<a href="%s?bundle_object_count=%s&bundle_offset:int=%s&property_override_method_id=%s">Next</a>\' % (context.REQUEST[\'URL\'], bundle_object_count, bundle_offset + bundle_object_count, property_override_method_id)\n + else:\n + context.getPortalObject().person_module.activate(active_process=active_process).ERP5Site_checkStockTable(bundle_object_count=bundle_object_count, bundle_offset=bundle_offset + bundle_object_count, property_override_method_id=property_override_method_id, active_process=active_process)\n +\n +if active_process is None:\n + return printed\n +else:\n + active_result = ActiveResult()\n + summary_list = []\n + summary_list.append(\'Entries %s..%s\' % (bundle_offset, bundle_offset + len(stock_line_list)))\n + severity = len(result_list)\n + if severity == 0:\n + summary_list.append(\'Success\')\n + else:\n + summary_list.append(\'Failed\')\n + active_result.edit(summary=\', \'.join(summary_list), severity=severity, detail=\'\\n\'.join(result_list))\n + return active_result\n + + +]]></string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_filepath</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>bundle_object_count=100, bundle_offset=0, property_override_method_id=None, active_process=None</string> </value> + </item> + <item> + <key> <string>errors</string> </key> + <value> + <tuple/> + </value> + </item> + <item> + <key> <string>func_code</string> </key> + <value> + <object> + <klass> + <global name="FuncCode" module="Shared.DC.Scripts.Signature"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>co_argcount</string> </key> + <value> <int>4</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>bundle_object_count</string> + <string>bundle_offset</string> + <string>property_override_method_id</string> + <string>active_process</string> + <string>_print_</string> + <string>_print</string> + <string>tuple</string> + <string>MARKER</string> + <string>int</string> + <string>None</string> + <string>null_value_list</string> + <string>_getattr_</string> +<string>context</string> + <string>portal_catalog</string> + <string>property_override_dict</string> + <string>getattr</string> + <string>Products.CMFActivity.ActiveResult</string> + <string>ActiveResult</string> + <string>result_list</string> + <string>stock_line_list</string> + <string>attribute_id_list</string> + <string>_getiter_</string> + <string>stock_line</string> + <string>_getitem_</string> + <string>object_candidate_list</string> + <string>len</string> + <string>Exception</string> + <string>repr</string> + <string>actual_object</string> + <string>attribute_id</string> + <string>override_method_id</string> + <string>reference_value</string> + <string>same_type</string> + <string>catalog_value</string> + <string>False</string> + <string>reference_can_be_null_value</string> + <string>list</string> + <string>reference_value_item</string> + <string>True</string> + <string>message</string> + <string>active_result</string> + <string>summary_list</string> + <string>severity</string> + </tuple> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>func_defaults</string> </key> + <value> + <tuple> + <int>100</int> + <int>0</int> + <none/> + <none/> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>ERP5Site_checkStockTable</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision index 44dfb1d0bc..b1ef57c1f7 100644 --- a/product/ERP5/bootstrap/erp5_core/bt/revision +++ b/product/ERP5/bootstrap/erp5_core/bt/revision @@ -1 +1 @@ -264 \ No newline at end of file +265 \ No newline at end of file -- 2.30.9