summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-11-25 19:52:04 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-11-25 19:52:22 +0100
commit79736eb1cf6abacb2b79c8b8f8ca52d1cfcc6715 (patch)
tree46831c06aa2e7577e091e4d5109371a56718a844
parent052178a79f9099d1ce3c36e56334cdc15911ef09 (diff)
fix tests
-rw-r--r--README.md12
-rw-r--r--appinfo/register_command.php4
-rw-r--r--appinfo/routes.php1
-rw-r--r--command/migrate.php (renamed from command/generatesearchindices.php)11
-rw-r--r--controller/admincontroller.php20
-rw-r--r--css/admin.css6
-rw-r--r--js/admin/Admin.js13
-rw-r--r--service/itemservice.php23
-rw-r--r--templates/admin.php15
-rw-r--r--tests/integration/command/CommandTest.php4
-rw-r--r--tests/unit/controller/AdminControllerTest.php16
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php2
12 files changed, 97 insertions, 30 deletions
diff --git a/README.md b/README.md
index 79587fe48..6f8fc28c4 100644
--- a/README.md
+++ b/README.md
@@ -115,7 +115,13 @@ We switched to a different feed parsing library which creates article ids differ
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:
- ./occ news:create-search-indices
+ ./occ news:migrate
+
+### Updating from versions prior to 7
+
+Version 7 adds article deduplication. In order for this to work properly, database columns need to be generated. Since this can time out
+
+ ./occ news:migrate
## FAQ
@@ -188,9 +194,9 @@ The following commands are available when using the **occ** file in the top dire
./occ
-* **Generate search indices**:
+* **Migrate older data (only needed for certain versions, see Updating section)**:
- ./occ news:create-search-indices
+ ./occ news:migrate
Translations
------------
diff --git a/appinfo/register_command.php b/appinfo/register_command.php
index dc6b4fe31..91e379525 100644
--- a/appinfo/register_command.php
+++ b/appinfo/register_command.php
@@ -9,12 +9,12 @@
* @copyright Bernhard Posselt 2015
*/
-use OCA\News\Command\GenerateSearchIndices;
+use OCA\News\Command\Migrate;
use OCA\News\Command\VerifyInstall;
$newsApp = new OCA\News\AppInfo\Application();
$newsContainer = $newsApp->getContainer();
-$newsCmd = $newsContainer->query(GenerateSearchIndices::class);
+$newsCmd = $newsContainer->query(Migrate::class);
$verifyCmd = $newsContainer->query(VerifyInstall::class);
$application->add($newsCmd);
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 979ca3dac..9ebee93ef 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -21,6 +21,7 @@ return ['routes' => [
// admin
['name' => 'admin#update', 'url' => '/admin', 'verb' => 'PUT'],
+['name' => 'admin#migrate', 'url' => '/admin/migrate', 'verb' => 'POST'],
// folders
['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'],
diff --git a/command/generatesearchindices.php b/command/migrate.php
index 4bc41d04b..364ceda42 100644
--- a/command/generatesearchindices.php
+++ b/command/migrate.php
@@ -19,7 +19,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
use OCA\News\Service\ItemService;
-class GenerateSearchIndices extends Command {
+class Migrate extends Command {
private $service;
@@ -29,18 +29,19 @@ class GenerateSearchIndices extends Command {
}
protected function configure() {
- $this->setName('news:create-search-indices')
- ->setDescription('Recreates the search indices for all items');
+ $this->setName('news:migrate')
+ ->setDescription('Migrates the database schema. Needed when ' .
+ 'updating from versions prior to: 7.0.0');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln(
- "\nCreating search indices, this could take a while...\n"
+ "\nMigrating data, this could take a while...\n"
);
$progressbar = function ($steps) use ($output) {
return new ProgressBar($output, $steps);
};
- $this->service->generateSearchIndicies($progressbar);
+ $this->service->generateSearchIndices($progressbar);
$output->writeln("\n");
}
diff --git a/controller/admincontroller.php b/controller/admincontroller.php
index 7c9ccf7f2..3d8b272ba 100644
--- a/controller/admincontroller.php
+++ b/controller/admincontroller.php
@@ -13,22 +13,25 @@
namespace OCA\News\Controller;
-use \OCP\AppFramework\Http\TemplateResponse;
-use \OCP\IRequest;
-use \OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IRequest;
+use OCP\AppFramework\Controller;
-use \OCA\News\Config\Config;
+use OCA\News\Config\Config;
+use OCA\News\Service\itemService;
class AdminController extends Controller {
private $config;
private $configPath;
+ private $itemService;
public function __construct($AppName, IRequest $request, Config $config,
- $configFile){
+ ItemService $itemService, $configFile){
parent::__construct($AppName, $request);
$this->config = $config;
$this->configPath = $configFile;
+ $this->itemService = $itemService;
}
// There are no checks for the index method since the output is rendered
@@ -82,5 +85,12 @@ class AdminController extends Controller {
];
}
+ /**
+ * Generates indices
+ */
+ public function migrate() {
+ $this->itemService->generateSearchIndices();
+ return [];
+ }
}
diff --git a/css/admin.css b/css/admin.css
index 8571bc860..518508ffb 100644
--- a/css/admin.css
+++ b/css/admin.css
@@ -5,4 +5,8 @@
#news .form-line {
margin: 25px 0 15px 0;
-} \ No newline at end of file
+}
+
+#news .notice {
+ color: red;
+}
diff --git a/js/admin/Admin.js b/js/admin/Admin.js
index 823d6b0ab..93b5f0268 100644
--- a/js/admin/Admin.js
+++ b/js/admin/Admin.js
@@ -87,7 +87,18 @@
$('#news input[type="text"]').blur(submit);
$('#news input[type="checkbox"]').change(submit);
+ $('#news-migrate').click(function () {
+ var button = $(this);
+ button.addClass('loading');
+
+ $.post(OC.generateUrl('/apps/news/admin/migrate'))
+ .always(function (data) {
+ button.removeClass('loading');
+ });
+
+ return false;
+ });
});
-}(window, document, jQuery)); \ No newline at end of file
+}(window, document, jQuery));
diff --git a/service/itemservice.php b/service/itemservice.php
index 6f454dbf5..0b0746258 100644
--- a/service/itemservice.php
+++ b/service/itemservice.php
@@ -259,23 +259,30 @@ class ItemService extends Service {
/**
* Regenerates the search index for all items
*/
- public function generateSearchIndicies($progressbar) {
- $this->systemConfig->setSystemValue('maintenance', true);
-
+ public function generateSearchIndices($progressbar=null) {
+ if ($progressbar) {
+ $this->systemConfig->setSystemValue('maintenance', true);
+ $progressbar = $progressbar(count($rows));
+ $progressbar->setFormat('verbose');
+ }
+
$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();
+
+ if ($progressbar) {
+ $progressbar->advance();
+ }
}
- $progressbar->finish();
+ if ($progressbar) {
+ $progressbar->finish();
+ $this->systemConfig->setSystemValue('maintenance', false);
+ }
- $this->systemConfig->setSystemValue('maintenance', false);
}
}
diff --git a/templates/admin.php b/templates/admin.php
index 9f2a815ac..f4eac5089 100644
--- a/templates/admin.php
+++ b/templates/admin.php
@@ -122,7 +122,20 @@ style('news', 'admin');
<p><input type="text" name="news-explore-url"
value="<?php p($_['exploreUrl']); ?>"></p>
</div>
+ <div class="form-line">
+ <p>
+ <label for="news-migrate">
+ <?php p($l->t('Migrate data')); ?>
+ </label>
+ </p>
+ <p><em><?php p($l->t('Migrates existing data after updating from versions prior to 7.0.0')); ?></em></p>
+ <p><em class="notice"><?php p($l->t(
+ 'This takes about 1 minute per user. For bigger installations use ' .
+ 'this console command to prevent timeouts:')); ?> php -f owncloud/occ news:migrate
+ </em></p>
+ <p><button type="button" name="news-migrate" id="news-migrate"><?php p($l->t('Migrate data')); ?></button></p>
+ </div>
<div id="news-saved-message">
<span class="msg success"><?php p($l->t('Saved')); ?></span>
</div>
-</div> \ No newline at end of file
+</div>
diff --git a/tests/integration/command/CommandTest.php b/tests/integration/command/CommandTest.php
index 4501f3b95..72d7602ff 100644
--- a/tests/integration/command/CommandTest.php
+++ b/tests/integration/command/CommandTest.php
@@ -17,8 +17,8 @@ class CommandTest extends \PHPUnit_Framework_TestCase {
$this->corePath = __DIR__ . '/../../../../../';
}
- public function testGenerateIndices() {
- $command = $this->corePath . 'occ news:create-search-indices';
+ public function testMigrate() {
+ $command = $this->corePath . 'occ news:migrate';
exec($command, $_, $success);
$this->assertSame(0, $success);
diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php
index d86c4cf98..c74b8570e 100644
--- a/tests/unit/controller/AdminControllerTest.php
+++ b/tests/unit/controller/AdminControllerTest.php
@@ -21,6 +21,7 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
private $controller;
private $config;
private $configPath;
+ private $itemService;
/**
* Gets run before each test
@@ -35,9 +36,14 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
'\OCA\News\Config\Config')
->disableOriginalConstructor()
->getMock();
+ $this->itemService = $this->getMockBuilder(
+ '\OCA\News\Service\ItemService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->configPath = 'my.ini';
$this->controller = new AdminController($this->appName, $this->request,
- $this->config, $this->configPath);
+ $this->config, $this->itemService, $this->configPath);
}
@@ -151,4 +157,12 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $response);
}
+
+ public function testMigrate() {
+ $this->itemService->expects($this->once())
+ ->method('generateSearchIndices');
+ $this->controller->migrate();
+ }
+
+
}
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index 276a3e485..f6a03afa2 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -235,7 +235,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
$item->setEnclosureLink($this->enclosureLink);
}
$item->generateSearchIndex();
-
+
return $item;
}