GenCode - Allow execution when civicrm-packages is loaded higher up via composer
[civicrm-core.git] / xml / GenCode.php
1 <?php
2
3 if (PHP_SAPI !== 'cli') {
4 die("GenCode can only be run from command line.");
5 }
6
7 $includes = ['.', '../packages', '../../civicrm-packages', '..'];
8 ini_set('include_path', implode(PATH_SEPARATOR, $includes));
9 // make sure the memory_limit is at least 512 MB
10 $memLimitString = trim(ini_get('memory_limit'));
11 $memLimitUnit = strtolower(substr($memLimitString, -1));
12 $memLimit = (int) $memLimitString;
13 switch ($memLimitUnit) {
14 case 'g':
15 $memLimit *= 1024;
16 case 'm':
17 $memLimit *= 1024;
18 case 'k':
19 $memLimit *= 1024;
20 }
21
22 if ($memLimit >= 0 and $memLimit < 536870912) {
23 // Note: When processing all locales, CRM_Core_I18n::singleton() eats a lot of RAM.
24 ini_set('memory_limit', -1);
25 }
26 // avoid php warnings if timezone is not set - CRM-10844
27 date_default_timezone_set('UTC');
28
29 define('CIVICRM_UF', 'Drupal');
30 define('CIVICRM_UF_BASEURL', '/');
31 define('CIVICRM_L10N_BASEDIR', getenv('CIVICRM_L10N_BASEDIR') ? getenv('CIVICRM_L10N_BASEDIR') : __DIR__ . '/../l10n');
32
33 require_once 'CRM/Core/ClassLoader.php';
34 CRM_Core_ClassLoader::singleton()->register();
35
36 # TODO: pull these settings from configuration
37 $genCode = new CRM_Core_CodeGen_Main(
38 // $CoreDAOCodePath
39 '../CRM/Core/DAO/',
40 // $sqlCodePath
41 '../sql/',
42 // $phpCodePath
43 '../',
44 // $tplCodePath
45 '../templates/',
46 // IGNORE
47 NULL,
48 // cms
49 @$argv[3],
50 // db version
51 empty($argv[2]) ? NULL : $argv[2],
52 // schema file
53 empty($argv[1]) ? 'schema/Schema.xml' : $argv[1],
54 // path to digest file
55 getenv('CIVICRM_GENCODE_DIGEST') ? getenv('CIVICRM_GENCODE_DIGEST') : NULL
56 );
57 $genCode->main();