| 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 | $GLOBALS['civicrm_paths']['cms.root']['url'] = 'http://gencode.example.com/do-not-use'; |
| 33 | |
| 34 | require_once 'CRM/Core/ClassLoader.php'; |
| 35 | CRM_Core_ClassLoader::singleton()->register(); |
| 36 | |
| 37 | # TODO: pull these settings from configuration |
| 38 | $genCode = new CRM_Core_CodeGen_Main( |
| 39 | // $CoreDAOCodePath |
| 40 | '../CRM/Core/DAO/', |
| 41 | // $sqlCodePath |
| 42 | '../sql/', |
| 43 | // $phpCodePath |
| 44 | '../', |
| 45 | // $tplCodePath |
| 46 | '../templates/', |
| 47 | // IGNORE |
| 48 | NULL, |
| 49 | // cms |
| 50 | @$argv[3], |
| 51 | // db version |
| 52 | empty($argv[2]) ? NULL : $argv[2], |
| 53 | // schema file |
| 54 | empty($argv[1]) ? 'schema/Schema.xml' : $argv[1], |
| 55 | // path to digest file |
| 56 | getenv('CIVICRM_GENCODE_DIGEST') ? getenv('CIVICRM_GENCODE_DIGEST') : NULL |
| 57 | ); |
| 58 | $genCode->main(); |