Created
September 18, 2017 12:19
-
-
Save Feiron/273a04be14c9b62cd013a5665d72e8e7 to your computer and use it in GitHub Desktop.
Очистка писем из ящика Bitrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"); | |
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/mail/prolog.php"); | |
$APPLICATION->SetTitle("Тестирование"); | |
CModule::IncludeModule("mail"); | |
$mailboxID = 13; | |
$sql = "SELECT COUNT(*) as CNT FROM b_mail_message WHERE MAILBOX_ID = {$mailboxID}"; | |
$res = $DB->Query($sql); | |
$arResult = $res->Fetch(); | |
echo "<h1> Count:" . $arResult['CNT'] . '</h1>'; | |
$sql = "SELECT ID FROM b_mail_message WHERE MAILBOX_ID = {$mailboxID} ORDER BY FIELD_DATE asc LIMIT 2000"; | |
$res = $DB->Query($sql); | |
while ($arRes = $res->GetNext()) { | |
CMailMessage::Delete($arRes['ID']); | |
//echo 'ID=' . $arRes['ID'] . ' <br/>'; | |
} | |
if ($arResult['CNT'] > 0) { | |
echo "<script>setTimeout(function(){location.reload()}, 1000);</script>"; | |
} | |
function delete($id) | |
{ | |
global $DB; | |
$id = intval($id); | |
$res = $DB->Query('SELECT FILE_ID FROM b_mail_msg_attachment WHERE MESSAGE_ID = ' . $id); | |
while ($file = $res->fetch()) { | |
if ($file['FILE_ID']) | |
CFile::Delete($file['FILE_ID']); | |
} | |
$strSql = "DELETE FROM b_mail_msg_attachment WHERE MESSAGE_ID=" . $id; | |
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); | |
$strSql = "DELETE FROM b_mail_message WHERE ID=" . $id; | |
$DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment