Created
September 28, 2017 14:12
-
-
Save Feiron/05158efe79dbe7d0bb2d4684b6c56f0a to your computer and use it in GitHub Desktop.
Работа по удалению файлов папки
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
<? | |
define('STOP_STATISTICS', true); | |
define('BX_SECURITY_SHOW_MESSAGE', true); | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); | |
use Bitrix\Disk\Configuration; | |
use Bitrix\Disk\Driver; | |
use Bitrix\Disk\ExternalLink; | |
use Bitrix\Disk\File; | |
use Bitrix\Disk\Folder; | |
use Bitrix\Disk\Internals\Error\Error; | |
use Bitrix\Disk\Internals\ExternalLinkTable; | |
use Bitrix\Disk\Internals\ObjectTable; | |
use Bitrix\Disk\Version; | |
use Bitrix\Main\EventResult; | |
use Bitrix\Main\Localization\Loc; | |
use Bitrix\Main\Loader; | |
CModule::IncludeModule('crm'); | |
CModule::IncludeModule('gpw.1cdb'); | |
CModule::IncludeModule('gpw.payments'); | |
CModule::IncludeModule('disk'); | |
set_time_limit(0); | |
function calcCnt($iFolderID) | |
{ | |
$folder = Folder::loadById((int)$iFolderID, array('STORAGE')); | |
$securityContext = $folder->getStorage()->getCurrentUserSecurityContext(); | |
$parameters = array( | |
'filter' => array( | |
'PARENT_ID' => $folder->getRealObjectId(), | |
'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, | |
), | |
); | |
$parameters = Bitrix\Disk\Driver::getInstance()->getRightsManager()->addRightsCheck( | |
$securityContext, | |
$parameters, | |
array('ID', 'CREATED_BY') | |
); | |
$countQuery = new \Bitrix\Main\Entity\Query(ObjectTable::getEntity()); | |
$countQuery | |
->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')) | |
->addSelect(new \Bitrix\Main\Entity\ExpressionField('FILE_SIZE', 'SUM(%s)', 'SIZE')) | |
->setFilter($parameters['filter']); | |
foreach ($parameters['runtime'] as $field) { | |
$countQuery->registerRuntimeField('', $field); | |
} | |
unset($field); | |
$totalData = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); | |
return $totalData['CNT']; | |
} | |
$iFolderID = 1719; | |
$obFolder = \Bitrix\Disk\Folder::loadById($iFolderID); | |
$rights = \Bitrix\Disk\Driver::getInstance()->getFakeSecurityContext(); | |
$arFiles = $obFolder->getChildren($rights, array('limit' => 500, 'order' => array('ID' => 'asc'))); | |
$iCnt = calcCnt($iFolderID); | |
?> | |
<head><title><?= $iCnt ?> / 500</title></head> | |
<h1><?= $iCnt ?></h1> | |
<? | |
foreach ($arFiles as $key => $obFile) { | |
$obRealFile = \Bitrix\Disk\File::loadById($obFile->getId()); | |
echo ($key + 1) . ' ' . $obRealFile->getOriginalName() . ' ' . $obRealFile->getParentId() . ' <br>'; | |
$obRealFile->delete(\Bitrix\Disk\SystemUser::SYSTEM_USER_ID); | |
} | |
sleep(2); | |
if ($iCnt > 0) { | |
?> | |
<script>location.reload()</script> | |
<? | |
} | |
//$APPLICATION->IncludeComponent('gpw:crm.report.voices','', array()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment