Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/calendar/lib/update/ |
Upload File : |
<?php namespace Bitrix\Calendar\Update; use Bitrix\Main\Loader; use Bitrix\Main\Update\Stepper; class LocationDuplicateCleaner extends Stepper { protected static $moduleId = "calendar"; public static function className() { return get_called_class(); } /** * @param array $result * @return bool * @throws \Bitrix\Main\LoaderException */ public function execute(array &$result): bool { if (!Loader::includeModule("calendar")) { return self::FINISH_EXECUTION; } if ($dataToClean = $this->getEntryDataToClean()) { $this->cleanDuplicates((int)$dataToClean['PARENT_ID'], (int)$dataToClean['LASTID']); return self::CONTINUE_EXECUTION; } return self::FINISH_EXECUTION; } /** * @return array|null */ private function getEntryDataToClean(): ?array { global $DB; $strSql = "select MAX(ID) as LASTID, PARENT_ID, COUNT(1) as CNT from b_calendar_event where CAL_TYPE='location' group by PARENT_ID having CNT > 1 order by ID desc limit 1"; $res = $DB->Query($strSql); if ($entry = $res->Fetch()) { return $entry; } return null; } /** * @param int $parentId parent id which will be used to delete duplicates * @param int $entryToLeave id of entry which will not be deleted * @return void */ private function cleanDuplicates(int $parentId, int $entryToLeave): void { global $DB; $strSql = "delete from b_calendar_event where CAL_TYPE = 'location' and PARENT_ID = '".$parentId."' and ID != '".$entryToLeave."' limit 1000"; $DB->Query($strSql); } }