Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php set_time_limit(0);
- $_SERVER['DOCUMENT_ROOT'] = ".";
- define("NO_KEEP_STATISTIC", true);
- define("NOT_CHECK_PERMISSIONS", true);
- $prolog = $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php";
- if (file_exists($prolog)) include($prolog); else die("Указанный каталог не является корневой директорией сайта на 1С-Битрикс" . PHP_EOL);
- $arFilesCache = array();
- $result = $DB->Query('SELECT ID, FILE_NAME, SUBDIR FROM b_file WHERE MODULE_ID = "iblock"');
- while ($row = $result->Fetch()) {
- $arFilesCache[$row["ID"]] = $row['SUBDIR'] . '/' . $row['FILE_NAME'];
- }
- $f = fopen($_SERVER["DOCUMENT_ROOT"] . "/duplicates.txt", "r");
- $dublicates = [];
- while(!feof($f)) {
- $data = explode("./", fgets($f));
- $imPath = trim($data[1]);
- if ($imPath !== null && $imPath !== "") {
- $dublicates[] = "iblock/" . trim($data[1]);
- }
- }
- foreach ($arFilesCache as $id => $path) {
- if ($path !== "") {
- if (in_array($path, $dublicates)) {
- if (strpos($path, '.png') !== false ||
- strpos($path, '.jpg') !== false) {
- CFile::delete($id);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement