當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ArtefactTypeFileBase::bulk_delete方法代碼示例

本文整理匯總了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();
 }
開發者ID:vohung96,項目名稱:mahara,代碼行數:55,代碼來源:lib.php

示例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();
 }
開發者ID:richardmansfield,項目名稱:richardms-mahara,代碼行數:44,代碼來源:lib.php


注:本文中的ArtefactTypeFileBase::bulk_delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。