forked from NetCommons3/NetCommons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetCommonsMigration.php
More file actions
63 lines (57 loc) · 1.51 KB
/
NetCommonsMigration.php
File metadata and controls
63 lines (57 loc) · 1.51 KB
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
<?php
/**
* NetCommonsMigration
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('CakeMigration', 'Migrations.Lib');
App::uses('I18n', 'I18n');
/**
* NetCommonsMigration
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\NetCommons\Config\Migration
*/
class NetCommonsMigration extends CakeMigration {
/**
* Update model records
*
* @param string $model model name to update
* @param string $records records to be stored
* @param string $clear 初期化するかどうか
* @return bool Should process continue
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function updateRecords($model, $records, $clear = true) {
$Model = $this->generateModel($model);
if ($clear) {
$Model->deleteAll(array(), false, false);
}
foreach ($records as $record) {
$Model->create();
if (!$Model->save($record, false)) {
return false;
}
}
return true;
}
/**
* Load models
*
* @param array $models models to load
* @param string $source data source
* @return void
*/
public function loadModels(array $models = [], $source = 'master') {
foreach ($models as $model => $class) {
$this->$model = ClassRegistry::init($class, true);
if ($this->$model->useDbConfig !== 'test') {
$this->$model->setDataSource($source);
}
}
}
}