1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
messagecleaner.php
См. документацию.
1<?php
2
3namespace Bitrix\Forum\Internals;
4
5use \Bitrix\Main;
6use \Bitrix\Forum;
7
9{
10 protected static int $limit = 10;
11 protected static $moduleId = "forum";
12
13 public static function getTitle(): string
14 {
15 return 'Message cleaner';
16 }
17
18 public function execute(array &$option)
19 {
20 $option["steps"] = 1;
21 $option["count"] = 1;
22 if (self::do() > 0)
23 {
24 return self::FINISH_EXECUTION;
25 }
26 return self::CONTINUE_EXECUTION;
27 }
28
29 private static function do()
30 {
31 $limit = self::$limit;
33SELECT ID, FORUM_ID, TOPIC_ID, MESSAGE_ID, NEW_TOPIC, APPROVED, PARAM1, PARAM2, AUTHOR_ID
34FROM b_forum_service_deleted_message
35ORDER BY ID ASC
36LIMIT {$limit}
37SQL
38 );
39 $votes = [];
41 $last = null;
42 while ($message = $dbRes->fetch())
43 {
44 if ($message["PARAM1"] == 'VT')
45 {
46 $votes[] = $message["PARAM2"];
47 }
48
49 $selectSql = "SELECT * FROM b_forum_file where MESSAGE_ID=" . intval($message['MESSAGE_ID']) . " ORDER BY ID ASC";
50
51 $dbFileRes = Main\Application::getConnection()->query($selectSql);
52
53 if ($dbFileRes && ($file = $dbFileRes->fetch()))
54 {
55 do
56 {
57 \CFile::Delete($file["FILE_ID"]);
58 }
59 while ($file = $dbFileRes->fetch());
60 $deleteSql = "DELETE FROM b_forum_file where MESSAGE_ID=" . intval($message['MESSAGE_ID']);
61 Main\Application::getConnection()->queryExecute($deleteSql);
62 }
63
64 $USER_FIELD_MANAGER->Delete("FORUM_MESSAGE", $message["MESSAGE_ID"]);
65 $limit--;
66 $last = $message;
67 }
68
69 if (!empty($votes) && IsModuleInstalled("vote") && \CModule::IncludeModule("vote"))
70 {
71 array_map(function($voteId) {
72 \CVote::Delete($voteId);
73 }, $votes);
74 }
75
76 if ($last)
77 {
78 Main\Application::getConnection()->queryExecute(<<<SQL
79DELETE FROM b_forum_service_deleted_message WHERE ID <= {$last['ID']}
80SQL
81 );
82 }
83 return $limit;
84 }
85
86 public static function runForTopic(int $topicId)
87 {
88 if (Main\Application::getConnection()->getType() === 'pgsql')
89 {
90 Main\Application::getConnection()->queryExecute(<<<SQL
91INSERT INTO b_forum_service_deleted_message
92 (FORUM_ID, TOPIC_ID, MESSAGE_ID, NEW_TOPIC, APPROVED, PARAM1, PARAM2, AUTHOR_ID)
93SELECT FORUM_ID, TOPIC_ID, ID, NEW_TOPIC, APPROVED, PARAM1, PARAM2, AUTHOR_ID
94FROM b_forum_message
95WHERE TOPIC_ID = {$topicId}
96ON CONFLICT (MESSAGE_ID) DO NOTHING
97SQL
98 );
99 }
100 else
101 {
102 Main\Application::getConnection()->queryExecute(<<<SQL
103INSERT IGNORE INTO b_forum_service_deleted_message
104 (FORUM_ID, TOPIC_ID, MESSAGE_ID, NEW_TOPIC, APPROVED, PARAM1, PARAM2, AUTHOR_ID)
105SELECT FORUM_ID, TOPIC_ID, ID, NEW_TOPIC, APPROVED, PARAM1, PARAM2, AUTHOR_ID
106FROM b_forum_message
107WHERE TOPIC_ID = {$topicId}
108SQL
109 );
110 }
111
112 self::bind(0);
113 }
114}
static runForTopic(int $topicId)
Определения messagecleaner.php:86
execute(array &$option)
Определения messagecleaner.php:18
static getConnection($name="")
Определения application.php:638
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $USER_FIELD_MANAGER
Определения attempt.php:6
IsModuleInstalled($module_id)
Определения tools.php:5301
$message
Определения payment.php:8
$option
Определения options.php:1711
$dbRes
Определения yandex_detail.php:168