From 5657a9dd10a67ea87d35d59386589c957ad40e59 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Mon, 26 Mar 2012 20:25:45 +0200 Subject: [PATCH] Added a migrate() function to generate uuid for events and attributes that didn't have an uuid --- app/Controller/AppController.php | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 9438b8976..5a810d704 100644 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -98,16 +98,42 @@ class AppController extends Controller { /** * Updates the missing fields from v0.1 to v0.2 of CyDefSIG + * First you will need to manually update the database to the new schema. + * Then run this function by setting debug = 1 (or more) and call /events/migrate */ - function migrate () { + function migrate() { + if (Configure::read('debug') == 0) throw new NotFoundException(); // generate uuids for events who have no uuid $this->loadModel('Event'); + $params = array( + 'conditions' => array('Event.uuid' => ''), + 'recursive' => 0, + 'fields' => array('Event.id'), + ); + $events = $this->Event->find('all', $params); - + echo '

Generating UUID for events: '; + foreach ($events as $event) { + $this->Event->id = $event['Event']['id']; + $this->Event->saveField('uuid', String::uuid()); + echo $event['Event']['id'].' '; + } + echo "

"; // generate uuids for attributes who have no uuid $this->loadModel('Attribute'); - - debug("foo"); + $params = array( + 'conditions' => array('Attribute.uuid' => ''), + 'recursive' => 0, + 'fields' => array('Attribute.id'), + ); + $attributes = $this->Attribute->find('all', $params); + echo '

Generating UUID for attributes: '; + foreach ($attributes as $attribute) { + $this->Attribute->id = $attribute['Attribute']['id']; + $this->Attribute->saveField('uuid', String::uuid()); + echo $attribute['Attribute']['id'].' '; + } + echo "

"; }