From a97dd58e3b499b60ac8b37786d402d7f2e371a88 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Mon, 14 Aug 2017 10:34:53 +0200 Subject: Split binary to booleans (#203) * replaced old status with 2 flags for unread and starred * add fields to db, replace int(1,0) with booleans in sql queries, removed StatusFlags class + refactor code relying to it * add repair step for migration * again use integer(1,0) instead of bool in sql queries, because of sqlite doesn't support true/false * add/fix unit tests for new boolean status * set unread/starred flags as statements in sql * fixed mysql unknown column items.unread, fixed marking of read items on repair step * remove unnecessary bool casts * add empty checks to Items::is* methods * update migration to use native sql instead of the querybuilder * don't cast the flags manually, let the api do the work --- lib/Migration/MigrateStatusFlags.php | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/Migration/MigrateStatusFlags.php (limited to 'lib/Migration') diff --git a/lib/Migration/MigrateStatusFlags.php b/lib/Migration/MigrateStatusFlags.php new file mode 100644 index 000000000..acf53ebba --- /dev/null +++ b/lib/Migration/MigrateStatusFlags.php @@ -0,0 +1,56 @@ + + * @copyright Daniel Opitz 2017 + */ + +namespace OCA\News\Migration; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\IRepairStep; +use OCP\Migration\IOutput; + +class MigrateStatusFlags implements IRepairStep { + + /** @var IDBConnection */ + private $db; + + /** @var IConfig */ + private $config; + + /** + * @param IDBConnection $db + * @param IConfig $config + */ + public function __construct(IDBConnection $db, IConfig $config) { + $this->db = $db; + $this->config = $config; + } + + public function getName() { + return 'Migrate binary status into separate boolean fields'; + } + + public function run(IOutput $output) { + $version = $this->config->getAppValue('news', 'installed_version', '0.0.0'); + if (version_compare($version, '11.0.6', '>=')) { + return; + } + + $sql = 'UPDATE `*PREFIX*news_items` ' + . 'SET `unread` = ((`status` & 2) = 2), ' + . '`starred` = ((`status` & 4) = 4)'; + $query = $this->db->prepare($sql); + + if (!$query->execute()) { + throw new \Exception('Could not migrate status'); + } + } +} \ No newline at end of file -- cgit v1.2.3