4 * Create SQL files to create and populate a new schema.
6 class CRM_Core_CodeGen_Schema
extends CRM_Core_CodeGen_BaseTask
{
7 function __construct() {
9 $this->locales
= $this->findLocales();
13 CRM_Core_CodeGen_Util_File
::createDir($this->config
->sqlCodePath
);
15 $this->generateCreateSql();
16 $this->generateDropSql();
18 $this->generateLocaleDataSql();
20 // also create the archive tables
21 // $this->generateCreateSql('civicrm_archive.mysql' );
22 // $this->generateDropSql('civicrm_archive_drop.mysql');
24 $this->generateNavigation();
25 $this->generateSample();
28 function generateCreateSql($fileName = 'civicrm.mysql') {
29 echo "Generating sql file\n";
30 $template = new CRM_Core_CodeGen_Util_Template('sql');
32 $template->assign('database', $this->config
->database
);
33 $template->assign('tables', $this->tables
);
34 $dropOrder = array_reverse(array_keys($this->tables
));
35 $template->assign('dropOrder', $dropOrder);
36 $template->assign('mysql', 'modern');
38 $template->run('schema.tpl', $this->config
->sqlCodePath
. $fileName);
41 function generateDropSql($fileName = 'civicrm_drop.mysql') {
42 echo "Generating sql drop tables file\n";
43 $dropOrder = array_reverse(array_keys($this->tables
));
44 $template = new CRM_Core_CodeGen_Util_Template('sql');
45 $template->assign('dropOrder', $dropOrder);
46 $template->run('drop.tpl', $this->config
->sqlCodePath
. $fileName);
49 function generateNavigation() {
50 echo "Generating navigation file\n";
51 $template = new CRM_Core_CodeGen_Util_Template('sql');
52 $template->run('civicrm_navigation.tpl', $this->config
->sqlCodePath
. "civicrm_navigation.mysql");
55 function generateLocaleDataSql() {
56 $template = new CRM_Core_CodeGen_Util_Template('sql');
59 $oldTsLocale = $tsLocale;
60 foreach ($this->locales
as $locale) {
61 echo "Generating data files for $locale\n";
63 $template->assign('locale', $locale);
64 $template->assign('db_version', $this->config
->db_version
);
67 'civicrm_country.tpl',
68 'civicrm_state_province.tpl',
69 'civicrm_currency.tpl',
71 'civicrm_navigation.tpl',
72 'civicrm_version_sql.tpl',
75 $ext = ($locale != 'en_US' ?
".$locale" : '');
76 // write the initialize base-data sql script
77 $template->runConcat($sections, $this->config
->sqlCodePath
. "civicrm_data$ext.mysql");
79 // write the acl sql script
80 $template->run('civicrm_acl.tpl', $this->config
->sqlCodePath
. "civicrm_acl$ext.mysql");
82 $tsLocale = $oldTsLocale;
85 function generateSample() {
86 $template = new CRM_Core_CodeGen_Util_Template('sql');
91 $template->runConcat($sections, $this->config
->sqlCodePath
. 'civicrm_sample.mysql');
94 function findLocales() {
95 require_once 'CRM/Core/Config.php';
96 $config = CRM_Core_Config
::singleton(FALSE);
98 if (substr($config->gettextResourceDir
, 0, 1) === '/') {
99 $localeDir = $config->gettextResourceDir
;
102 $localeDir = '../' . $config->gettextResourceDir
;
104 if (file_exists($localeDir)) {
105 $config->gettextResourceDir
= $localeDir;
106 $locales = preg_grep('/^[a-z][a-z]_[A-Z][A-Z]$/', scandir($localeDir));
109 $localesMask = getenv('CIVICRM_LOCALES');
110 if (!empty($localesMask)) {
111 $mask = explode(',', $localesMask);
112 $locales = array_intersect($locales, $mask);
115 if (!in_array('en_US', $locales)) {
116 array_unshift($locales, 'en_US');