From 6f48a74ead80c57e291ca2be78645449e99ae5f0 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 26 Nov 2015 19:51:29 +0100 Subject: add autoupdate for indices --- CHANGELOG.md | 4 +- appinfo/register_command.php | 21 ------- appinfo/update.php | 17 ++++++ command/migrate.php | 48 ---------------- command/verifyinstall.php | 80 --------------------------- controller/admincontroller.php | 8 --- db/item.php | 1 + service/itemservice.php | 17 +----- templates/admin.php | 13 ----- tests/integration/command/CommandTest.php | 34 ------------ tests/unit/controller/AdminControllerTest.php | 7 --- tests/unit/upgrade/UpgradeTest.php | 63 +++++++++++++++++++++ upgrade/upgrade.php | 49 ++++++++++++++++ 13 files changed, 132 insertions(+), 230 deletions(-) delete mode 100644 appinfo/register_command.php create mode 100644 appinfo/update.php delete mode 100644 command/migrate.php delete mode 100644 command/verifyinstall.php delete mode 100644 tests/integration/command/CommandTest.php create mode 100644 tests/unit/upgrade/UpgradeTest.php create mode 100644 upgrade/upgrade.php 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 @@ - - * @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 @@ + + * @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 @@ - - * @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 @@ - - * @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('Missing file: ' . $path); - } - foreach ($errors as $path) { - $output->writeln('Invalid checksum: ' . $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('Installation verified, everything OK!' . - ''); - } - } - -} 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');

-
-

- -

-

t('Migrates existing data after updating from versions prior to 7.0.0')); ?>

-

t( - 'This takes about 1 minute per user. For bigger installations use ' . - 'this console command to prevent timeouts:')); ?> php -f owncloud/occ news:migrate -

-

-
t('Saved')); ?>
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 @@ - - * @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 @@ +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 @@ + + * @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(); + } + } + +} -- cgit v1.2.3