public function upload($targetWikiId, $wikiList) { $isError = false; $targetWikiLang = \WikiFactory::getVarValueByName('wgLanguageCode', $targetWikiId); foreach ($wikiList as $sourceWikiId => $images) { $sourceWikiLang = \WikiFactory::getVarValueByName('wgLanguageCode', $sourceWikiId); $uploadedImages = array(); foreach ($images as $image) { $result = $this->uploadSingleImage($image['id'], $image['name'], $targetWikiId, $sourceWikiId); if ($result['status'] === 0) { $uploadedImages[] = ['id' => $result['id'], 'name' => $result['name']]; $this->finalizeImageUploadStatus($image['id'], $sourceWikiId, \ImageReviewStatuses::STATE_APPROVED); } else { // on error move image back to review, so that upload could be retried $this->finalizeImageUploadStatus($image['id'], $sourceWikiId, \ImageReviewStatuses::STATE_UNREVIEWED); $isError = true; } } if (!empty($uploadedImages) && !in_array($sourceWikiId, $this->corporatePageIds)) { // if images uploaded but not from import script $updateData = $this->getImagesToUpdateInDb($sourceWikiId, $sourceWikiLang, $uploadedImages); if (!empty($updateData)) { // updating city_visualization table $this->model->saveVisualizationData($sourceWikiId, $updateData, $sourceWikiLang); // purging interstitial cache $memcKey = $this->helper->getMemcKey($sourceWikiId, $sourceWikiLang); \F::app()->wg->Memc->set($memcKey, null); } } } if (!empty($uploadedImages) && in_array($sourceWikiId, $this->corporatePageIds)) { // if images uploaded but not from import script // saving changes in city_visualization_images table and purging cache $this->addImagesToPromoteDb($targetWikiId, $targetWikiLang, $uploadedImages); $this->model->purgeWikiPromoteDataCache($targetWikiId, $targetWikiLang); } if (!empty($uploadedImages)) { // if wikis have been added by import script or regularly by Special:Promote $this->model->purgeVisualizationWikisListCache($targetWikiId, $targetWikiLang); } return !$isError; }
/** * Called once a file has been deleted. * * @param $file reference to the deleted file * @param $oldimage in case of the deletion of an old image, the name of the old file * @param $article in case all revisions of the file have been deleted a reference to the article associated with the file. * @see http://www.mediawiki.org/wiki/Manual:Hooks/FileDeleteComplete */ public static function onFileDeleteComplete($file, $oldimage, $page) { /** * No $page when deleting an old image ($oldimage). Nothing to do. * * @see FileDeleteForm::doDelete() */ if (!$page instanceof Page) { return true; } global $wgCityId, $wgContLang; $visualization = new CityVisualization(); $visualization->removeImageFromReviewByName($wgCityId, $page->getTitle()->getText(), $wgContLang->getCode()); $visualization->purgeWikiPromoteDataCache($wgCityId, $wgContLang->getCode()); return true; }