本文整理汇总了PHP中ArtefactTypeFileBase::bulk_delete方法的典型用法代码示例。如果您正苦于以下问题:PHP ArtefactTypeFileBase::bulk_delete方法的具体用法?PHP ArtefactTypeFileBase::bulk_delete怎么用?PHP ArtefactTypeFileBase::bulk_delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArtefactTypeFileBase
的用法示例。
在下文中一共展示了ArtefactTypeFileBase::bulk_delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bulk_delete
public static function bulk_delete($artefactids)
{
global $USER;
require_once 'group.php';
if (empty($artefactids)) {
return;
}
$idstr = join(',', array_map('intval', $artefactids));
db_begin();
// Get the size of all the files we're about to delete that belong to
// the user.
if ($group = group_current_group()) {
$totalsize = get_field_sql('
SELECT SUM(size)
FROM {artefact_file_files} f JOIN {artefact} a ON f.artefact = a.id
WHERE a.group = ? AND f.artefact IN (' . $idstr . ')', array($group->id));
} else {
$totalsize = get_field_sql('
SELECT SUM(size)
FROM {artefact_file_files} f JOIN {artefact} a ON f.artefact = a.id
WHERE a.owner = ? AND f.artefact IN (' . $idstr . ')', array($USER->get('id')));
}
// Get all fileids so that we can delete the files on disk
$filetodeleteids = get_column_sql('
SELECT fileid
FROM {artefact_file_files} aff1
WHERE artefact IN (' . $idstr . ')
GROUP BY fileid
HAVING COUNT(aff1.artefact) IN
(SELECT COUNT(aff2.artefact)
FROM {artefact_file_files} aff2
WHERE aff1.fileid = aff2.fileid)', null);
// The current rule is that file deletion should be logged in the artefact_log table
// only for group-owned files. To save time we will be slightly naughty here and
// log deletion for all these files if at least one is group-owned.
$log = (bool) count_records_select('artefact', 'id IN (' . $idstr . ') AND "group" IS NOT NULL');
delete_records_select('artefact_attachment', 'attachment IN (' . $idstr . ')');
delete_records_select('artefact_file_files', 'artefact IN (' . $idstr . ')');
parent::bulk_delete($artefactids, $log);
foreach ($filetodeleteids as $filetodeleteid) {
$file = get_config('dataroot') . self::get_file_directory($filetodeleteid) . '/' . $filetodeleteid;
if (is_file($file)) {
unlink($file);
}
}
if ($totalsize) {
if ($group) {
group_quota_remove($group->id, $totalsize);
} else {
$USER->quota_remove($totalsize);
$USER->commit();
}
}
db_commit();
}
示例2: bulk_delete
public static function bulk_delete($artefactids)
{
global $USER;
if (empty($artefactids)) {
return;
}
$idstr = join(',', array_map('intval', $artefactids));
db_begin();
// Get the size of all the files we're about to delete that belong to
// the user.
$totalsize = get_field_sql('
SELECT SUM(size)
FROM {artefact_file_files} f JOIN {artefact} a ON f.artefact = a.id
WHERE a.owner = ? AND f.artefact IN (' . $idstr . ')', array($USER->get('id')));
// Get all fileids so that we can delete the files on disk
$fileids = get_records_select_assoc('artefact_file_files', 'artefact IN (' . $idstr . ')', array());
$fileidcounts = get_records_sql_assoc('
SELECT fileid, COUNT(fileid) AS fileidcount
FROM {artefact_file_files}
WHERE artefact IN (' . $idstr . ')
GROUP BY fileid', null);
// The current rule is that file deletion should be logged in the artefact_log table
// only for group-owned files. To save time we will be slightly naughty here and
// log deletion for all these files if at least one is group-owned.
$log = (bool) count_records_select('artefact', 'id IN (' . $idstr . ') AND "group" IS NOT NULL');
delete_records_select('artefact_attachment', 'attachment IN (' . $idstr . ')');
delete_records_select('artefact_file_files', 'artefact IN (' . $idstr . ')');
parent::bulk_delete($artefactids, $log);
foreach ($fileids as $r) {
// Delete the file on disk if there's only one artefact left pointing to it
if ($fileidcounts[$r->fileid]->fileidcount == 1) {
$file = get_config('dataroot') . self::get_file_directory($r->fileid) . '/' . $r->fileid;
if (is_file($file)) {
unlink($file);
}
}
$fileidcounts[$r->fileid]->fileidcount--;
}
if ($totalsize) {
$USER->quota_remove($totalsize);
$USER->commit();
}
db_commit();
}