forked from beeznest/chamilo-lms-icpna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console-config.php
executable file
·183 lines (131 loc) · 5.67 KB
/
console-config.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
<?php
/* For licensing terms, see /license.txt */
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$sysPath = __DIR__."/";
AnnotationRegistry::registerFile($sysPath."vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
$reader = new AnnotationReader();
$driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array($sysPath."tests/doctrine_console/mapping"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$courseList = CourseManager::get_real_course_list();
$app['chamilo.log'] = $app['sys_log_path'].'/chamilo-cli.log';
// Loading db connections
$connectionOptions = array();
if (!empty($courseList)) {
$dbPrefix = isset($_configuration['db_prefix']) && !empty($_configuration['db_prefix']) ? $_configuration['db_prefix'].Database::get_database_glue() : null;
foreach ($courseList as $course) {
$connectionOptions['_chamilo_course_'.$course['db_name']] = array(
'driver' => 'pdo_mysql',
'dbname' => $dbPrefix.$course['db_name'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
}
}
if (isset($_configuration['main_database'])) {
$connectionOptions['main_database'] = array(
'driver' => 'pdo_mysql',
'dbname' => $_configuration['main_database'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
}
if (isset($_configuration['statistics_database'])) {
$connectionOptions['statistics_database'] = array(
'driver' => 'pdo_mysql',
'dbname' => $_configuration['statistics_database'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
} else {
if (isset($_configuration['main_database'])) {
$connectionOptions['statistics_database'] = $connectionOptions['main_database'];
}
}
if (isset($_configuration['user_personal_database'])) {
$connectionOptions['user_personal_database'] = array(
'driver' => 'pdo_mysql',
'dbname' => $_configuration['user_personal_database'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
} else {
if (isset($_configuration['main_database'])) {
$connectionOptions['user_personal_database'] = $connectionOptions['main_database'];
}
}
$defaultConnection = array(
'driver' => 'pdo_mysql'
);
if (isset($_configuration['main_database'])) {
$defaultConnection = array(
'driver' => 'pdo_mysql',
'dbname' => $_configuration['main_database'],
'user' => $_configuration['db_user'],
'password' => $_configuration['db_password'],
'host' => $_configuration['db_host'],
);
}
$em = \Doctrine\ORM\EntityManager::create($defaultConnection, $config);
//Fixes some errors
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('set', 'string');
$helpers = array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em),
'configuration' => new \Chash\Helpers\ConfigurationHelper()
);
use Doctrine\DBAL\DriverManager;
$multipleEM = array();
foreach ($connectionOptions as $name => $connection) {
$em = \Doctrine\ORM\EntityManager::create($connection, $config);
//$helpers[$name] = new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em);
$helpers[$name] = new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection());
}
/*
To generate doctrine2 entities you must:
cd /var/www/chamilo11/tests/doctrine_console
Delete old mappings/entities
sudo rm -R mapping generated repository
Creating the mapping from the DB
sudo mkdir mapping generated repository
You can add a Namespace if you want to with: --namespace "Entity"
sudo php5 doctrine.php orm:convert-mapping --force --from-database --namespace "Entity" annotation mapping
1. Generate entities
sudo php5 doctrine.php orm:generate-entities --generate-annotations="true" generated
Validate schema
sudo php5 doctrine.php orm:validate-schema -v
Move generated files in a chamilo folder:
sudo rm -R main/inc/Entity/*
mkdir main/inc/Entity
cp -R tests/doctrine_console/generated/* main/inc/Entity
fixes \ORM bug see http://redgreenrefactor.blogsite.org/php/code-first-approaching-php-with-doctrine-2-2-1-and-composer/
cd main/inc/Entity
sed -i 's/@ORM\\/@/g' *.php
For tests
php5 tests/doctrine_console/doctrine.php orm:generate-entities --generate-annotations="true" main/inc/Entity
Then autoload classes with composer
sudo php5 composer.phar update or sudo composer.phar update
2. Migrations
a. Generate empty migration file
cd /var/www/chamilo11/tests/doctrine_console
php5 doctrine.php migrations:generate
b. Check status
php5 doctrine.php migrations:status
c. Check sql
php5 doctrine.php migrations:migrate --dry-run
d. execute migration
php5 doctrine.php migrations:migrate
e. Revert migrations
php5 doctrine.php migrations:migrate 0
http://docs.doctrine-project.org/projects/doctrine-migrations/en/latest/reference/managing_migrations.html
*/