-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_checker.module
69 lines (61 loc) · 2.04 KB
/
file_checker.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @file
* File Checker hooks and callbacks.
*/
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\file\FileInterface;
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_base_field_info().
*
* Adds a 'missing' basefield to the core file entity.
*/
function file_checker_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'file') {
$fields = array();
$fields['missing'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Missing'))
->setDescription(t('Whether the file can be found at the uri.'));
// ->setRevisionable(TRUE);
return $fields;
}
}
/**
* The callback function for an Ultimate Cron job that starts file checking.
*/
function file_checker_start($job) {
\Drupal::service('file_checker.bulk_file_checking')->start();
}
/**
* The callback for an Ultimate Cron job that checks fies for up to 50 seconds.
*/
function file_checker_execute50($job) {
\Drupal::service('file_checker.bulk_file_checking')->executeInBackground(50);
}
/**
* The callback for the batch API launch from UI.
*/
function file_checker_execute_in_ui(&$context) {
\Drupal::service('file_checker.bulk_file_checking')->executeInUI(10, $context);
}
/**
* Implements hook_ENTITY_TYPE_insert() for file.
*
* Check files when recorded location changes, if configured to do so.
* We use update/insert not presave out of concern that the file might not have
* been moved into its uri location at the time of presave.
*/
function file_checker_file_insert(FileInterface $file) {
\Drupal::service('file_checker.single_file_checking')->checkIfChanged($file);
}
/**
* Implements hook_ENTITY_TYPE_update() for file.
*
* Check files when recorded location changes, if configured to do so.
* We use update/insert not presave out of concern that the file might not
* have been moved into its uri location at the time of presave.
*/
function file_checker_file_update(FileInterface $file) {
\Drupal::service('file_checker.single_file_checking')->checkIfChanged($file);
}