- echo "\nFound old $table table, upgrading it to contain 'act_uri' and 'act_created' field...";
-
- $schemadef['fields']['act_uri'] = array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'URI of the deleted notice');
- $schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'datetime the notice record was created');
- unset($schemadef['unique keys']);
- $schema->ensureTable($table, $schemadef);
-
- $deleted = new Deleted_notice();
- $result = $deleted->find();
- if ($result === false) {
- print "\nFound no deleted_notice entries, continuing...";
- return true;
- }
- print "\nFound $result deleted_notice entries, aligning with new database layout: ";
- while($deleted->fetch()) {
- $orig = clone($deleted);
- $deleted->act_uri = $deleted->uri;
- // this is a fake URI just to have something to put there to avoid NULL. crc32 of uri is to avoid collisions
- $deleted->uri = TagURI::mint(strtolower(get_called_class()).':%d:%s:%s:%s:crc32=%x',
- $deleted->profile_id,
- ActivityUtils::resolveUri(self::getObjectType(), true),
- 'unknown',
- common_date_iso8601($deleted->created),
- crc32($deleted->act_uri)
- );
- $deleted->act_created = $deleted->created; // we don't actually know when the notice was created
- $deleted->updateWithKeys($orig, 'id');
- print ".";
+
+ if (!isset($schemadef['fields']['act_created'])) {
+ // this is a "normal" upgrade from StatusNet for example
+ echo "\nFound old $table table, upgrading it to add 'act_created' field...";
+
+ $schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'datetime the notice record was created');
+ $schema->ensureTable($table, $schemadef);
+
+ $deleted = new Deleted_notice();
+ // we don't actually know when the notice was created for the old ones
+ $deleted->query('UPDATE deleted_notice SET act_created=created;');
+ } else {
+ // 2015-10-03 For a while we had act_uri and act_created fields which
+ // apparently wasn't necessary.
+ echo "\nFound old $table table, upgrading it to remove 'act_uri' field...";
+
+ // we stored what should be in 'uri' in the 'act_uri' field for some night-coding reason.
+ $deleted = new Deleted_notice();
+ $deleted->query('UPDATE deleted_notice SET uri=act_uri;');