Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
add migrate command, fix #185
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed Mar 21, 2015
1 parent 35550fe commit f6bf8ce
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
owncloud-news (5.3.0)
* **Enhancement**: Make it possible to search articles in the search field
* **Enhancement**: Make it possible to search articles in the search field. To migrate older articles to this functionality, check the README section "Updating from versions prior to 5.3.0"
* **New dependency**: Bump required ownCloud version to 8.1

owncloud-news (5.2.8)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ You need to do the following:
### After updating from a version prior to 4 all my read articles reappear as unread and there are duplicates
We switched to a different feed parsing library which creates article ids differently than before. This means that the same article is not found in the database because it was generated with a different id and is thus readded. This should happen only once for each feed after the upgrade and there is no data loss. Unfortunately there is no fix for this since the id is a hash which can not be reversed, so a smooth transition is not possible.

### Updating from versions prior to 5.3.0

5.3.0 adds the possibility to search your articles. To do this efficiently however, the News app needs to generate an index. This is done automatically for new articles, but older articles need to be migrated. Because large installations have millions of articles, generating the search index has been offloaded to a separate command to prevent timeouts when upgrading the app. To make your old articles searchable run this command in your ownCloud top directory:

php -f console.php news:create-search-indices

## FAQ

### How do I reset the News app
Expand Down
2 changes: 1 addition & 1 deletion appinfo/checksum.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions appinfo/register_command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* ownCloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2015
*/

$newsApp = new OCA\News\AppInfo\Application();
$newsCmd = $newsApp->getContainer()->query('OCA\News\Command\GenerateSearchIndices');

$application->add($newsCmd);
45 changes: 45 additions & 0 deletions command/generatesearchindices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* ownCloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2015
*/

namespace OCA\News\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;

use OCA\News\Service\ItemService;


class GenerateSearchIndices extends Command {

private $service;

public function __construct(ItemService $service) {
parent::__construct();
$this->service = $service;
}

protected function configure() {
$this->setName('news:create-search-indices')
->setDescription('Recreates the search indices for all items');
}

protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("\nCreating search indices, this could take a while...\n");
$progressbar = function ($steps) use ($output) {
return new ProgressBar($output, $steps);
};
$this->service->generateSearchIndicies($progressbar);
$output->writeln("\n");
}

}
14 changes: 13 additions & 1 deletion db/itemmapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace OCA\News\Db;

use \OCP\IDBConnection;
use OCP\IDBConnection;


class ItemMapper extends NewsMapper {
Expand Down Expand Up @@ -328,4 +328,16 @@ public function deleteUser($userId) {
}


/**
* Returns a list of ids and userid of all items
*/
public function findAllItemIdsAndUsers() {
$sql = 'SELECT `items`.`id`, `feeds`.`user_id` ' .
'FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
'ON `items`.`feed_id` = `feeds`.`id`';
return $this->execute($sql)->fetchAll();
}


}
40 changes: 33 additions & 7 deletions service/itemservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

namespace OCA\News\Service;

use \OCP\AppFramework\Db\DoesNotExistException;
use \OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;

use \OCA\News\Db\ItemMapper;
use \OCA\News\Db\StatusFlag;
use \OCA\News\Db\FeedType;
use \OCA\News\Config\Config;
use OCA\News\Db\ItemMapper;
use OCA\News\Db\StatusFlag;
use OCA\News\Db\FeedType;
use OCA\News\Config\Config;


class ItemService extends Service {
Expand All @@ -28,16 +29,19 @@ class ItemService extends Service {
private $config;
private $timeFactory;
private $itemMapper;
private $systemConfig;

public function __construct(ItemMapper $itemMapper,
StatusFlag $statusFlag,
ITimeFactory $timeFactory,
Config $config){
Config $config,
IConfig $systemConfig){
parent::__construct($itemMapper);
$this->statusFlag = $statusFlag;
$this->config = $config;
$this->timeFactory = $timeFactory;
$this->itemMapper = $itemMapper;
$this->systemConfig = $systemConfig;
}


Expand Down Expand Up @@ -252,4 +256,26 @@ public function deleteUser($userId) {
}


/**
* Regenerates the search index for all items
*/
public function generateSearchIndicies($progressbar) {
$this->systemConfig->setSystemValue('maintenance', true);

$rows = $this->itemMapper->findAllItemIdsAndUsers();
$progressbar = $progressbar(count($rows));
$progressbar->setFormat('verbose');

foreach ($rows as $row) {
$item = $this->find($row['id'], $row['user_id']);
$item->generateSearchIndex();
$this->itemMapper->update($item);
$progressbar->advance();
}

$progressbar->finish();

$this->systemConfig->setSystemValue('maintenance', false);
}

}
9 changes: 7 additions & 2 deletions tests/unit/service/ItemServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
private $time;
private $newestItemId;
private $config;

private $systemConfig;

protected function setUp(){
$this->time = 222;
Expand All @@ -54,8 +54,13 @@ protected function setUp(){
'\OCA\News\Config\Config')
->disableOriginalConstructor()
->getMock();
$this->systemConfig = $this->getMockBuilder(
'OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$this->itemService = new ItemService($this->mapper,
$this->statusFlag, $this->timeFactory, $this->config);
$this->statusFlag, $this->timeFactory, $this->config,
$this->systemConfig);
$this->user = 'jack';
$this->id = 3;
$this->updatedSince = 20333;
Expand Down

0 comments on commit f6bf8ce

Please sign in to comment.