Exemple #1
0
 /**
  * Initialize the sync process
  *
  * @return void
  */
 public function start()
 {
     // Check for a valid token. If invalid, send a 403 with the error message.
     JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
     // Put in a buffer to silence noise.
     ob_start();
     // Initiate an empty state
     CmcSyncerState::resetState();
     $state = CmcSyncerState::getState();
     $input = JFactory::getApplication()->input;
     $lists = $input->getString('lists');
     $chimp = new CmcHelperChimp();
     $listStats = $chimp->lists(array('list_id' => $lists));
     $names = array();
     foreach ($listStats['data'] as $key => $list) {
         $state->lists[$key] = array();
         $state->lists[$key]['mc_id'] = $list['id'];
         $state->lists[$key]['name'] = $list['name'];
         $state->lists[$key]['toSync'] = $list['stats']['member_count'];
         $names[] = $list['name'];
         // Delete the old list info
         CmcHelperList::delete($list['id']);
         // Add the new list info
         $listModel = $this->getModel('List', 'cmcModel');
         $listModel->save($list);
         // Add the joomla list id
         $state->lists[$key]['id'] = $listModel->getState('list.id');
         // Delete users in that list
         CmcHelperUsers::delete($list['id']);
     }
     $state->header = JText::sprintf('COM_CMC_LISTS_TO_SYNC', count($state->lists));
     $state->message = JText::sprintf('COM_CMC_LISTS_TO_SYNC_DESC', '"' . implode('", "', $names) . '"', $state->lists[0]['name']);
     $state->offset = 0;
     CmcSyncerState::setState($state);
     $this->sendResponse($state);
 }