News:

Support the VirtueMart project and become a member

Main Menu

VM1 to VM2: Porting of waitinglist missing

Started by mbarry, January 16, 2014, 06:37:47 AM

Previous topic - Next topic

mbarry

VM 2.0.26a/d
Joomla 2.5.17

Scenario:
      Run the VM2 Migration tool with "everything" selected".
         
Issue:
      The table vm_waiting_list is not ported to virtuemart_waitingusers
       
Solution:
      A new function portVm1WaitingList() has been created and included in helpers/migrator.php
     
      Call function from migrateAllInOne() after line 208 as $result = $this->portVm1WaitingList()

      install.sql is also modified to include new entry " `waitinglist` longblob, "  in Table `#__virtuemart_migration_oldtonew_ids`
 
Affected files:
      administrator/components/com_virtuemart/helpers/migrator.php  line 208 and 2167
      administrator/components/com_virturemart/install/install.sql  line 424 

code snip for portVm1WaitingList()

   /**
    *
    * Port VM1 Waiting List
    * Assumes userId is maintained between VM1 and VM2 which they will be if JUpgrade is used
    *
    * @author M. Barry
    */
   public function portVm1Waitinglist() {
   
      if($this->_stop || (microtime(true)-$this->starttime) >= ($this->maxScriptTime)){
         return;
      }
      vmInfo('Migration: processing Waitinglist ..... ');
      $alreadyKnownIds = $this->getMigrationProgress('waitinglist');
      $alreadyProcessed = count($alreadyKnownIds);
      $completionStatus = false;
      $i = 0;
   
      $q = 'SELECT * FROM `#__vm_waiting_list` WHERE 1';
      $this->_db->setQuery($q);
      $waitinglist = $this->_db->loadAssocList();
      $maxItems = count($waitinglist);
      
      if (empty($waitinglist)) {
         vmWarn('portVm1Waitinglist : No VM1 waiting list exist');
         return;
      }
   
      foreach ($waitinglist as $waitingUser) {
         
         if(array_key_exists($waitingUser['waiting_list_id'],$alreadyKnownIds)) {
            continue;
         }
            
         $productIdMapping = $this->getMigrationProgress('products');
         $productId = $productIdMapping[$waitingUser['product_id']];
         
         if(empty($productId)) {
            vmError('portVm1Waitinglist : product could not be found ID '.$waitingUser['product_id']);
            continue;
         }
         // Migration process should ensure VM2 userId is identical to VM1 userId if JUpgrade is used to migrate the VM1 tables to VM2
         // In this case a userId = 0 is valid for non-registered users on product queries
         $userId = $waitingUser['user_id'];
         
         if($waitingUser['user_id'] != '0') {
            $q = 'SELECT `virtuemart_user_id` FROM `#__virtuemart_vmusers` WHERE `#__virtuemart_vmusers`.`virtuemart_user_id`= "'.$waitingUser['user_id'].'"';
            $this->_db->setQuery($q);
            $userId = $this->_db->loadResult();
               
            if(empty($userId)) {
               vmError('portVm1Waitinglist : User does not exist ID '.$userId);
               continue;
            }
         }
            
         $data['virtuemart_product_id'] = $productId;
         $data['virtuemart_user_id'] = $userId;
         $data['notify_email'] = $waitingUser['notify_email'];
         $data['notified'] = $waitingUser['notified'];
         $data['notify_date'] = $data['created_on'] =  $this->_changeToStamp($waitingUser['notify_date']);
         $data['created_by'] = $userId;
         
         $model = VmModel::getModel ('waitinglist');
         if (!$model->adduser($data)) {
            $errors = $model->getErrors ();
            if(!empty($error)) {
               vmError ('portVm1Waitinglist : '.$error);
            }
         }
                  
         $alreadyKnownIds[$waitingUser['waiting_list_id']] = (int) $productId;
         
         $i++;
         if((microtime(true)-$this->starttime) >= ($this->maxScriptTime)){
            break;
         }
      }
      $this->storeMigrationProgress('waitinglist',$alreadyKnownIds);
      vmInfo('Migration: '.$i.' waiting users processed this run, already processed '.$alreadyProcessed.' of '.$maxItems);
      if(($alreadyProcessed+$i) == $maxItems) $completionStatus = true;
      return $completionStatus;
   }