public function delete($targetWikiId, $wikiList)
 {
     $app = \F::app();
     foreach ($wikiList as $sourceWikiId => $images) {
         $sourceWikiLang = \WikiFactory::getVarValueByName('wgLanguageCode', $sourceWikiId);
         if (!empty($images)) {
             $removedImages = array();
             foreach ($images as $imageName) {
                 if (\PromoImage::fromPathname($imageName)->isValid()) {
                     $result = $this->removeSingleImage($targetWikiId, $imageName);
                     if ($result['status'] === 0) {
                         $removedImages[] = $imageName;
                     }
                 }
             }
         }
         if (!empty($removedImages)) {
             $memcKey = $this->helper->getMemcKey($sourceWikiId, $sourceWikiLang);
             $updateData = $this->syncAdditionalImages($sourceWikiId, $sourceWikiLang, $removedImages);
             // update in db
             if (!empty($updateData)) {
                 // updating city_visualization table
                 $this->model->saveVisualizationData($sourceWikiId, $updateData, $sourceWikiLang);
                 // purging interstitial cache
                 $app->wg->Memc->set($memcKey, null);
             }
         }
     }
     // since an admin can't delete main image we don't purge visualization list cache
     // as it happens during uploads
     return true;
 }
 public function saveVisualizationData($data, $langCode)
 {
     global $wgEnableUploads;
     wfProfileIn(__METHOD__);
     if (empty($wgEnableUploads)) {
         throw new Exception('promote-upload-image-uploads-disabled');
     }
     $cityId = $this->wg->cityId;
     $files = array('additionalImages' => array());
     $promoImages = array();
     $visualizationModel = new CityVisualization();
     $isCorpLang = $visualizationModel->isCorporateLang($langCode);
     foreach ($data as $fileType => $dataContent) {
         switch ($fileType) {
             case 'mainImageName':
                 $fileName = $dataContent;
                 // uploaded fileName that matches through infer type, means that
                 // file was not really uploaded, and was already present in DB
                 // FIXME: this mechanism is hacky, it should be more durable than string matching
                 $promoMainImage = PromoImage::fromPathname($fileName);
                 if ($promoMainImage->isType(PromoImage::MAIN)) {
                     //check if file exists on current wiki
                     $file = GlobalFile::newFromText($promoMainImage->getPathname(), $cityId);
                     if ($file->exists()) {
                         array_push($promoImages, $promoMainImage);
                     }
                 } else {
                     $promoMainImage = new PromoImage(PromoImage::MAIN, $this->wg->DBname);
                     $promoMainImage->processUploadedFile($fileName);
                     array_push($promoImages, $promoMainImage);
                 }
                 break;
             case 'additionalImagesNames':
                 $additionalImagesNames = $dataContent;
                 $additionalImages = $this->saveAdditionalFiles($additionalImagesNames);
                 $promoImages = array_merge($promoImages, $additionalImages);
                 break;
             case 'headline':
                 $headline = $dataContent;
                 break;
             case 'description':
                 $description = $dataContent;
                 break;
         }
     }
     //attempt to cleanup if there used to be a promo main image
     if (empty($promoMainImage)) {
         $promoMainImage = new PromoImage(PromoImage::MAIN, $this->wg->DBname);
         if ($promoMainImage->corporateFileByLang($this->wg->ContLanguageCode)->exists()) {
             $promoMainImage->deleteImageFromCorporate();
         }
     }
     $updateData = array('city_lang_code' => $langCode, 'city_headline' => $headline, 'city_description' => $description);
     $additionalImageNames = array();
     $modifiedImageNames = array();
     foreach ($promoImages as $promoImage) {
         if ($promoImage->isType(PromoImage::MAIN)) {
             if (!$promoImage->wasRemoved()) {
                 $updateData['city_main_image'] = $promoImage->getPathname();
             } else {
                 $updateData['city_main_image'] = null;
             }
         } else {
             if (!$promoImage->wasRemoved()) {
                 array_push($additionalImageNames, $promoImage->getPathname());
             }
         }
         if ($promoImage->isFileChanged() and !$promoImage->wasRemoved()) {
             array_push($modifiedImageNames, $promoImage->getPathname());
         }
     }
     $updateData['city_images'] = json_encode($additionalImageNames);
     WikiaLogger::instance()->debug("SpecialPromote", ['method' => __METHOD__, 'files' => $files, 'data' => $data, 'updateData' => $updateData, 'cityId' => $cityId]);
     $visualizationModel->saveVisualizationData($cityId, $updateData, $langCode);
     if (!empty($modifiedImageNames)) {
         $imageReviewState = $isCorpLang ? ImageReviewStatuses::STATE_UNREVIEWED : ImageReviewStatuses::STATE_AUTO_APPROVED;
         $visualizationModel->saveImagesForReview($cityId, $langCode, $modifiedImageNames, $imageReviewState);
     }
     $visualizationModel->updateWikiPromoteDataCache($cityId, $langCode, $updateData);
     // clear memcache so it's visible on site after edit
     $helper = new WikiGetDataForVisualizationHelper();
     $corpWikiId = $visualizationModel->getTargetWikiId($langCode);
     // wiki info cache
     $this->wg->memc->delete($helper->getMemcKey($cityId, $langCode));
     $this->wg->memc->delete((new WikiGetDataForPromoteHelper())->getMemcKey($cityId, $langCode));
     $this->wg->memc->delete((new WikiGetDataForPromoteHelper())->getImagesMemcKey($cityId, $langCode));
     // wiki list cache
     $this->wg->memc->delete($visualizationModel->getVisualizationWikisListDataCacheKey($corpWikiId, $langCode));
     // batches cache
     $this->wg->memc->delete($visualizationModel->getVisualizationBatchesCacheKey($corpWikiId, $langCode));
     wfProfileOut(__METHOD__);
 }