VM1 to VM2: Customs Table needs repairing after dumping all the data

Started by mbarry, January 15, 2014, 16:15:20 PM

Previous topic - Next topic

mbarry

VM 2.0.26a
Joomla 2.5.17

Scenario:
      To provide a repeatable clean install and migration process for VM2
      Run "Remove Virtuemart Data" - this deletes all the data in the VM Tables identified by uninstall_data.sql including table `#__virtuemart_customs`
      Run "Install or If necessary update tables" - this recreates any deleted Tables (as identified in install.sql) and installs any required data (as defined in script.virtuemart.php)
      Run the VM2 Migration tool with "everything" selected".
     
      As administrator
      Select Product->Products
      Select any Product
      Select Custom Fields Tab
      In the "Search for Related Products" type in a couple of characters of a known sku, a popup with items should be displayed with images of products. If this error occurs only blank images will appear and can not be saved.

Issue:
      Related Products functionality does not work after the DB has been purged with "Remove Virtuemart Data" and reset with "Install or If necessary update tables".
     
      There are two entries created on installation in the virtuemart_customs TABLE that must be there. The first entry configures the system to support Related Products
      and the second supports related categories.   
      Problem is that the `#__virtuemart_customs` is never preloaded with the original data again.

Solution:
      Modified script.virtuemart.php to include new function checkAddDefaultCustoms() which installs the required sql data for Related Products and Related Categories.
     
       Call function from update($loadVm = true) after line 253 as $this->checkAddDefaultCustoms();
       
       Insert new function after line 532

Affected files:
      administrator/components/com_virturemart/install/script.virtuemart.php

code snip for checkAddDefaultCustoms() is given below

      /**
       * Checks if both types of default customs are set
       * @author M. Barry
       */   
      private function checkAddDefaultCustoms(){
      
         $q = 'SELECT `virtuemart_custom_id` FROM `#__virtuemart_customs` WHERE `field_type` = "R" ';
      
         $this->_db = JFactory::getDbo();
         $this->_db->setQuery($q);
         $res = $this->_db ->loadResult();
      
         if(empty($res)){
            $q = "INSERT INTO `#__virtuemart_customs` ( `virtuemart_custom_id`, `custom_parent_id`, `admin_only`, `custom_title`, `custom_tip`, `custom_value`, `custom_field_desc`, `field_type`, `is_list`, `is_hidden`, `is_cart_attribute`, `published`, `created_on`, `created_by`, `modified_on`, `modified_by`, `locked_on`, `locked_by`) VALUES
              (1,0, 0, 'COM_VIRTUEMART_RELATED_PRODUCTS', 'COM_VIRTUEMART_RELATED_PRODUCTS_TIP', '', 'COM_VIRTUEMART_RELATED_PRODUCTS_DESC', 'R', 0, 0, 0, 1, '2011-05-25 21:52:43', 62, '2011-05-25 21:52:43', 62, '0000-00-00 00:00:00', 0);";
            $this->_db->setQuery($q);
            $this->_db->query();
         }
      
         $q = 'SELECT `virtuemart_custom_id` FROM `#__virtuemart_customs` WHERE `field_type` = "Z" ';
      
         $this->_db->setQuery($q);
         $res = $this->_db ->loadResult();
      
         if(empty($res)){
            $q = "INSERT INTO `#__virtuemart_customs` ( `virtuemart_custom_id`, `custom_parent_id`, `admin_only`, `custom_title`, `custom_tip`, `custom_value`, `custom_field_desc`, `field_type`, `is_list`, `is_hidden`, `is_cart_attribute`, `published`, `created_on`, `created_by`, `modified_on`, `modified_by`, `locked_on`, `locked_by`) VALUES
            (2,0, 0, 'COM_VIRTUEMART_RELATED_CATEGORIES', 'COM_VIRTUEMART_RELATED_CATEGORIES_TIP', NULL, 'COM_VIRTUEMART_RELATED_CATEGORIES_DESC', 'Z', 0, 0, 0, 1, '0000-00-00 00:00:00', 0, '0000-00-00 00:00:00', 0, '0000-00-00 00:00:00', 0);";
            $this->_db->setQuery($q);
            $this->_db->query();
         }
      
      }