Exemple #1
0
 public static function beforeSchemaUpdate()
 {
     $table = strtolower(get_called_class());
     $schema = Schema::get();
     $schemadef = $schema->getTableDef($table);
     // 2015-12-31 RSVPs refer to Happening by event_uri now, not event_id. Let's migrate!
     if (isset($schemadef['fields']['event_uri'])) {
         // We seem to have already migrated, good!
         return;
     }
     // this is a "normal" upgrade from StatusNet for example
     echo "\nFound old {$table} table, upgrading it to add 'event_uri' field...";
     $schemadef['fields']['event_uri'] = array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'Event URI');
     $schema->ensureTable($table, $schemadef);
     $rsvp = new RSVP();
     $rsvp->find();
     while ($rsvp->fetch()) {
         $event = Happening::getKV('id', $rsvp->event_id);
         if (!$event instanceof Happening) {
             $rsvp->delete();
             continue;
         }
         $orig = clone $rsvp;
         $rsvp->event_uri = $event->uri;
         $rsvp->updateWithKeys($orig);
     }
     print "DONE.\n";
     print "Resuming core schema upgrade...";
 }