summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-11-26 19:51:29 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-11-26 19:51:49 +0100
commit6f48a74ead80c57e291ca2be78645449e99ae5f0 (patch)
tree783d228246b38fe135f772461958d00f56900ac0
parent050ca4af5a2c72ecd31305ed7b91afc4f411efa1 (diff)
add autoupdate for indices
-rw-r--r--CHANGELOG.md4
-rw-r--r--appinfo/register_command.php21
-rw-r--r--appinfo/update.php17
-rw-r--r--command/migrate.php48
-rw-r--r--command/verifyinstall.php80
-rw-r--r--controller/admincontroller.php8
-rw-r--r--db/item.php1
-rw-r--r--service/itemservice.php17
-rw-r--r--templates/admin.php13
-rw-r--r--tests/integration/command/CommandTest.php34
-rw-r--r--tests/unit/controller/AdminControllerTest.php7
-rw-r--r--tests/unit/upgrade/UpgradeTest.php63
-rw-r--r--upgrade/upgrade.php49
13 files changed, 132 insertions, 230 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 484ac89bf..7971281d7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,6 @@
owncloud-news (7.0.0)
-* **Backwards incompatible change**: Rename **./occ news:create-search-indices** to **./occ news:migrate**
-* **Backwards incompatible change**: News data needs to be migrated, otherwise an incorrect amount of articles will show up in the web interface **./occ news:migrate**
+* **Backwards incompatible change**: Remove console commands and instead run them after specific updates
* **Enhancement**: If a feed failed to update more than 10 times, show a hint in the web interface
-* **Enhancement**: Add a button in the admin section to run the **news:migrate** command through the web interface
owncloud-news (6.1.1)
* **Security**: Update picoFeed to add an [XXE fix for php-fpm](http://framework.zend.com/security/advisory/ZF2015-06) on systems with PHP <5.5.22 or >5.6 and <5.6.6. This issue allows any user with access to the News app to read abitrary files from the server. For more information read up on the [Zend advisory](http://framework.zend.com/security/advisory/ZF2015-06) and the [OWASP page](https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing). Affected supported distributions include [Ubuntu 14.04](https://bugs.launchpad.net/ubuntu/trusty/+source/php5/+bug/1509817)
diff --git a/appinfo/register_command.php b/appinfo/register_command.php
deleted file mode 100644
index 91e379525..000000000
--- a/appinfo/register_command.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Bernhard Posselt 2015
- */
-
-use OCA\News\Command\Migrate;
-use OCA\News\Command\VerifyInstall;
-
-$newsApp = new OCA\News\AppInfo\Application();
-$newsContainer = $newsApp->getContainer();
-$newsCmd = $newsContainer->query(Migrate::class);
-$verifyCmd = $newsContainer->query(VerifyInstall::class);
-
-$application->add($newsCmd);
-$application->add($verifyCmd);
diff --git a/appinfo/update.php b/appinfo/update.php
new file mode 100644
index 000000000..a99b4d4de
--- /dev/null
+++ b/appinfo/update.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2015
+ */
+
+namespace OCA\News\AppInfo;
+
+use OCA\News\Upgrade\Upgrade;
+
+$app = new Application();
+$app->getContainer()->query(Upgrade::class)->upgrade();
diff --git a/command/migrate.php b/command/migrate.php
deleted file mode 100644
index 364ceda42..000000000
--- a/command/migrate.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @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 Migrate extends Command {
-
- private $service;
-
- public function __construct(ItemService $service) {
- parent::__construct();
- $this->service = $service;
- }
-
- protected function configure() {
- $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(
- "\nMigrating data, this could take a while...\n"
- );
- $progressbar = function ($steps) use ($output) {
- return new ProgressBar($output, $steps);
- };
- $this->service->generateSearchIndices($progressbar);
- $output->writeln("\n");
- }
-
-}
diff --git a/command/verifyinstall.php b/command/verifyinstall.php
deleted file mode 100644
index 4277ff6e7..000000000
--- a/command/verifyinstall.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @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 Riimu\Kit\PathJoin\Path;
-
-use OCA\News\Utility\FileChecksumValidator;
-
-
-class VerifyInstall extends Command {
-
- private $fileChecksums;
-
- public function __construct($checksums) {
- parent::__construct();
- $this->fileChecksums = $checksums;
- }
-
- protected function configure() {
- $this->setName('news:verify-install')
- ->setDescription('Run this command to check if your News ' .
- 'installation has outdated or missing files.');
- }
-
- protected function execute(InputInterface $input, OutputInterface $output) {
- $checksums = json_decode($this->fileChecksums, true);
- $root = __DIR__ . '/../';
- $progressbar = new ProgressBar($output, count($checksums));
- $errors = [];
- $missing = [];
-
- foreach($checksums as $file => $checksum) {
- $progressbar->advance();
- $absPath = Path::normalize($root . $file);
-
- if (!file_exists($absPath)) {
- $missing[] = $absPath;
- } elseif (md5(file_get_contents($absPath)) !== $checksum) {
- $errors[] = $absPath;
- }
- }
-
- $output->writeln("\n");
-
- if (count($errors) > 0 || count($missing) > 0) {
- foreach ($missing as $path) {
- $output->writeln('<error>Missing file:</error> ' . $path);
- }
- foreach ($errors as $path) {
- $output->writeln('<error>Invalid checksum:</error> ' . $path);
- }
- $output->writeln("\nYour News installation does not " .
- 'match the recorded files and versions. This ' .
- 'is either caused by missing or old files or an ' .
- 'invalid or out of date appinfo/checksum.json ' .
- 'file.');
- $output->writeln('Either way, please make sure that the contents ' .
- 'of the News app\'s directory match the ' .
- 'contents of the installed tarball.');
- return 1;
- } else {
- $output->writeln('<info>Installation verified, everything OK!' .
- '</info>');
- }
- }
-
-}
diff --git a/controller/admincontroller.php b/controller/admincontroller.php
index 3d8b272ba..a673566de 100644
--- a/controller/admincontroller.php
+++ b/controller/admincontroller.php
@@ -85,12 +85,4 @@ class AdminController extends Controller {
];
}
- /**
- * Generates indices
- */
- public function migrate() {
- $this->itemService->generateSearchIndices();
- return [];
- }
-
}
diff --git a/db/item.php b/db/item.php
index 117e98fb5..5cbfc2fa2 100644
--- a/db/item.php
+++ b/db/item.php
@@ -44,6 +44,7 @@ use \OCP\AppFramework\Db\Entity;
* @method integer getLastModified()
* @method void setLastModified(integer $value)
* @method void setFingerprint(string $value)
+ * @method void setSearchIndex(string $value)
*/
class Item extends Entity implements IAPI, \JsonSerializable {
diff --git a/service/itemservice.php b/service/itemservice.php
index 0b0746258..ec6bee8bd 100644
--- a/service/itemservice.php
+++ b/service/itemservice.php
@@ -259,28 +259,13 @@ class ItemService extends Service {
/**
* Regenerates the search index for all items
*/
- public function generateSearchIndices($progressbar=null) {
- if ($progressbar) {
- $this->systemConfig->setSystemValue('maintenance', true);
- $progressbar = $progressbar(count($rows));
- $progressbar->setFormat('verbose');
- }
-
+ public function generateSearchIndices() {
$rows = $this->itemMapper->findAllItemIdsAndUsers();
foreach ($rows as $row) {
$item = $this->find($row['id'], $row['user_id']);
$item->generateSearchIndex();
$this->itemMapper->update($item);
-
- if ($progressbar) {
- $progressbar->advance();
- }
- }
-
- if ($progressbar) {
- $progressbar->finish();
- $this->systemConfig->setSystemValue('maintenance', false);
}
}
diff --git a/templates/admin.php b/templates/admin.php
index f4eac5089..1d7c56003 100644
--- a/templates/admin.php
+++ b/templates/admin.php
@@ -122,19 +122,6 @@ 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>
diff --git a/tests/integration/command/CommandTest.php b/tests/integration/command/CommandTest.php
deleted file mode 100644
index 72d7602ff..000000000
--- a/tests/integration/command/CommandTest.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Bernhard Posselt 2015
- */
-
-class CommandTest extends \PHPUnit_Framework_TestCase {
-
- private $corePath;
-
- public function setUp() {
- $this->corePath = __DIR__ . '/../../../../../';
- }
-
- public function testMigrate() {
- $command = $this->corePath . 'occ news:migrate';
- exec($command, $_, $success);
-
- $this->assertSame(0, $success);
- }
-
- public function testCronUpdate() {
- $command = 'php -f ' . $this->corePath . 'cron.php';
- exec($command, $output, $success);
-
- $this->assertSame(0, $success);
- }
-
-}
diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php
index c74b8570e..9d5014636 100644
--- a/tests/unit/controller/AdminControllerTest.php
+++ b/tests/unit/controller/AdminControllerTest.php
@@ -158,11 +158,4 @@ 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/upgrade/UpgradeTest.php b/tests/unit/upgrade/UpgradeTest.php
new file mode 100644
index 000000000..936c329ca
--- /dev/null
+++ b/tests/unit/upgrade/UpgradeTest.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Created by IntelliJ IDEA.
+ * User: bernhard
+ * Date: 11/26/15
+ * Time: 7:40 PM
+ */
+
+namespace OCA\News\Upgrade;
+
+use OCP\IConfig;
+use OCA\News\Service\ItemService;
+
+class UpgradeTest extends \PHPUnit_Framework_TestCase {
+
+ /** @var Upgrade */
+ private $upgrade;
+
+ /** @var ItemService */
+ private $service;
+
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ $this->config = $this->getMockBuilder(
+ '\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->service = $this->getMockBuilder(
+ '\OCA\News\Service\ItemService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->upgrade = new Upgrade($this->config, $this->service, 'news');
+ }
+
+ public function testUpgrade() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with($this->equalTo('news'), $this->equalTo('installed_version'))
+ ->will($this->returnValue('6.9.9'));
+
+ $this->service->expects($this->once())
+ ->method('generateSearchIndices');
+
+ $this->upgrade->upgrade();
+ }
+
+ public function testNoUpgrade() {
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with($this->equalTo('news'), $this->equalTo('installed_version'))
+ ->will($this->returnValue('7.0.0'));
+
+ $this->service->expects($this->never())
+ ->method('generateSearchIndices');
+
+ $this->upgrade->upgrade();
+ }
+
+}
diff --git a/upgrade/upgrade.php b/upgrade/upgrade.php
new file mode 100644
index 000000000..45fcadfad
--- /dev/null
+++ b/upgrade/upgrade.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2015
+ */
+
+namespace OCA\News\Upgrade;
+
+use OCP\IConfig;
+use OCA\News\Service\ItemService;
+
+class Upgrade {
+
+ /** @var IConfig */
+ private $config;
+
+ /** @var ItemService */
+ private $itemService;
+
+ private $appName;
+
+ /**
+ * Upgrade constructor.
+ * @param IConfig $config
+ * @param $appName
+ */
+ public function __construct(IConfig $config, ItemService $itemService,
+ $appName) {
+ $this->config = $config;
+ $this->appName = $appName;
+ $this->itemService = $itemService;
+ }
+
+ public function upgrade() {
+ $previousVersion = $this->config->getAppValue(
+ $this->appName, 'installed_version'
+ );
+
+ if (version_compare($previousVersion, '7', '<')) {
+ $this->itemService->generateSearchIndices();
+ }
+ }
+
+}