return $out;
}
+ public function renameTable(string $old_name, string $new_name) : bool
+ {
+ try {
+ $this->getTableDef($old_name);
+ try {
+ $this->getTableDef($new_name);
+ // New table exists, can't work
+ throw new ServerException("Both table {$old_name} and {$new_name} exist. You're on your own");
+ } catch(SchemaTableMissingException $e) {
+ // New table doesn't exist, carry on
+ }
+ } catch(SchemaTableMissingException $e) {
+ // Already renamed, or no previous table, so we're done
+ return true;
+ }
+ return $this->runSqlSet(["ALTER TABLE {$old_name} RENAME TO {$new_name};"]);
+ }
+
}
class SchemaTableMissingException extends Exception
*/
public function onCheckSchema()
{
+ $this->onEndUpgrade(); // Ensure rename
+
$schema = Schema::get();
- $schema->ensureTable('file_oembed', File_oembed::schemaDef());
+ $schema->ensureTable('file_embed', File_embed::schemaDef());
return true;
}
+ public function onEndUpgrade()
+ {
+ $schema = Schema::get();
+ return $schema->renameTable('file_oembed', 'file_embed');
+ }
+
/**
* This code executes when GNU social creates the page routing, and we hook
* on this event to add our action handler for Embed.
defined('GNUSOCIAL') || die();
/**
- * Table Definition for file_oembed
+ * Table Definition for file_embed
*
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
-class File_oembed extends Managed_DataObject
+class File_embed extends Managed_DataObject
{
- public $__table = 'file_oembed'; // table name
+ public $__table = 'file_embed'; // table name
public $file_id; // int(4) primary_key not_null
public $version; // varchar(20)
public $type; // varchar(20)
),
'primary key' => array('file_id'),
'foreign keys' => array(
- 'file_oembed_file_id_fkey' => array('file', array('file_id' => 'id')),
+ 'file_embed_file_id_fkey' => array('file', array('file_id' => 'id')),
),
);
}