Merge pull request #19594 from eileenmcnaughton/535m
[civicrm-core.git] / setup / plugins / blocks / opt-in.disabled.php
1 <?php
2 /**
3 * @file
4 *
5 * Display a block with opt-in settings.
6 *
7 * The file `opt-in.disabled.php` is ignored by default. To enable, you should
8 * either rename it to `opt-in.civi-setup.php` or symlink it.
9 */
10
11 if (!defined('CIVI_SETUP')) {
12 exit("Installation plugins must only be loaded by the installer.\n");
13 }
14
15 // First pass: initialize 'settings' block.
16 \Civi\Setup::dispatcher()
17 ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent $e) {
18 \Civi\Setup::log()->info(sprintf('[%s] Register blocks', basename(__FILE__)));
19
20 $e->getCtrl()->blocks['opt-in'] = array(
21 // FIXME
22 'is_active' => TRUE,
23 'file' => __DIR__ . DIRECTORY_SEPARATOR . 'opt-in.tpl.php',
24 'class' => 'if-no-errors',
25 'weight' => 55,
26 );
27 }, \Civi\Setup::PRIORITY_PREPARE);
28
29 // Second pass: Parse any settings that have been approved for use in this form.
30 \Civi\Setup::dispatcher()
31 ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent $e) {
32 if (!$e->getCtrl()->blocks['opt-in']['is_active']) {
33 return;
34 }
35
36 \Civi\Setup::log()->info(sprintf('[%s] Parse inputs', basename(__FILE__)));
37 $values = $e->getField('opt-in', array());
38 $e->getModel()->extras['opt-in']['empoweredBy'] = !empty($values['empoweredBy']);
39 $e->getModel()->extras['opt-in']['versionCheck'] = !empty($values['versionCheck']);
40
41 // echo '<pre>'; print_r(['model'=> $e->getModel()->getValues(), 'v'=>$values]); echo '</pre>';
42
43 }, \Civi\Setup::PRIORITY_LATE);
44
45 \Civi\Setup::dispatcher()
46 ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent $e) {
47 $m = $e->getModel();
48
49 if (isset($m->extras['opt-in']['empoweredBy'])) {
50 \Civi\Setup::log()->info(sprintf('[%s] Set empoweredBy', basename(__FILE__)));
51 \Civi::settings()->set('empoweredBy', (bool) $m->extras['opt-in']['empoweredBy']);
52 }
53
54 if (isset($m->extras['opt-in']['versionCheck'])) {
55 \Civi\Setup::log()->info(sprintf('[%s] Set versionCheck', basename(__FILE__)));
56 \CRM_Core_DAO::executeQuery('UPDATE civicrm_job SET is_active = %1 WHERE api_entity LIKE "job" AND api_action LIKE "version_check"', array(
57 1 => array($m->extras['opt-in']['versionCheck'] ? 1 : 0, 'Int'),
58 ));
59 }
60 }, \Civi\Setup::PRIORITY_LATE + 100);