Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Make it possible to mark messages important
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Apr 22, 2020
1 parent 8a6f5ba commit fce904a
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 33 deletions.
33 changes: 0 additions & 33 deletions lib/Migration/Version1040Date20200326130220.php

This file was deleted.

56 changes: 56 additions & 0 deletions lib/Migration/Version1040Date20200422130220.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version1040Date20200422130220 extends SimpleMigrationStep {

/** @var IDBConnection */
protected $connection;

public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$schema->dropTable('mail_messages');

return $schema;
}

public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
// Reset locks and sync tokens
$qb1 = $this->connection->getQueryBuilder();
$updateMailboxes = $qb1->update('mail_mailboxes')
->set('sync_new_lock', $qb1->createNamedParameter(null))
->set('sync_new_token', $qb1->createNamedParameter(null))
->set('sync_changed_lock', $qb1->createNamedParameter(null))
->set('sync_changed_token', $qb1->createNamedParameter(null))
->set('sync_vanished_lock', $qb1->createNamedParameter(null))
->set('sync_vanished_token', $qb1->createNamedParameter(null));
$updateMailboxes->execute();

// Clean up some orphaned data
$qb2 = $this->connection->getQueryBuilder();
$deleteRecipients = $qb2->delete('mail_recipients');
$deleteRecipients->execute();
}

}
117 changes: 117 additions & 0 deletions lib/Migration/Version1040Date20200422142920.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

declare(strict_types=1);

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version1040Date20200422142920 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$messagesTable = $schema->createTable('mail_messages');
$messagesTable->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
'length' => 20,
]);
$messagesTable->addColumn('uid', 'integer', [
'notnull' => true,
'length' => 4,
]);
$messagesTable->addColumn('message_id', 'string', [
'notnull' => false,
'length' => 255,
]);
$messagesTable->addColumn('mailbox_id', 'integer', [
'notnull' => true,
'length' => 20,
]);
$messagesTable->addColumn('subject', 'string', [
'notnull' => true,
'length' => 255,
'default' => '',
]);
$messagesTable->addColumn('sent_at', 'integer', [
'notnull' => true,
'length' => 4,
]);
$messagesTable->addColumn('flag_answered', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_deleted', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_draft', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_flagged', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_seen', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_forwarded', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_junk', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_notjunk', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('flag_attachments', 'boolean', [
'notnull' => false,
]);
$messagesTable->addColumn('flag_important', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('structure_analyzed', 'boolean', [
'notnull' => true,
'default' => false,
]);
$messagesTable->addColumn('preview_text', 'string', [
'notnull' => false,
'length' => 255,
]);
$messagesTable->addColumn('updated_at', 'integer', [
'notnull' => false,
'length' => 4,
]);
$messagesTable->setPrimaryKey(['id']);
// We allow each UID just once
$messagesTable->addUniqueIndex(
[
'uid',
'mailbox_id',
],
'mail_msg_mb_uid_idx'
);
$messagesTable->addIndex(['sent_at'], 'mail_msg_sent_idx');

return $schema;
}

}

0 comments on commit fce904a

Please sign in to comment.