first migration script for misp0.2 to misp1.0 (not finished)

pull/61/head
Christophe Vandeplas 2012-06-14 11:03:43 +02:00
parent 2d283962ce
commit 3996edca45
1 changed files with 68 additions and 15 deletions

View File

@ -189,30 +189,34 @@ class AppController extends Controller {
if (!self::_isAdmin()) throw new NotFoundException();
// search for composite value1 fields and explode it to value1 and value2
$this->loadModel('Attribute');
_explodeValueToValues();
}
function _explodeValueToValues() {
// search for composite value1 fields and explode it to value1 and value2
$this->loadModel('Attribute');
$params = array(
'conditions' => array(
'OR' => array(
'Attribute.type' => $this->Attribute->getCompositeTypes()
)
),
'conditions' => array(
'OR' => array(
'Attribute.type' => $this->Attribute->getCompositeTypes()
)
),
'recursive' => 0,
'fields' => array('Attribute.id', 'Attribute.value1'),
);
$attributes = $this->Attribute->find('all', $params);
echo '<p>Exploding composite fields in 2 columns: </p><ul>';
foreach ($attributes as $attribute) {
$pieces = explode('|', $attribute['Attribute']['value1']);
if (2 != sizeof($pieces)) continue; // do nothing if not 2 pieces
echo '<h2>Exploding composite fields in 2 columns: </h2><ul>';
foreach ($attributes as $attribute) {
$pieces = explode('|', $attribute['Attribute']['value1']);
if (2 != sizeof($pieces)) continue; // do nothing if not 2 pieces
$this->Attribute->id = $attribute['Attribute']['id'];
echo '<li>'.$attribute['Attribute']['id'].' --> '.$attribute['Attribute']['value1'].' --> '.$pieces[0].' --> '.$pieces[1].'</li> ';
$this->Attribute->saveField('value1', $pieces[0]);
$this->Attribute->id = $attribute['Attribute']['id'];
echo '<li>'.$attribute['Attribute']['id'].' --> '.$attribute['Attribute']['value1'].' --> '.$pieces[0].' --> '.$pieces[1].'</li> ';
$this->Attribute->saveField('value1', $pieces[0]);
$this->Attribute->id = $attribute['Attribute']['id'];
$this->Attribute->saveField('value2', $pieces[1]);
}
echo "</ul> DONE</p>";
echo "</ul> DONE.";
}
@ -246,6 +250,55 @@ class AppController extends Controller {
// search for incompatible combination of category / type
}
function miratemisp02to10() {
if (!self::_isAdmin()) throw new NotFoundException();
// add missing columns, rename other columns
$queries = array(
// ATTRIBUTES
// rename value to value1
"ALTER TABLE `attributes` CHANGE `value` `value1` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL "
// add value2
,"ALTER TABLE `attributes` ADD `value2` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `value1` "
// fix the keys
,"ALTER TABLE `attributes` DROP INDEX `uuid`;"
,"ALTER TABLE `attributes` ADD INDEX `value1_key` ( `value1` ( 5 ) ) ;"
,"ALTER TABLE `attributes` ADD INDEX `value2_key` ( `value2` ( 5 ) ) ;"
// EVENTS
// remove useless things
,"ALTER TABLE `events` DROP `user_id`"
,"ALTER TABLE `events` DROP `alerted`"
,"ALTER TABLE `events` ADD `revision` INT( 10 ) NOT NULL DEFAULT '0' AFTER `uuid` "
// fix the keys
,"ALTER TABLE events DROP INDEX uuid"
,"ALTER TABLE events DROP INDEX info"
// SERVERS
// rename lastfetchedid to lastpushedid
,"ALTER TABLE `servers` CHANGE `lastfetchedid` `lastpushedid` INT( 11 ) NOT NULL "
// add lastpulledid
,"ALTER TABLE `servers` ADD `lastpulledid` INT( 11 ) NOT NULL AFTER `lastpushedid` "
// USERS
// fix keys
,"ALTER TABLE `users` DROP INDEX `username`"
,"ALTER TABLE `users` ADD INDEX `email` ( `email` ) "
);
// execute the queries
foreach ($queries as &$query) {
$result = $this->{$this->modelClass}->query($query);
}
// TODO first search for incompatible combination of category / type
// then search for composite value1 fields and explode it to value1 and value2
//_explodeValueToValues();
}
}