/**
  * Main action for editing hub modules
  */
 public function editHubAction()
 {
     global $wgCityId;
     if (!$this->checkAccess()) {
         return false;
     }
     $this->retriveDataFromUrl();
     $this->wg->Out->addJsConfigVars(['wgEditHubModuleIdSelected' => $this->selectedModuleId, 'wgEditHubModuleIdPopularVideos' => WikiaHubsModulePopularvideosService::MODULE_ID, 'wgEditHubModuleIdFeaturedVideo' => WikiaHubsModuleFeaturedvideoService::MODULE_ID]);
     $this->checkDate($this->date);
     $this->flashMessage = FlashMessages::pop();
     $modulesData = $this->editHubModel->getModulesData($wgCityId, $this->date, $this->selectedModuleId);
     $this->prepareLayoutData($this->selectedModuleId, $modulesData);
     $this->response->addAsset('resources/jquery/jquery.validate.js');
     $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHub.js');
     $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHubNavigation.js');
     $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/jquery.MetaData.js');
     $selectedModuleValues = $modulesData['moduleList'][$this->selectedModuleId]['data'];
     $module = WikiaHubsModuleService::getModuleByName($this->editHubModel->getNotTranslatedModuleName($this->selectedModuleId), $wgCityId);
     $form = new FormBuilderService(EditHubModel::FORM_FIELD_PREFIX);
     $form->setFields($module->getFormFields());
     if ($this->request->wasPosted()) {
         $selectedModuleValues = $this->request->getParams();
         $selectedModuleValues = $module->filterData($selectedModuleValues);
         $isValid = $form->validate($selectedModuleValues);
         if ($isValid) {
             $this->editHubModel->saveModule(['cityId' => $wgCityId, 'langCode' => $this->wg->ContLang->getCode(), 'verticalId' => WikiFactoryHub::getInstance()->getCategoryId($wgCityId)], $this->date, $this->selectedModuleId, $selectedModuleValues, $this->wg->user->getId());
             $this->purgeCache($module);
             FlashMessages::put(wfMessage('edit-hub-module-save-ok', $modulesData['activeModuleName'])->escaped());
             $nextUrl = $this->getNextModuleUrl();
             $this->response->redirect($nextUrl);
         } else {
             $this->errorMessage = wfMessage('edit-hub-module-save-error')->escaped();
         }
     }
     $form->setFieldsValues($selectedModuleValues);
     $this->moduleName = $modulesData['activeModuleName'];
     $this->moduleContent = $module->renderEditor(['form' => $form]);
     $this->overrideTemplate('editHub');
 }
Beispiel #2
0
 /**
  * @group Slow
  * @slowExecutionTime 0.05797 ms
  * Test saving module when there is data already saved
  */
 public function testSaveModuleUpdate()
 {
     $params = array('langCode' => 'pl', 'cityId' => 123456, 'verticalId' => WikiFactoryHub::CATEGORY_ID_GAMING);
     $dataToInsert = array('lang' => $params['langCode'], 'sectionId' => $params['sectionId'], 'verticalId' => $params['verticalId'], 'timestamp' => 1234567, 'moduleId' => WikiaHubsModulePollsService::MODULE_ID, 'data' => array('test1' => 'test2', 'hola hola' => 'espaniola'), 'editorId' => 666);
     $dbMock = $this->getMock('DatabaseMysql', array('selectField', 'update'));
     $dbMock->expects($this->once())->method('selectField')->will($this->returnValue(1));
     $dbMock->expects($this->once())->method('update')->with($this->equalTo(EditHubModel::HUBS_TABLE_NAME), $this->equalTo(array('module_data' => json_encode($dataToInsert['data']), 'last_editor_id' => $dataToInsert['editorId'])), $this->equalTo(array('lang_code' => $dataToInsert['lang'], 'vertical_id' => $dataToInsert['verticalId'], 'module_id' => $dataToInsert['moduleId'], 'hub_date' => $dbMock->timestamp($dataToInsert['timestamp']), 'city_id' => 123456)));
     $mockGetDB = $this->getGlobalFunctionMock('wfGetDB');
     $mockGetDB->expects($this->any())->method('wfGetDB')->will($this->returnValue($dbMock));
     $model = new EditHubModel();
     $model->saveModule($params, $dataToInsert['timestamp'], $dataToInsert['moduleId'], $dataToInsert['data'], $dataToInsert['editorId']);
 }