-
-
Notifications
You must be signed in to change notification settings - Fork 825
/
Copy pathindex.php
1981 lines (1748 loc) · 68.4 KB
/
index.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Note that this installer has been based of the SilverStripe installer.
* You can get more information from the SilverStripe Website at
* http://www.silverstripe.com/.
*
* Copyright (c) 2006-7, SilverStripe Limited - www.silverstripe.com
* All rights reserved.
*
* License: BSD-3-clause
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of SilverStripe nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes and modifications (c) 2007-2017 by CiviCRM LLC
*
*/
/**
* CiviCRM Installer
*/
ini_set('max_execution_time', 3000);
if (stristr(PHP_OS, 'WIN')) {
define('CIVICRM_DIRECTORY_SEPARATOR', '/');
define('CIVICRM_WINDOWS', 1);
}
else {
define('CIVICRM_DIRECTORY_SEPARATOR', DIRECTORY_SEPARATOR);
define('CIVICRM_WINDOWS', 0);
}
global $installType;
global $crmPath;
global $pkgPath;
global $installDirPath;
global $installURLPath;
// Set the install type
// this is sent as a query string when the page is first loaded
// and subsequently posted to the page as a hidden field
// only permit acceptable installation types to prevent issues;
$acceptableInstallTypes = ['drupal', 'wordpress', 'backdrop'];
if (isset($_POST['civicrm_install_type']) && in_array($_POST['civicrm_install_type'], $acceptableInstallTypes)) {
$installType = $_POST['civicrm_install_type'];
}
elseif (isset($_GET['civicrm_install_type']) && in_array(strtolower($_GET['civicrm_install_type']), $acceptableInstallTypes)) {
$installType = strtolower($_GET['civicrm_install_type']);
}
else {
// default value if not set and not an acceptable install type.
$installType = "drupal";
}
if ($installType == 'drupal' || $installType == 'backdrop') {
$crmPath = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
$installDirPath = $installURLPath = '';
}
elseif ($installType == 'wordpress') {
$crmPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
$installDirPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
$installURLPath = WP_PLUGIN_URL . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
}
else {
$errorTitle = "Oops! Unsupported installation mode";
$errorMsg = sprintf('%s: unknown installation mode. Please refer to the online documentation for more information.', $installType);
errorDisplayPage($errorTitle, $errorMsg, FALSE);
}
$composerJsonPath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'composer.json';
if (file_exists($composerJsonPath)) {
$composerJson = json_decode(file_get_contents($composerJsonPath), 1);
$minPhpVer = preg_replace(';[~^];', '', $composerJson['require']['php']);
if (!version_compare(phpversion(), $minPhpVer, '>=')) {
errorDisplayPage('PHP Version Requirement', sprintf("CiviCRM requires PHP %s+. The web server is running PHP %s.", $minPhpVer, phpversion()), FALSE);
}
}
$pkgPath = $crmPath . DIRECTORY_SEPARATOR . 'packages';
require_once $crmPath . '/CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();
$loadGenerated = 0;
if (isset($_POST['loadGenerated'])) {
$loadGenerated = 1;
}
require_once dirname(__FILE__) . CIVICRM_DIRECTORY_SEPARATOR . 'langs.php';
foreach ($langs as $locale => $_) {
if ($locale == 'en_US') {
continue;
}
if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, [$crmPath, 'sql', "civicrm_data.$locale.mysql"]))) {
unset($langs[$locale]);
}
}
// Set the CMS
// This is mostly sympbolic, since nothing we do during the install
// really requires CIVICRM_UF to be defined.
$installTypeToUF = [
'wordpress' => 'WordPress',
'drupal' => 'Drupal',
'backdrop' => 'Backdrop',
];
$uf = ($installTypeToUF[$installType] ?? 'Drupal');
define('CIVICRM_UF', $uf);
// Set the Locale (required by CRM_Core_Config)
global $tsLocale;
$tsLocale = 'en_US';
$seedLanguage = 'en_US';
// Backwards compatibility with default location of l10n files
if (!defined('CIVICRM_L10N_BASEDIR') && file_exists($crmPath . DIRECTORY_SEPARATOR . 'l10n')) {
define('CIVICRM_L10N_BASEDIR', $crmPath . DIRECTORY_SEPARATOR . 'l10n');
}
// CRM-16801 This validates that seedLanguage is valid by looking in $langs.
// NB: the variable is initial a $_REQUEST for the initial page reload,
// then becomes a $_POST when the installation form is submitted.
if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) {
$seedLanguage = $_REQUEST['seedLanguage'];
$tsLocale = $_REQUEST['seedLanguage'];
}
CRM_Core_Config::singleton(FALSE);
$GLOBALS['civicrm_default_error_scope'] = NULL;
// The translation files are in the parent directory (l10n)
$i18n = CRM_Core_I18n::singleton();
// Support for Arabic, Hebrew, Farsi, etc.
// Used in the template.html
$short_lang_code = CRM_Core_I18n_PseudoConstant::shortForLong($tsLocale);
$text_direction = (CRM_Core_I18n::isLanguageRTL($tsLocale) ? 'rtl' : 'ltr');
global $cmsPath;
if ($installType == 'drupal') {
//CRM-6840 -don't force to install in sites/all/modules/
$object = new CRM_Utils_System_Drupal();
$cmsPath = $object->cmsRootPath();
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'civicrm.settings.php'
);
}
elseif ($installType == 'backdrop') {
$object = new CRM_Utils_System_Backdrop();
$cmsPath = $object->cmsRootPath();
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm.settings.php');
}
elseif ($installType == 'wordpress') {
$cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm';
$upload_dir = wp_upload_dir();
$files_dirname = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm';
$wp_civi_settings = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php';
$wp_civi_settings_deprectated = CIVICRM_PLUGIN_DIR . 'civicrm.settings.php';
if (file_exists($wp_civi_settings_deprectated)) {
$alreadyInstalled = $wp_civi_settings_deprectated;
}
elseif (file_exists($wp_civi_settings)) {
$alreadyInstalled = $wp_civi_settings;
}
}
if ($installType == 'drupal') {
// Lets check only /modules/.
$pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/';
if (!preg_match($pattern, str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME']))) {
$directory = implode(CIVICRM_DIRECTORY_SEPARATOR, ['sites', 'all', 'modules']);
$errorTitle = ts("Oops! Please correct your install location");
$errorMsg = ts("Please untar (uncompress) your downloaded copy of CiviCRM in the <strong>%1</strong> directory below your Drupal root directory.", [1 => $directory]);
errorDisplayPage($errorTitle, $errorMsg);
}
}
if ($installType == 'backdrop') {
// Lets check only /modules/.
$pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/';
if (!preg_match($pattern, str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME']))) {
$directory = 'modules';
$errorTitle = ts("Oops! Please correct your install location");
$errorMsg = ts("Please untar (uncompress) your downloaded copy of CiviCRM in the <strong>%1</strong> directory below your Drupal root directory.", [1 => $directory]);
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Exit with error if CiviCRM has already been installed.
if ($alreadyInstalled) {
$errorTitle = ts("Oops! CiviCRM is already installed");
$settings_directory = $cmsPath;
if ($installType == 'drupal') {
$settings_directory = implode(CIVICRM_DIRECTORY_SEPARATOR, [
ts('[your Drupal root directory]'),
'sites',
$siteDir,
]);
}
if ($installType == 'backdrop') {
$settings_directory = implode(CIVICRM_DIRECTORY_SEPARATOR, [
ts('[your Backdrop root directory]'),
$siteDir,
]);
}
$docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, ts('Installation Guide'), NULL, NULL, "wiki");
$errorMsg = ts("CiviCRM has already been installed. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>%1</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online documentation: %2.</li></ul>", [1 => $settings_directory, 2 => $docLink]);
errorDisplayPage($errorTitle, $errorMsg, FALSE);
}
$versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm-version.php';
if (file_exists($versionFile)) {
require_once $versionFile;
$civicrm_version = civicrmVersion();
}
else {
$civicrm_version = 'unknown';
}
if ($installType == 'drupal') {
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'Drupal') {
$errorTitle = ts("Oops! Incorrect CiviCRM version");
$errorMsg = ts("This installer can only be used for the Drupal version of CiviCRM.");
errorDisplayPage($errorTitle, $errorMsg);
}
define('DRUPAL_ROOT', $cmsPath);
$drupalVersionFiles = [
// D6
implode(CIVICRM_DIRECTORY_SEPARATOR, [$cmsPath, 'modules', 'system', 'system.module']),
// D7
implode(CIVICRM_DIRECTORY_SEPARATOR, [$cmsPath, 'includes', 'bootstrap.inc']),
];
foreach ($drupalVersionFiles as $drupalVersionFile) {
if (file_exists($drupalVersionFile)) {
require_once $drupalVersionFile;
}
}
// Bootstrap Drupal to get settings and user
$base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$base_root .= '://' . $_SERVER['HTTP_HOST'];
$base_url = $base_root;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Check that user is logged in and has administrative permissions
// This is necessary because the script exposes the database settings in the form and these could be viewed by unauthorised users
if ((!function_exists('user_access')) || (!user_access('administer site configuration'))) {
$errorTitle = ts("You don't have permission to access this page");
$errorMsg = ts("The installer can only be run by a user with the permission to administer site configuration.");
errorDisplayPage($errorTitle, $errorMsg);
exit();
}
if (!defined('VERSION') or version_compare(VERSION, '6.0') < 0) {
$errorTitle = ts("Oops! Incorrect Drupal version");
$errorMsg = ts("This version of CiviCRM can only be used with Drupal 6.x or 7.x. Please ensure that '%1' exists if you are running Drupal 7.0 and over.", [1 => implode("' or '", $drupalVersionFiles)]);
errorDisplayPage($errorTitle, $errorMsg);
}
}
elseif ($installType == 'backdrop') {
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'Backdrop') {
$errorTitle = ts("Oops! Incorrect CiviCRM version");
$errorMsg = ts("This installer can only be used for the Backdrop version of CiviCRM.");
errorDisplayPage($errorTitle, $errorMsg);
}
define('BACKDROP_ROOT', $cmsPath);
$backdropVersionFiles = [
// Backdrop
implode(CIVICRM_DIRECTORY_SEPARATOR, [$cmsPath, 'core', 'includes', 'bootstrap.inc']),
];
foreach ($backdropVersionFiles as $backdropVersionFile) {
if (file_exists($backdropVersionFile)) {
require_once $backdropVersionFile;
}
}
if (!defined('BACKDROP_VERSION') or version_compare(BACKDROP_VERSION, '1.0') < 0) {
$errorTitle = ts("Oops! Incorrect Backdrop version");
$errorMsg = ts("This version of CiviCRM can only be used with Backdrop 1.x. Please ensure that '%1' exists if you are running Backdrop 1.0 and over.", [1 => implode("' or '", $backdropVersionFiles)]);
errorDisplayPage($errorTitle, $errorMsg);
}
}
elseif ($installType == 'wordpress') {
//HACK for now
$civicrm_version['cms'] = 'WordPress';
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'WordPress') {
$errorTitle = ts("Oops! Incorrect CiviCRM version");
$errorMsg = ts("This installer can only be used for the WordPress version of CiviCRM.");
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Load CiviCRM database config
if (isset($_POST['mysql'])) {
$databaseConfig = $_POST['mysql'];
}
if ($installType == 'wordpress') {
// Load WP database config
if (isset($_POST['mysql'])) {
$databaseConfig = $_POST['mysql'];
}
else {
$databaseConfig = [
"server" => DB_HOST,
"username" => DB_USER,
"password" => DB_PASSWORD,
"database" => DB_NAME,
];
}
}
if ($installType == 'drupal') {
// Load drupal database config
if (isset($_POST['drupal'])) {
$drupalConfig = $_POST['drupal'];
}
else {
$dbServer = $databases['default']['default']['host'];
if (!empty($databases['default']['default']['port'])) {
$dbServer .= ':' . $databases['default']['default']['port'];
}
$drupalConfig = [
"server" => $dbServer,
"username" => $databases['default']['default']['username'],
"password" => $databases['default']['default']['password'],
"database" => $databases['default']['default']['database'],
];
}
}
if ($installType == 'backdrop') {
// Load backdrop database config
if (isset($_POST['backdrop'])) {
$backdropConfig = $_POST['backdrop'];
}
else {
$backdropConfig = [
"server" => "localhost",
"username" => "backdrop",
"password" => "",
"database" => "backdrop",
];
}
}
// By default set CiviCRM database to be same as CMS database
if (!isset($databaseConfig)) {
if (($installType == 'drupal') && (isset($drupalConfig))) {
$databaseConfig = $drupalConfig;
}
if (($installType == 'backdrop') && (isset($backdropConfig))) {
$databaseConfig = $backdropConfig;
}
}
// Check requirements
$req = new InstallRequirements();
$req->check();
if ($req->hasErrors()) {
$hasErrorOtherThanDatabase = TRUE;
}
if ($databaseConfig) {
$dbReq = new InstallRequirements();
$dbReq->checkdatabase($databaseConfig, 'CiviCRM');
if ($installType == 'drupal') {
$dbReq->checkdatabase($drupalConfig, 'Drupal');
}
if ($installType == 'backdrop') {
$dbReq->checkdatabase($backdropConfig, 'Backdrop');
}
}
// Actual processor
if (isset($_POST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling
if (!isset($_POST['force_reinstall']) && $alreadyInstalled) {
include $installDirPath . 'template.html';
}
else {
$inst = new Installer();
$inst->install($_POST);
}
// Show the config form
}
else {
include $installDirPath . 'template.html';
}
/**
* This class checks requirements
* Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
* of 3 parts:
* $description[0] - The test category
* $description[1] - The test title
* $description[2] - The test error to show, if it goes wrong
*/
class InstallRequirements {
public $errors;
public $warnings;
public $tests;
public $conn;
// @see CRM_Upgrade_Form::MINIMUM_THREAD_STACK
const MINIMUM_THREAD_STACK = 192;
/**
* Just check that the database configuration is okay.
* @param $databaseConfig
* @param $dbName
*/
public function checkdatabase($databaseConfig, $dbName) {
if ($this->requireFunction('mysqli_connect',
[
ts("PHP Configuration"),
ts("MySQL support"),
ts("MySQL support not included in PHP."),
]
)
) {
$this->requireMySQLServer($databaseConfig['server'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Does the server exist?"),
ts("Can't find the a MySQL server on '%1'.", [1 => $databaseConfig['server']]),
$databaseConfig['server'],
]
);
if ($this->requireMysqlConnection($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Are the access credentials correct?"),
ts("That username/password doesn't work"),
]
)
) {
@$this->requireMySQLVersion(CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER,
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("MySQL version at least %1", [1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER]),
ts("MySQL version %1 or higher is required, you are running MySQL %2.", [1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER, 2 => mysqli_get_server_info($this->conn)]),
ts("MySQL %1", [1 => mysqli_get_server_info($this->conn)]),
]
);
$this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Is auto_increment_increment set to 1"),
ts("An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround."),
]
);
$testDetails = [
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Is the provided database name valid?"),
ts("The database name provided is not valid. Please use only 0-9, a-z, A-Z, _ and - as characters in the name."),
];
if (!CRM_Core_DAO::requireSafeDBName($databaseConfig['database'])) {
$this->error($testDetails);
return FALSE;
}
else {
$this->testing($testDetails);
}
$this->requireMySQLThreadStack($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
self::MINIMUM_THREAD_STACK,
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Does MySQL thread_stack meet minimum (%1k)", [1 => self::MINIMUM_THREAD_STACK]),
"",
// "The MySQL thread_stack does not meet minimum " . CRM_Upgrade_Form::MINIMUM_THREAD_STACK . "k. Please update thread_stack in my.cnf.",
]
);
}
$onlyRequire = $dbName == 'Drupal' || $dbName == 'Backdrop';
$this->requireDatabaseOrCreatePermissions(
$databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Can I access/create the database?"),
ts("I can't create new databases and the database '%1' doesn't exist.", [1 => $databaseConfig['database']]),
],
$onlyRequire
);
if ($dbName != 'Drupal' && $dbName != 'Backdrop') {
$this->requireNoExistingData(
$databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Does the database have data from a previous installation?"),
ts("CiviCRM data from previous installation exists in '%1'.", [1 => $databaseConfig['database']]),
]
);
$this->requireMySQLInnoDB($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts("Can I access/create InnoDB tables in the database?"),
ts("Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server."),
]
);
$this->requireMySQLTempTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts('Can I create temporary tables in the database?'),
ts('Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.'),
]
);
$this->requireMySQLLockTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts('Can I create lock tables in the database?'),
ts('Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.'),
]
);
$this->requireMySQLTrigger($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts('Can I create triggers in the database?'),
ts('Unable to create triggers. This MySQL user is missing the CREATE TRIGGERS privilege.'),
]
);
$this->requireMySQLUtf8mb4($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
[
ts("MySQL %1 Configuration", [1 => $dbName]),
ts('Is the <code>utf8mb4</code> character set supported?'),
ts('This MySQL server does not support the <code>utf8mb4</code> character set.'),
]
);
}
}
}
/**
* Connect via mysqli.
*
* This is exactly the same as mysqli_connect(), except that it accepts
* the port as part of the `$host`.
*
* @param string $host
* Ex: 'localhost', 'localhost:3307', '127.0.0.1:3307', '[::1]', '[::1]:3307'.
* @param string $username
* @param string $password
* @param string $database
* @return \mysqli
*/
protected function connect($host, $username, $password, $database = '') {
$hostParts = explode(':', $host);
if (count($hostParts) > 1 && strrpos($host, ']') !== strlen($host) - 1) {
$port = array_pop($hostParts);
$host = implode(':', $hostParts);
}
else {
$port = NULL;
}
$conn = @mysqli_connect($host, $username, $password, $database, $port);
return $conn;
}
/**
* Check everything except the database.
*/
public function check() {
global $crmPath, $installType;
$this->errors = NULL;
$this->requirePHPVersion([
ts("PHP Configuration"),
ts("PHP7 installed"),
]);
// Check that we can identify the root folder successfully
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'README.md',
[
ts("File permissions"),
ts("Does the webserver know where files are stored?"),
ts("The webserver isn't letting me identify where files are stored."),
$this->getBaseDir(),
],
TRUE
);
// CRM-6485: make sure the path does not contain PATH_SEPARATOR, as we don’t know how to escape it
$this->requireNoPathSeparator(
[
ts("File permissions"),
ts('Does the CiviCRM path contain PATH_SEPARATOR?'),
ts('The path %1 contains PATH_SEPARATOR (the %2 character).', [1 => $this->getBaseDir(), 2 => PATH_SEPARATOR]),
$this->getBaseDir(),
]
);
$requiredDirectories = ['CRM', 'packages', 'templates', 'js', 'api', 'i', 'sql'];
foreach ($requiredDirectories as $dir) {
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . $dir,
[
ts("File permissions"),
ts("Folder '%1' exists?", [1 => $dir]),
ts("There is no '%1' folder.", [1 => $dir]),
], TRUE
);
}
$configIDSiniDir = NULL;
global $cmsPath;
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
if ($installType == 'drupal') {
// make sure that we can write to sites/default and files/
$writableDirectories = [
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'files',
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir,
];
}
elseif ($installType == 'backdrop') {
// make sure that we can write to sites/default and files/
$writableDirectories = [
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'files',
$cmsPath,
];
}
elseif ($installType == 'wordpress') {
// make sure that we can write to uploads/civicrm/
$upload_dir = wp_upload_dir();
$files_dirname = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm';
if (!file_exists($files_dirname)) {
wp_mkdir_p($files_dirname);
}
$writableDirectories = [$files_dirname];
}
foreach ($writableDirectories as $dir) {
$dirName = CIVICRM_WINDOWS ? $dir : CIVICRM_DIRECTORY_SEPARATOR . $dir;
$testDetails = [
ts("File permissions"),
ts("Is the %1 folder writeable?", [1 => $dir]),
NULL,
];
$this->requireWriteable($dirName, $testDetails, TRUE);
}
// Check for rewriting
if (isset($_SERVER['SERVER_SOFTWARE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SOFTWARE']));
}
elseif (isset($_SERVER['SERVER_SIGNATURE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
}
if ($webserver == '') {
$webserver = ts("I can't tell what webserver you are running");
}
// Check for $_SERVER configuration
$this->requireServerVariables(['SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME'], [
ts("Webserver config"),
ts("Recognised webserver"),
ts("You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."),
]);
// Check for MySQL support
$this->requireFunction('mysqli_connect', [
ts("PHP Configuration"),
ts("MySQL support"),
ts("MySQL support not included in PHP."),
]);
// Check for XML support
$this->requireFunction('simplexml_load_file', [
ts("PHP Configuration"),
ts("SimpleXML support"),
ts("SimpleXML support not included in PHP."),
]);
// Check for JSON support
$this->requireFunction('json_encode', [
ts("PHP Configuration"),
ts("JSON support"),
ts("JSON support not included in PHP."),
]);
// check for Multibyte support such as mb_substr. Required for proper handling of Multilingual setups.
$this->requireFunction('mb_substr', [
ts("PHP Configuration"),
ts("Multibyte support"),
ts("Multibyte support not enabled in PHP."),
]);
// Check for xcache_isset and emit warning if exists
$this->checkXCache([
ts("PHP Configuration"),
ts("XCache compatibility"),
ts("XCache is installed and there are known compatibility issues between XCache and CiviCRM. Consider using an alternative PHP caching mechanism or disable PHP caching altogether."),
]);
// Check memory allocation
$this->requireMemory(32 * 1024 * 1024,
64 * 1024 * 1024,
[
ts("PHP Configuration"),
ts("Memory allocated (PHP config option 'memory_limit')"),
ts("CiviCRM needs a minimum of %1 MB allocated to PHP, but recommends %2 MB.", [1 => 32, 2 => 64]),
ini_get("memory_limit"),
]
);
return $this->errors;
}
/**
* @param $min
* @param $recommended
* @param $testDetails
*/
public function requireMemory($min, $recommended, $testDetails) {
$this->testing($testDetails);
$mem = $this->getPHPMemory();
if ($mem < $min && $mem > 0) {
$testDetails[2] .= " " . ts("You only have %1 allocated", [1 => ini_get("memory_limit")]);
$this->error($testDetails);
}
elseif ($mem < $recommended && $mem > 0) {
$testDetails[2] .= " " . ts("You only have %1 allocated", [1 => ini_get("memory_limit")]);
$this->warning($testDetails);
}
elseif ($mem == 0) {
$testDetails[2] .= " " . ts("We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least %1 MB.", [1 => 32]);
$this->warning($testDetails);
}
}
/**
* @return float
*/
public function getPHPMemory() {
$memString = ini_get("memory_limit");
switch (strtolower(substr($memString, -1))) {
case "k":
return round(substr($memString, 0, -1) * 1024);
case "m":
return round(substr($memString, 0, -1) * 1024 * 1024);
case "g":
return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
default:
return round($memString);
}
}
public function listErrors() {
if ($this->errors) {
echo "<p>" . ts("The following problems are preventing me from installing CiviCRM:") . "</p>";
foreach ($this->errors as $error) {
echo "<li>" . htmlentities($error) . "</li>";
}
}
}
/**
* @param string|null $section
*/
public function showTable($section = NULL) {
if ($section) {
$tests = $this->tests[$section];
echo "<table class=\"testResults\" width=\"100%\">";
foreach ($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
}
echo "</table>";
}
else {
foreach ($this->tests as $section => $tests) {
echo "<h3>$section</h3>";
echo "<table class=\"testResults\" width=\"100%\">";
foreach ($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
}
echo "</table>";
}
}
}
/**
* @param string $funcName
* @param $testDetails
*
* @return bool
*/
public function requireFunction($funcName, $testDetails) {
$this->testing($testDetails);
if (!function_exists($funcName)) {
$this->error($testDetails);
return FALSE;
}
else {
return TRUE;
}
}
/**
* @param $testDetails
*/
public function checkXCache($testDetails) {
if (function_exists('xcache_isset') &&
ini_get('xcache.size') > 0
) {
$this->testing($testDetails);
$this->warning($testDetails);
}
}
/**
* @param array $testDetails
* @return bool
*/
public function requirePHPVersion($testDetails) {
$this->testing($testDetails);
$phpVersion = phpversion();
$aboveMinVersion = version_compare($phpVersion, CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER) >= 0;
if ($aboveMinVersion) {
if (version_compare($phpVersion, CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER) < 0) {
$testDetails[2] = ts('This webserver is running an outdated version of PHP (%1). It is strongly recommended to upgrade to PHP %2 or later, as older versions can present a security risk. The preferred version is %3.', [
1 => $phpVersion,
2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER),
]);
$this->warning($testDetails);
}
return TRUE;
}
if (empty($testDetails[2])) {
$testDetails[2] = ts("You need PHP version %1 or later, only %2 is installed. Please upgrade your server, or ask your web-host to do so.", [1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER, 2 => $phpVersion]);
}
$this->error($testDetails);
}
/**
* @param string $filename
* @param $testDetails
* @param bool $absolute
*/
public function requireFile($filename, $testDetails, $absolute = FALSE) {
$this->testing($testDetails);
if (!$absolute) {
$filename = $this->getBaseDir() . $filename;
}
if (!file_exists($filename)) {
$testDetails[2] .= " (" . ts("file '%1' not found", [1 => $filename]) . ')';
$this->error($testDetails);
}
}
/**
* @param $testDetails
*/
public function requireNoPathSeparator($testDetails) {
$this->testing($testDetails);
if (substr_count($this->getBaseDir(), PATH_SEPARATOR)) {
$this->error($testDetails);
}
}
/**
* @param string $filename
* @param $testDetails
*/
public function requireNoFile($filename, $testDetails) {
$this->testing($testDetails);
$filename = $this->getBaseDir() . $filename;
if (file_exists($filename)) {
$testDetails[2] .= " (" . ts("file '%1' found", [1 => $filename]) . ")";
$this->error($testDetails);
}
}
/**
* @param string $filename
* @param $testDetails
*/
public function moveFileOutOfTheWay($filename, $testDetails) {
$this->testing($testDetails);
$filename = $this->getBaseDir() . $filename;
if (file_exists($filename)) {
if (file_exists("$filename.bak")) {
rm("$filename.bak");
}
rename($filename, "$filename.bak");
}
}
/**
* @param string $filename
* @param $testDetails
* @param bool $absolute
*/
public function requireWriteable($filename, $testDetails, $absolute = FALSE) {
$this->testing($testDetails);
if (!$absolute) {
$filename = $this->getBaseDir() . $filename;
}
if (!is_writable($filename)) {
$name = NULL;
if (function_exists('posix_getpwuid')) {
$user = posix_getpwuid(posix_geteuid());
$name = '- ' . $user['name'] . ' -';
}
if (!isset($testDetails[2])) {
$testDetails[2] = NULL;
}