function changeApplicationXmlVersions($file, $versionNum, $subver) { $verStr = $versionNum . "_" . $subver; $newFiles = getNewFileName(); $doc = new DOMDocument(); $doc->load($file); $assests = $doc->getElementsByTagName("asset"); $modules = $doc->getElementsByTagName("module"); foreach ($newFiles as $nfi) { foreach ($assests as $ai) { $src = $ai->getAttribute("src"); if (strpos($src, $nfi) !== false) { //echo "ok<br />"; $ai->setAttribute("version", $verStr); } $src = $ai->nodeValue; if (strpos($src, $nfi) !== false) { $ai->setAttribute("version", $verStr); //echo "ok<br />"; } } foreach ($modules as $mi) { $src = $mi->getAttribute("src"); if (strpos($src, $nfi) !== false) { $mi->setAttribute("version", $verStr); //echo "ok $nfi<br />"; } } } $doc->save($file); }
function run() { $status = getStatus(); for ($i = 1; $i < 20; $i++) { $currentFile = 'Problem' . $i . '.c'; $programSource = file_get_contents($currentFile); // replace some stuff that is not needed at all $preprocessedSource = str_replace('#include <stdio.h>', '', $programSource); $preprocessedSource = str_replace('#include <assert.h>', '', $preprocessedSource); $preprocessedSource = str_replace('#include <math.h>', '', $preprocessedSource); $preprocessedSource = str_replace(': assert(0);', ':;', $preprocessedSource); $preprocessedSource = 'extern int __VERIFIER_nondet_int();' . $preprocessedSource; $preprocessedSource = replaceMain($preprocessedSource); // default error labels (0 - 59) for ($j = 0; $j < 60; $j++) { $finalProgramSource = setErrorLabel($j, $preprocessedSource); $state = 'unknown'; if (isset($status[$i][$j])) { $state = $status[$i][$j]; } file_put_contents(getNewFileName($i, $j, $state), $finalProgramSource); } // global error label $state = 'unknown'; if (isset($status[$i][$j])) { $state = $status[$i][$j]; } $finalProgramSource = str_replace('globalError:;', 'ERROR: goto ERROR;', $preprocessedSource); file_put_contents(getNewFileName($i, 60, $state), $finalProgramSource); } }
public function actionIndex() { exit; // prepare logger to dump logs every time one comes in Yii::getLogger()->autoFlush = 1; Yii::getLogger()->autoDump = true; function getNewFileName($fileName) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); $oldName = pathinfo($fileName, PATHINFO_FILENAME); return md5(uniqid($fileName)) . '.' . $ext; } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } function logParse($message) { Yii::log($message, CLogger::LEVEL_TRACE, 'parse'); Yii::getLogger()->flush(true); } logParse("Begin"); $begin = getmicrotime(); $regexpArray = array('p' => '~^p\\..+~iU', 'pl' => '~^pl\\..+~iU', 'plx' => '~^plx\\..+~iU'); $titlesArray = array('p' => '', 'pl' => 'Плитка из камня', 'plx' => 'Плитка из камня с подсветкой'); $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->uploadPath . DIRECTORY_SEPARATOR . 'parse_tile'; $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stones = array(); $imagesFiles = array(); // Обработка серий foreach ($seriesList as $skey => $seriesPath) { //if($skey > 1) break; $seriesAlias = basename($seriesPath); if ($seriesAlias == '.' || $seriesAlias == '..') { continue; } $series = Series::model()->findByAlias($seriesAlias); if (is_null($series)) { logParse("Серия " . $seriesAlias . " не найдена"); echo "Серия " . $seriesAlias . " не найдена<br />"; exit; } echo '<h1>' . $series->title . '</h1>'; logParse("Series " . $series->title); $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stonesCounter = 0; $stoneImagesCounter = 0; $sort = 0; foreach ($stonesList as $stonePath) { $stoneTitle = basename($stonePath); if ($stoneTitle == '.' || $stoneTitle == '..') { continue; } //echo '<h3>' . $stoneTitle . '</h3>'; $stonesCounter++; $sort += 100; $stone = new Stone(); $stone->type_id = 2; $stone->series_id = $series->id; $stone->title = $stoneTitle; $stone->metatitle = $stone->keywords = $stone->description = $stone->title; // Генерация алиаса $alias = \yupe\helpers\YText::translit($stone->title) . '-tile'; if ($stone->findByAlias($alias) !== null) { $alias = $alias . '-' . mt_rand(10000, 99999); } $stone->alias = $alias; $stone->sort = $sort; $imagesList = array(); foreach ($regexpArray as $key => $regexp) { foreach (CFileHelper::findFiles($stonePath) as $file) { //echo $file . '<br />'; if (preg_match($regexp, basename($file))) { $imagesList[$key] = $file; } } } $stoneImages = array(); foreach ($imagesList as $key => $item) { $itemName = basename($item); $newName = getNewFileName($item); $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName); if (preg_match($regexpArray['p'], $itemName)) { $stone->image = $newName; //echo $itemName . '<br />'; } else { $image = new StoneImage(); $image->title = $titlesArray[$key]; $image->image = $newName; $stoneImages[] = $image; } //echo $itemName . '<br />'; $stoneImagesCounter++; } $stone->images = $stoneImages; $stones[] = $stone; } echo 'Камней: ' . $stonesCounter . '<br />'; echo 'Изображений: ' . $stoneImagesCounter . '<br />'; echo '<hr>'; } // Сохраняем камни и изображения в БД foreach ($stones as $stone) { logParse($stone->title); if ($stone->save(false)) { $imagesCounter = 0; foreach ($stone->images as $image) { $imagesCounter += 100; $image->item_id = $stone->id; $image->sort = $imagesCounter; if (!$image->save(false)) { logParse($image->image . ' - error'); echo $image->image . ' - error<br />'; } } logParse('success'); } else { logParse('error'); //echo $stone->title . ' - error<br />'; //var_dump($stone->getErrors()); } } // Копируем изображения foreach ($imagesFiles as $image) { copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']); } $end = getmicrotime(); $time = $end - $begin; echo "Время выполнения скрипта: " . $time . "с."; logParse("Время выполнения скрипта: " . $time . "с."); echo '<hr>'; }
public function actionIndex() { // prepare logger to dump logs every time one comes in Yii::getLogger()->autoFlush = 1; Yii::getLogger()->autoDump = true; function getNewFileName($fileName) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); $oldName = pathinfo($fileName, PATHINFO_FILENAME); return md5(uniqid($fileName)) . '.' . $ext; } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } function logParse($message) { Yii::log($message, CLogger::LEVEL_TRACE, 'parse'); Yii::getLogger()->flush(true); } logParse("Begin"); $begin = getmicrotime(); /* $regexpArray = array( 'mm' => '~^mm[^x]*\..+~iU', 'fr1' => '~^fr[\d]{0,2}[^x]*\..+~iU', 'sl' => '~^sl[\d]{0,2}[^x]*\..+~iU', 'b1' => '~^b1[^x]*\..+~iU', 'b2' => '~^b2[^x]*\..+~iU', 'frx' => '~^fr[\d]{0,2}x.*\..+~iU', 'slx' => '~^slx.*\..+~iU', 'b1x' => '~^b1x.*\..+~iU', 'b2x' => '~^b2x.*\..+~iU', ); * */ $regexpArray = array('mm' => '~^mm\\..+~iU', 'fr' => '~^fr\\..+~iU', 'fr2' => '~^fr2\\..+~iU', 'sl' => '~^sl\\..+~iU', 'b1' => '~^b1\\..+~iU', 'b2' => '~^b2\\..+~iU', 'frx' => '~^frx.*\\..+~iU', 'slx' => '~^slx.*\\..+~iU', 'b1x' => '~^b1x.*\\..+~iU', 'b2x' => '~^b2x.*\\..+~iU'); $titlesArray = array('mm' => '', 'fr' => 'Фрагмент', 'fr2' => 'Фрагмент 2', 'sl' => 'Слеб', 'b1' => 'Bookmatch 1', 'b2' => 'Bookmatch 2', 'frx' => 'Фрагмент с подсветкой', 'slx' => 'Слеб с подсветкой', 'b1x' => 'Bookmatch 1 с подсветкой', 'b2x' => 'Bookmatch 2 с подсветкой'); $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->geParsePath(); $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stones = array(); $imagesFiles = array(); // Обработка серий foreach ($seriesList as $seriesPath) { $seriesAlias = basename($seriesPath); if ($seriesAlias == '.' || $seriesAlias == '..') { continue; } $series = Series::model()->findByAlias($seriesAlias); if (is_null($series)) { logParse("Серия " . $seriesAlias . " не найдена"); echo "Серия " . $seriesAlias . " не найдена<br />"; exit; } echo '<h1>' . $series->title . '</h1>'; logParse("Series " . $series->title); $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stonesCounter = 0; $stoneImagesCounter = 0; $sort = 0; foreach ($stonesList as $stonePath) { $stoneTitle = basename($stonePath); if ($stoneTitle == '.' || $stoneTitle == '..') { continue; } //echo '<h3>' . $stoneTitle . '</h3>'; $stonesCounter++; $sort += 100; $stone = new Stone(); $stone->series_id = $series->id; $stone->title = $stoneTitle; $stone->metatitle = $stone->keywords = $stone->description = $stone->title; $stone->generateAlias(); $stone->sort = $sort; $imagesList = array(); foreach ($regexpArray as $key => $regexp) { foreach (CFileHelper::findFiles($stonePath) as $file) { if (preg_match($regexp, basename($file))) { $imagesList[$key] = $file; } } } $stoneImages = array(); foreach ($imagesList as $key => $item) { $itemName = basename($item); $newName = getNewFileName($item); $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName); if (preg_match($regexpArray['mm'], $itemName)) { $stone->image = $newName; //echo $itemName . '<br />'; } else { $image = new StoneImage(); $image->title = $titlesArray[$key]; $image->image = $newName; $stoneImages[] = $image; } //echo $itemName . '<br />'; $stoneImagesCounter++; } $stone->images = $stoneImages; $stones[] = $stone; } echo 'Камней: ' . $stonesCounter . '<br />'; echo 'Изображений: ' . $stoneImagesCounter . '<br />'; echo '<hr>'; } // Сохраняем камни и изображения в БД foreach ($stones as $stone) { logParse($stone->title); if ($stone->save(false)) { $imagesCounter = 0; foreach ($stone->images as $image) { $imagesCounter += 100; $image->item_id = $stone->id; $image->sort = $imagesCounter; if (!$image->save(false)) { logParse($image->image . ' - error'); echo $image->image . ' - error<br />'; } } logParse('success'); } else { logParse('error'); //echo $stone->title . ' - error<br />'; //var_dump($stone->getErrors()); } } // Копируем изображения foreach ($imagesFiles as $image) { copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']); } $end = getmicrotime(); $time = $end - $begin; echo "Время выполнения скрипта: " . $time . "с."; logParse("Время выполнения скрипта: " . $time . "с."); echo '<hr>'; }
public function actionIndex() { exit; $prefix = $_GET['prefix']; // prepare logger to dump logs every time one comes in Yii::getLogger()->autoFlush = 1; Yii::getLogger()->autoDump = true; function getNewFileName($fileName) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); $oldName = pathinfo($fileName, PATHINFO_FILENAME); return md5(uniqid($fileName)) . '.' . $ext; } function logParse($message) { Yii::log($message, CLogger::LEVEL_TRACE, 'parse'); Yii::getLogger()->flush(true); } //logParse("Begin"); $begin = getmicrotime(); // Начало $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->uploadPath . DIRECTORY_SEPARATOR . 'parse'; $csvFile = $parsePath . DIRECTORY_SEPARATOR . "realty_{$prefix}.csv"; $csvData = file_get_contents($csvFile); $csvData = mb_convert_encoding($csvData, 'utf-8', 'windows-1251'); $csvData = explode("\r\n", $csvData); //var_dump($csvData); $imagesFiles = []; $galleries = []; foreach ($csvData as $key => $row) { if ($key == 0) { continue; } //if($key >= 50) // break; $fields = explode(";", $row); // Номер $num = (int) $fields[0]; $imgFolderNum = $fields[1]; if (empty($num)) { continue; } // Изображения if ($imgFolderNum != '' && $imgFolderNum != '-') { $imagesPath = $parsePath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $imgFolderNum; if (file_exists($imagesPath)) { if (key_exists($imgFolderNum, $galleries)) { continue; } $gallery = new RealtyGallery(); $gallery->title = trim($fields[6]); $gallery->xls_id = $imgFolderNum; $galleries[$imgFolderNum] = $gallery; $imagesList = FileHelper::findFilesNatSort($imagesPath); $itemImages = []; foreach ($imagesList as $key => $item) { //echo $item . '<br>'; $itemName = basename($item); $newName = getNewFileName($item); $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName); $itemImages[] = $newName; } $gallery->images = $itemImages; } } } echo 'Галерей: ' . count($galleries) . '<br />'; echo 'Изображений: ' . count($imagesFiles) . '<br />'; echo '<hr>'; /* foreach($imagesFiles as $key => $image) { echo ++$key . ' - ' . $image['fullPath'] . '<br />'; } * */ //exit(); // Сохраняем массив с изображениями в файл file_put_contents($parsePath . DIRECTORY_SEPARATOR . "images_{$prefix}.txt", json_encode($imagesFiles)); unset($imagesFiles); // Сохраняем галереи и изображения в БД foreach ($galleries as $gallery) { //logParse($realtyItem->title); if ($gallery->save()) { // Изображения $imagesCounter = 0; foreach ($gallery->images as $imageName) { $image = new RealtyGalleryImage(); $image->image = $imageName; $imagesCounter += 100; $image->item_id = $gallery->id; $image->sort = $imagesCounter; if (!$image->save(false)) { //logParse($image->image . ' - error'); echo $image->image . ' - error<br />'; } unset($image); } //logParse('success'); } else { //logParse('error'); echo $gallery->title . ' - error<br />'; var_dump($gallery->getErrors()); } } $end = getmicrotime(); $time = $end - $begin; echo "Время выполнения скрипта: " . $time . "с."; //logParse("Время выполнения скрипта: " . $time . "с."); echo '<hr>'; }