Further modules included.
[yaffs-website] / web / modules / contrib / linkchecker / linkchecker.install
1 <?php
2
3 /**
4  * @file
5  * Installation file for Link Checker module.
6  */
7
8 use Drupal\user\Entity\User;
9
10 /**
11  * Implements hook_install().
12  */
13 function linkchecker_install() {
14   $linkchecker_default_impersonate_account = User::load(1);
15   \Drupal::configFactory()->getEditable('linkchecker.settings')->set('error.impersonate_account', $linkchecker_default_impersonate_account->getAccountName())->save();
16 }
17
18 /**
19  * Implements hook_schema().
20  */
21 function linkchecker_schema() {
22
23   $schema['linkchecker_block_custom'] = array(
24     'description' => 'Stores all link references for custom blocks.',
25     'fields' => array(
26       'bid'  => array(
27         'type' => 'int',
28         'not null' => TRUE,
29         'description' => 'Primary Key: Unique {block_custom}.bid.',
30       ),
31       'lid' => array(
32         'type' => 'int',
33         'not null' => TRUE,
34         'description' => 'Primary Key: Unique {linkchecker_link}.lid.',
35       ),
36     ),
37     'primary key' => array('bid', 'lid'),
38     'foreign keys' => array(
39       'bid' => array(
40         'table' => 'block_custom',
41         'columns' => array('bid' => 'bid'),
42       ),
43       'lid' => array(
44         'table' => 'linkchecker_link',
45         'columns' => array('lid' => 'lid'),
46       ),
47     ),
48     'indexes' => array('lid' => array('lid')),
49   );
50
51   $schema['linkchecker_comment'] = array(
52     'description' => 'Stores all link references for comments.',
53     'fields' => array(
54       'cid'  => array(
55         'type' => 'int',
56         'not null' => TRUE,
57         'description' => 'Primary Key: Unique {comment}.cid.',
58       ),
59       'lid' => array(
60         'type' => 'int',
61         'not null' => TRUE,
62         'description' => 'Primary Key: Unique {linkchecker_link}.lid.',
63       ),
64     ),
65     'primary key' => array('cid', 'lid'),
66     'foreign keys' => array(
67       'cid' => array(
68         'table' => 'comment',
69         'columns' => array('cid' => 'cid'),
70       ),
71       'lid' => array(
72         'table' => 'linkchecker_link',
73         'columns' => array('lid' => 'lid'),
74       ),
75     ),
76     'indexes' => array('lid' => array('lid')),
77   );
78
79   $schema['linkchecker_node'] = array(
80     'description' => 'Stores all link references for nodes.',
81     'fields' => array(
82       'nid'  => array(
83         'type' => 'int',
84         'not null' => TRUE,
85         'description' => 'Primary Key: Unique {node}.nid.',
86       ),
87       'lid' => array(
88         'type' => 'int',
89         'not null' => TRUE,
90         'description' => 'Primary Key: Unique {linkchecker_link}.lid.',
91       ),
92     ),
93     'primary key' => array('nid', 'lid'),
94     'foreign keys' => array(
95       'nid' => array(
96         'table' => 'node',
97         'columns' => array('nid' => 'nid'),
98       ),
99       'lid' => array(
100         'table' => 'linkchecker_link',
101         'columns' => array('lid' => 'lid'),
102       ),
103     ),
104     'indexes' => array('lid' => array('lid')),
105   );
106
107   $schema['linkchecker_link'] = array(
108     'description' => 'Stores all links.',
109     'fields' => array(
110       'lid'  => array(
111         'type' => 'serial',
112         'not null' => TRUE,
113         'description' => 'Primary Key: Unique link ID.',
114       ),
115       'urlhash' => array(
116         'type' => 'varchar',
117         'length' => 64,
118         'not null' => TRUE,
119         'description' => 'The indexable hash of the {linkchecker_link}.url.',
120       ),
121       'url' => array(
122         'type' => 'text',
123         'not null' => TRUE,
124         'description' => 'The full qualified link.',
125       ),
126       'method' => array(
127         'type' => 'varchar',
128         'length' => 4,
129         'default' => 'HEAD',
130         'not null' => TRUE,
131         'description' => 'The method for checking links (HEAD, GET, POST).',
132       ),
133       'code' => array(
134         'type' => 'int',
135         'not null' => TRUE,
136         'default' => -1,
137         'description' => 'HTTP status code from link checking.',
138       ),
139       'error' => array(
140         'type' => 'text',
141         'not null' => FALSE,
142         'description' => 'The error message received from the remote server while doing link checking.',
143       ),
144       'fail_count' => array(
145         'type' => 'int',
146         'not null' => TRUE,
147         'default' => 0,
148         'description' => 'Fail count of unsuccessful link checks. No flapping detection. (Successful = 0, Unsuccessful = fail_count+1).',
149       ),
150       'last_checked' => array(
151         'type' => 'int',
152         'not null' => TRUE,
153         'default' => 0,
154         'description' => 'Timestamp of the last link check.',
155       ),
156       'status' => array(
157         'type' => 'int',
158         'not null' => TRUE,
159         'default' => 1,
160         'description' => 'Boolean indicating if a link should be checked or not.',
161       ),
162     ),
163     'primary key' => array('lid'),
164     'unique keys' => array('urlhash' => array('urlhash')),
165     'indexes' => array(
166       'method' => array('method'),
167       'code' => array('code'),
168       'fail_count' => array('fail_count'),
169       'last_checked' => array('last_checked'),
170       'status' => array('status'),
171     ),
172   );
173
174   return $schema;
175 }
176
177 /**
178  * Implements hook_modules_uninstalled().
179  *
180  * If the core modules are disabled the integration need to be disabled.
181  */
182 function linkchecker_modules_uninstalled($modules) {
183   // Disable link checks for custom blocks.
184   if (in_array('block', $modules)) {
185     \Drupal::config('linkchecker.settings')->set('scan_blocks', 0);
186     drupal_set_message(t('Link checks for blocks have been disabled.'));
187   }
188
189   // Disable link checks for comments.
190   if (in_array('comment', $modules)) {
191     foreach (node_type_get_names() as $type => $name) {
192       // @fixme: This is incorrect. The variable is inside node.type.*.third_party.linkchecker
193       //\Drupal::config('node.type.' . $type .  '.third_party.linkchecker')->clear('scan_comment');
194       //\Drupal::service('config.manager');
195       //$type->unsetThirdPartySetting('linkchecker', 'scan_comment', $form_state->getValue('scan_comment'));
196     }
197     drupal_set_message(t('Link checks for comments have been disabled.'));
198   }
199 }