Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New file sync filter settings: mimetype, filearea, component #478

Open
wants to merge 1 commit into
base: DEPRECATED_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions classes/local/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static function get_objectfs_config() {
$config->enabletasks = 0;
$config->enablelogging = 0;
$config->sizethreshold = 1024 * 10;
$config->filtercomponent = '';
$config->filterfilearea = '';
$config->filtermimetype = '';
$config->minimumage = 7 * DAYSECS;
$config->deletelocal = 0;
$config->consistencydelay = 10 * MINSECS;
Expand Down
49 changes: 49 additions & 0 deletions classes/local/object_manipulator/candidates/pusher_candidates.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,58 @@ class pusher_candidates extends manipulator_candidates_base {
* @return string
*/
public function get_candidates_sql() {

// Filter file component.
$filtercomponent = [];
if (!empty($this->config->filtercomponent)) {
foreach(explode(',', $this->config->filtercomponent) as $item){
if(!empty(trim($item))){
$filtercomponent[] = trim($item);
}
}

$filtercomponent = array_unique($filtercomponent);
}

$strcomponent = !empty($filtercomponent) ? " AND f.component IN ('".implode("','", $filtercomponent)."') " : '';

// Filter file filearea.
$filterfilearea = [];
if (!empty($this->config->filterfilearea)) {
foreach(explode(',', $this->config->filterfilearea) as $item){
if(!empty(trim($item))){
$filterfilearea[] = trim($item);
}
}

$filterfilearea = array_unique($filterfilearea);
}

$strfilearea = !empty($filterfilearea) ? " AND f.filearea IN ('".implode("','", $filterfilearea)."') " : '';

// Filter file mimetype.
$filtermimetype = [];
if (!empty($this->config->filtermimetype)) {
foreach(explode(',', $this->config->filtermimetype) as $item){
if(!empty(trim($item))){
$filtermimetype[] = trim($item);
}
}

$filtermimetype = array_unique($filtermimetype);
}

$strmimetype = !empty($filtermimetype) ? " AND f.mimetype IN ('".implode("','", $filtermimetype)."') " : '';

return 'SELECT MAX(f.id),
f.contenthash,
MAX(f.filesize) AS filesize
FROM {files} f
JOIN {tool_objectfs_objects} o ON f.contenthash = o.contenthash
WHERE f.filesize > :threshold
'.$strcomponent.'
'.$strfilearea.'
'.$strmimetype.'
AND f.filesize < :maximum_file_size
AND f.timecreated <= :maxcreatedtimestamp
AND o.location = :object_location
Expand All @@ -59,6 +105,9 @@ public function get_candidates_sql_params() {
return [
'maxcreatedtimestamp' => time() - $this->config->minimumage,
'threshold' => $this->config->sizethreshold,
'component' => $this->config->component,
'filearea' => $this->config->filearea,
'mimetype' => $this->config->mimetype,
'maximum_file_size' => $filesystem->get_maximum_upload_filesize(),
'object_location' => OBJECT_LOCATION_LOCAL,
];
Expand Down
6 changes: 6 additions & 0 deletions lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
$string['settings:filetransferheader'] = 'File Transfer Settings';
$string['settings:sizethreshold'] = 'Minimum size threshold (bytes)';
$string['settings:sizethreshold_help'] = 'Minimum size threshold for transfering objects to external object storage. If objects are over this size they will be transfered.';
$string['settings:filtercomponent'] = 'Component';
$string['settings:filtercomponent_help'] = 'A comma separated list of component items.';
$string['settings:filterfilearea'] = 'Filearea';
$string['settings:filterfilearea_help'] = 'A comma separated list of filearea items.';
$string['settings:filtermimetype'] = 'MimeType';
$string['settings:filtermimetype_help'] = 'A comma separated list of mimetype items.';
$string['settings:batchsize'] = 'Number files in one batch';
$string['settings:batchsize_help'] = 'Number of files to be transferred in one cron run';
$string['settings:maxorphanedage'] = 'Max orphaned object age';
Expand Down
12 changes: 12 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@
$settings->add(new admin_setting_configtext('tool_objectfs/sizethreshold',
new lang_string('settings:sizethreshold', 'tool_objectfs'), '', 1024 * 10, PARAM_INT));

$settings->add(new admin_setting_configtext('tool_objectfs/filtercomponent',
new lang_string('settings:filtercomponent', 'tool_objectfs'),
new lang_string('settings:filtercomponent_help', 'tool_objectfs'), '', PARAM_TEXT));

$settings->add(new admin_setting_configtext('tool_objectfs/filterfilearea',
new lang_string('settings:filterfilearea', 'tool_objectfs'),
new lang_string('settings:filterfilearea_help', 'tool_objectfs'), '', PARAM_TEXT));

$settings->add(new admin_setting_configtext('tool_objectfs/filtermimetype',
new lang_string('settings:filtermimetype', 'tool_objectfs'),
new lang_string('settings:filtermimetype_help', 'tool_objectfs'), '', PARAM_TEXT));

$settings->add(new admin_setting_configtext('tool_objectfs/batchsize',
new lang_string('settings:batchsize', 'tool_objectfs'), '', 10000, PARAM_INT));

Expand Down