Esempio n. 1
0
 /**
  * Do smth when called over ajax
  * @return mixed[]
  */
 public static function doAjaxStuff($parameters = array())
 {
     $errors = static::checkAccessPermissions(array('CHECK_CSRF' => true));
     $data = array();
     if (count($errors) == 0) {
         $request = static::getRequest();
         // action: process ajax
         if (isset($request['POST']['AJAX_CALL'])) {
             if ($request['POST']['ACT'] == 'REINDEX') {
                 $process = new Search\ReindexProcess($request['POST']['ACT_DATA']);
             }
             if ($request['POST']['step'] == 0) {
                 if (is_array($request['POST']['ACT_DATA']['TYPES'])) {
                     $all = false;
                     foreach ($request['POST']['ACT_DATA']['TYPES'] as $k => $type) {
                         if ($type == '') {
                             $all = true;
                             break;
                         }
                         $request['POST']['ACT_DATA']['TYPES'][$k] = intval($type);
                     }
                     $optValue = array();
                     if (!$all) {
                         $optValue = array_unique($request['POST']['ACT_DATA']['TYPES']);
                     }
                     Search\Finder::setIndexedTypes($optValue);
                 }
                 if (is_array($request['POST']['ACT_DATA']['LANG'])) {
                     $langs = TypeHelper::getLanguageList();
                     $all = false;
                     foreach ($request['POST']['ACT_DATA']['LANG'] as $k => $lang) {
                         if ($lang == '') {
                             $all = true;
                             break;
                         }
                         if (!isset($langs[$lang])) {
                             unset($request['POST']['ACT_DATA']['LANG'][$k]);
                         }
                     }
                     $optValue = array();
                     if (!$all) {
                         $optValue = array_unique($request['POST']['ACT_DATA']['LANG']);
                     }
                     Search\Finder::setIndexedLanguages($optValue);
                 }
                 $process->reset();
             }
             try {
                 @set_time_limit(0);
                 $data['PERCENT'] = $process->performStage();
                 $data['NEXT_STAGE'] = $process->getStageCode();
             } catch (Main\SystemException $e) {
                 $errors[] = $e->getMessage();
             }
             if ($data['PERCENT'] == 100) {
                 //$GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
             }
         }
     }
     return array('ERRORS' => $errors, 'DATA' => $data);
 }