Skip to content

Commit

Permalink
Merge pull request #170 from owncloud/stable10-migrations
Browse files Browse the repository at this point in the history
Stable10 migrations
  • Loading branch information
Vincent Petry authored Aug 16, 2017
2 parents 36ab920 + 245fa1c commit 0b967ac
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ php:

env:
global:
- CORE_BRANCH=master
- CORE_BRANCH=stable10
- APP_NAME=files_antivirus
matrix:
- DB=sqlite
Expand Down
75 changes: 75 additions & 0 deletions appinfo/Migrations/Version20170808220321.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace OCA\Files_Antivirus\Migrations;
use Doctrine\DBAL\Schema\Schema;
use OCP\Migration\ISchemaMigration;

/** Creates initial schema */
class Version20170808220321 implements ISchemaMigration {
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];
if (!$schema->hasTable("{$prefix}files_antivirus")) {
$table = $schema->createTable("{$prefix}files_antivirus");
$table->addColumn('fileid', 'bigint', [
'unsigned' => true,
'notnull' => true,
'length' => 11,
]);

$table->addColumn('check_time', 'integer', [
'notnull' => true,
'unsigned' => true,
'default' => 0,
]);
$table->setPrimaryKey(['fileid']);
}

if (!$schema->hasTable("{$prefix}files_avir_status")) {
$table = $schema->createTable("{$prefix}files_avir_status");
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'unsigned' => true,
'notnull' => true,
'length' => 11,
]);

$table->addColumn('group_id', 'integer', [
'notnull' => true,
'unsigned' => true,
'default' => 0,
]);

$table->addColumn('status_type', 'integer', [
'notnull' => true,
'unsigned' => true,
'default' => 0,
]);

$table->addColumn('result', 'integer', [
'notnull' => true,
'unsigned' => false,
'default' => 0,
]);

$table->addColumn('match', 'string', [
'length' => 64,
'notnull' => false,
'default' => null,
]);

$table->addColumn('description', 'string', [
'length' => 64,
'notnull' => false,
'default' => null,
]);

$table->addColumn('status', 'integer', [
'length' => 4,
'notnull' => true,
'default' => 0,
'unsigned' => false,
]);
$table->setPrimaryKey(['id']);
}
}
}
24 changes: 24 additions & 0 deletions appinfo/Migrations/Version20170808221437.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace OCA\Files_Antivirus\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use OCP\Migration\ISchemaMigration;

/** Updates some fields to bigint if required */
class Version20170808221437 implements ISchemaMigration {
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];

if ($schema->hasTable("${prefix}files_antivirus")) {
$table = $schema->getTable("{$prefix}files_antivirus");

$fileIdColumn = $table->getColumn('fileid');
if ($fileIdColumn && $fileIdColumn->getType()->getName() !== Type::BIGINT) {
$fileIdColumn->setType(Type::getType(Type::BIGINT));
$fileIdColumn->setOptions(['length' => 20]);
}
}
}
}
22 changes: 22 additions & 0 deletions appinfo/Migrations/Version20170808222334.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace OCA\Files_Antivirus\Migrations;
use OCA\Files_Antivirus\Db\RuleMapper;
use OCP\Migration\IOutput;
use OCP\Migration\ISimpleMigration;

/** Populate statuses */
class Version20170808222334 implements ISimpleMigration {
private $ruleMapper;

public function __construct(RuleMapper $ruleMapper){
$this->ruleMapper = $ruleMapper;
}

public function run(IOutput $out) {
$rules = $this->ruleMapper->findAll();
if (!count($rules)) {
$this->ruleMapper->populate();
}
}
}
5 changes: 2 additions & 3 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function __construct (array $urlParams = array()) {
$c->getServer()->getRootFolder(),
$c->getServer()->getUserSession()
);
});
});

$container->registerService('RuleMapper', function($c) {
$container->registerService('RuleMapper', function($c) {
return new RuleMapper(
$c->query('ServerContainer')->getDb()
);
Expand All @@ -81,7 +81,6 @@ public function __construct (array $urlParams = array()) {
$container->registerService('L10N', function($c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});

}

/**
Expand Down
110 changes: 0 additions & 110 deletions appinfo/database.xml

This file was deleted.

5 changes: 3 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ For this app to be effective, the ClamAV virus definitions should be kept up to
<repository type="git">http://github.com/owncloud/files_antivirus.git</repository>
<licence>AGPL</licence>
<author>Manuel Delgado, Bart Visscher, thinksilicon.de, Victor Dubiniuk</author>
<version>0.10.0.2</version>
<version>0.10.1.0</version>
<types>
<filesystem/>
</types>
<use-migrations>true</use-migrations>
<dependencies>
<owncloud min-version="10.0" max-version="10.0" />
<owncloud min-version="10.0.3" max-version="10.0" />
</dependencies>
<ocsid>157439</ocsid>
<settings>
Expand Down
7 changes: 0 additions & 7 deletions appinfo/install.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?php

$app = new \OCA\Files_Antivirus\AppInfo\Application();
$ruleMapper = $app->getContainer()->query('RuleMapper');
$rules = $ruleMapper->findAll();
if(!count($rules)) {
$ruleMapper->populate();
}

\OC::$server->getConfig()->setAppValue('files_antivirus', 'av_path', '/usr/bin/clamscan');
\OC::$server->getJobList()->add('OCA\Files_Antivirus\Cron\Task');

0 comments on commit 0b967ac

Please sign in to comment.