Merge pull request #16967 from wmortada/wp#46-2
[civicrm-core.git] / CRM / Admin / Form / Setting / UF.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for Site Url.
20 */
21 class CRM_Admin_Form_Setting_UF extends CRM_Admin_Form_Setting {
22
23 protected $_settings = [];
24
25 protected $_uf = NULL;
26
27 /**
28 * Build the form object.
29 */
30 public function buildQuickForm() {
31 $config = CRM_Core_Config::singleton();
32 $this->_uf = $config->userFramework;
33 $this->_settings['syncCMSEmail'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
34
35 if ($this->_uf == 'WordPress') {
36 $this->_settings['wpBasePage'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
37 }
38
39 CRM_Utils_System::setTitle(
40 ts('Settings - %1 Integration', [1 => $this->_uf])
41 );
42
43 if ($config->userSystem->is_drupal) {
44 $this->_settings['userFrameworkUsersTableName'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
45 }
46
47 // find out if drupal has its database prefixed
48 global $databases;
49 $drupal_prefix = '';
50 if (isset($databases['default']['default']['prefix'])) {
51 if (is_array($databases['default']['default']['prefix'])) {
52 $drupal_prefix = $databases['default']['default']['prefix']['default'];
53 }
54 else {
55 $drupal_prefix = $databases['default']['default']['prefix'];
56 }
57 }
58
59 if ($config->userSystem->viewsExists() &&
60 (
61 $config->dsn != $config->userFrameworkDSN || !empty($drupal_prefix)
62 )
63 ) {
64 $dsnArray = DB::parseDSN($config->dsn);
65 $tableNames = CRM_Core_DAO::getTableNames();
66 asort($tableNames);
67 $tablePrefixes = '$databases[\'default\'][\'default\'][\'prefix\']= array(';
68 if ($config->userFramework === 'Backdrop') {
69 $tablePrefixes = '$database_prefix = array(';
70 }
71 // add default prefix: the drupal database prefix
72 $tablePrefixes .= "\n 'default' => '$drupal_prefix',";
73 $prefix = "";
74 if ($config->dsn != $config->userFrameworkDSN) {
75 $prefix = "`{$dsnArray['database']}`.";
76 }
77 foreach ($tableNames as $tableName) {
78 $tablePrefixes .= "\n '" . str_pad($tableName . "'", 41) . " => '{$prefix}',";
79 }
80 $tablePrefixes .= "\n);";
81 $this->assign('tablePrefixes', $tablePrefixes);
82 }
83
84 parent::buildQuickForm();
85 }
86
87 }