Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ config = {
"master",
],
"appInstallCommandPhp": "make",
"codestyle": True,
"phan": {
"multipleVersions": {
"phpVersions": [
DEFAULT_PHP_VERSION,
"7.3",
],
},
},
"codestyle": False,
"phan": False,
"phpunit": {
"allDatabases": {
"phpVersions": [
Expand Down Expand Up @@ -892,7 +885,7 @@ def phpTests(ctx, testType, withCoverage):
"mysql:8.0",
"postgres:9.4",
],
"coverage": True,
"coverage": False,
"includeKeyInMatrixName": False,
"logLevel": "2",
"cephS3": False,
Expand All @@ -918,7 +911,7 @@ def phpTests(ctx, testType, withCoverage):
"postgres:9.4",
"oracle",
],
"coverage": True,
"coverage": False,
"includeKeyInMatrixName": False,
"logLevel": "2",
"cephS3": False,
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

env:
APP_NAME: files_antivirus
PHP_VERSIONS: '["7.4"]'

jobs:
get-vars:
runs-on: ubuntu-latest
outputs:
app-name: ${{ env.APP_NAME }}
php-versions: ${{ env.PHP_VERSIONS }}
steps:
- name: Set variables
run: |
echo "App name $APP_NAME"
echo "PHP versions string: $PHP_VERSIONS"

semantic-git-messages:
name: Commits
uses: owncloud/reusable-workflows/.github/workflows/semantic-git-message.yml@main

php-code-style:
name: PHP Code Style
needs:
- get-vars
uses: owncloud/reusable-workflows/.github/workflows/php-codestyle.yml@main
with:
app-name: ${{ needs.get-vars.outputs.app-name }}
php-versions: ${{ needs.get-vars.outputs.php-versions }}
12 changes: 6 additions & 6 deletions appinfo/Migrations/Version20170808221437.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
namespace OCA\Files_Antivirus\Migrations;

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

/**
Expand All @@ -26,7 +28,7 @@ class Version20170808221437 implements ISchemaMigration {
* @param array $options
*
* @return void
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function changeSchema(Schema $schema, array $options) {
Expand All @@ -36,12 +38,10 @@ public function changeSchema(Schema $schema, array $options) {
$table = $schema->getTable("{$prefix}files_antivirus");

$fileIdColumn = $table->getColumn('fileid');
if ($fileIdColumn
/** @phan-suppress-next-line PhanDeprecatedClassConstant */
&& $fileIdColumn->getType()->getName() !== Type::BIGINT
if ($fileIdColumn // @phpstan-ignore-line
&& $fileIdColumn->getType() instanceof BigIntType
) {
/** @phan-suppress-next-line PhanDeprecatedClassConstant */
$fileIdColumn->setType(Type::getType(Type::BIGINT));
$fileIdColumn->setType(Type::getType(Types::BIGINT));
$fileIdColumn->setOptions(['length' => 20]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion appinfo/Migrations/Version20180116141548.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Version20180116141548 implements ISqlMigration {
* @param IDBConnection $connection
* @return void
*/
public function sql(IDBConnection $connection) {
public function sql(IDBConnection $connection) { // @phpstan-ignore-line
$sql = $connection->getDatabasePlatform()->getTruncateTableSQL(
"`*PREFIX*files_antivirus`"
);
Expand Down
4 changes: 2 additions & 2 deletions appinfo/Migrations/Version20180116142011.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

/**
Expand All @@ -32,7 +32,7 @@ public function changeSchema(Schema $schema, array $options) {
$table->addColumn(
'etag',
/** @phan-suppress-next-line PhanDeprecatedClassConstant */
Type::STRING,
Types::STRING,
[
'default' => null,
'length' => 40,
Expand Down
4 changes: 2 additions & 2 deletions appinfo/Migrations/Version20210212160142.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Version20210212160142 implements ISchemaMigration {
* @param array $options
*
* @return void
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function changeSchema(Schema $schema, array $options) {
Expand All @@ -40,7 +40,7 @@ public function changeSchema(Schema $schema, array $options) {
$alterQuery = $dbConn->prepare(
'ALTER TABLE `*PREFIX*files_antivirus_status` RENAME TO `*PREFIX*files_avir_status`'
);
$alterQuery->execute();
$alterQuery->executeStatement();
}
}
}
18 changes: 6 additions & 12 deletions appinfo/Migrations/Version20210413110050.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,23 @@
* Cleans table before adding etag field
*/
class Version20210413110050 implements ISqlMigration {
/**
* @param IDBConnection $connection
* @return void
*/
public function sql(IDBConnection $conn) {
$conf = \OC::$server->getConfig();
$query = 'SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = \'files_antivirus\' AND (`configkey` = \'av_path\' OR `configkey` = \'av_cmd_options\')';
$result = $conn->executeQuery($query);
/** @phan-suppress-next-line PhanDeprecatedFunction */
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
try {
$conf->setSystemValue('files_antivirus.' . $row['configkey'], $row['configvalue']);
} catch (\Exception $e) {
echo 'Migration failed: ', $e->getMessage(), '\n';
return;
return [];
}
}
/** @phan-suppress-next-line PhanDeprecatedFunction */
$result->closeCursor();
$result->free();

$query = 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = \'files_antivirus\' AND (`configkey` = \'av_path\' OR `configkey` = \'av_cmd_options\')';
$result = $conn->executeQuery($query);
/** @phan-suppress-next-line PhanDeprecatedFunction */
$result->closeCursor();
$conn->executeStatement($query);

return [];
}
}
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please note that enabling this application can impact system performance as addi
<category>security</category>
<licence>AGPL</licence>
<author>Manuel Delgado, Bart Visscher, thinksilicon.de, Viktar Dubiniuk</author>
<version>1.2.3</version>
<version>1.3.0</version>
<documentation>
<admin>https://doc.owncloud.com/server/latest/admin_manual/configuration/server/antivirus_configuration.html</admin>
</documentation>
Expand All @@ -34,7 +34,7 @@ Please note that enabling this application can impact system performance as addi
<use-migrations>true</use-migrations>
<namespace>Files_Antivirus</namespace>
<dependencies>
<owncloud min-version="10.6" max-version="10" />
<owncloud min-version="10.15" max-version="11" />
</dependencies>
<settings>
<admin>OCA\Files_Antivirus\AdminPanel</admin>
Expand Down
2 changes: 1 addition & 1 deletion lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected function propertyToKey($property) {
public function __call($methodName, $args) {
$attr = \lcfirst(\substr($methodName, 3));
$key = $this->propertyToKey($attr);
if (\strpos($methodName, 'set') === 0) {
if (\strpos($methodName, 'set') === 0) { // @phpstan-ignore-line
$this->setter($key, $args);
} elseif (\strpos($methodName, 'get') === 0) {
return $this->getter($key);
Expand Down
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function ($mountPoint, $storage) {
'requestHelper' => $requestHelper
]
);
} else {
} else { // @phpstan-ignore-line
return $storage;
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/AvirWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function file_put_contents($path, $data) {
*
* @return resource | bool
*/
public function fopen($path, $mode) {
public function fopen($path, $mode) { // @phpstan-ignore-line
$stream = $this->storage->fopen($path, $mode);

if (\is_resource($stream)
Expand Down
23 changes: 7 additions & 16 deletions lib/Controller/RuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,26 @@

use \OCP\AppFramework\Controller;
use \OCP\IRequest;
use \OCP\IL10N;
use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use \OCA\Files_Antivirus\Db\Rule;
use \OCA\Files_Antivirus\Db\RuleMapper;

class RuleController extends Controller {
private $logger;
private $l10n;
private $ruleMapper;

/**
* RuleController constructor.
*
* @param string $appName
* @param IRequest $request
* @param ILogger $logger
* @param IL10N $l10n
* @param RuleMapper $ruleMapper
*/
public function __construct(
$appName,
IRequest $request,
ILogger $logger,
IL10N $l10n,
RuleMapper $ruleMapper
) {
parent::__construct($appName, $request);
$this->logger = $logger;
$this->l10n = $l10n;
$this->ruleMapper = $ruleMapper;
}

Expand Down Expand Up @@ -97,14 +87,14 @@ public function save($id, $statusType, $match, $description, $status) {
$rule = new Rule();
}

$rule->setStatusType($statusType);
$rule->setDescription($description);
$rule->setStatus($status);
$rule->setStatusType($statusType); // @phpstan-ignore-line
$rule->setDescription($description); // @phpstan-ignore-line
$rule->setStatus($status); // @phpstan-ignore-line

if ($statusType === Rule::RULE_TYPE_CODE) {
$rule->setResult($match);
$rule->setResult($match); // @phpstan-ignore-line
} else {
$rule->setMatch($match);
$rule->setMatch($match); // @phpstan-ignore-line
}

if ($id) {
Expand All @@ -127,9 +117,10 @@ public function delete($id) {
try {
$rule = $this->ruleMapper->find($id);
$this->ruleMapper->delete($rule);
return new JSONResponse($rule);
} catch (\Exception $e) {
//TODO: Handle
}
return new JSONResponse($rule);
return new JSONResponse([]);
}
}
9 changes: 4 additions & 5 deletions lib/Cron/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ protected function run($argument = '') {
}

$cnt = 0;
/** @phan-suppress-next-line PhanDeprecatedFunction */
while (($row = $result->fetch()) && $cnt < self::BATCH_SIZE) {
while (($row = $result->fetchAssociative()) && $cnt < self::BATCH_SIZE) {
try {
$fileId = $row['fileid'];
$userId = $row['user_id'];
Expand All @@ -150,10 +149,10 @@ protected function run($argument = '') {
}

/**
* @return \Doctrine\DBAL\Driver\Statement|int
* @return \Doctrine\DBAL\Result
*/
protected function getFilesForScan() {
$fileSizeLimit = \intval($this->appConfig->getAvMaxFileSize());
$fileSizeLimit = $this->appConfig->getAvMaxFileSize();
return $this->fileCollection->getCollection($fileSizeLimit);
}

Expand Down Expand Up @@ -182,7 +181,7 @@ protected function scanOneFile($owner, $fileId, $etag) {
$status->dispatch($item, true);
return true;
}
return false;
return false; // @phpstan-ignore-line
}

/**
Expand Down
11 changes: 6 additions & 5 deletions lib/Db/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace OCA\Files_Antivirus\Db;

use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OCP\IDBConnection;
use OCP\Files\IMimeTypeLoader;

Expand All @@ -38,14 +38,14 @@ public function __construct(IDBConnection $dbConnection, IMimeTypeLoader $mimeTy
/**
* @param int $fileSizeLimit
*
* @return \Doctrine\DBAL\Driver\Statement|int
* @return \Doctrine\DBAL\Result
*/
public function getCollection($fileSizeLimit) {
$dirMimeTypeId = $this->mimeTypeLoader->getId(
'httpd/unix-directory'
);
$qb = $this->dbConnection->getQueryBuilder();
if ($this->dbConnection->getDatabasePlatform() instanceof MySqlPlatform) {
if ($this->dbConnection->getDatabasePlatform() instanceof MySQLPlatform) {
$concatFunction = $qb->createFunction(
"CONCAT('/', mnt.user_id, '/')"
);
Expand All @@ -58,6 +58,7 @@ public function getCollection($fileSizeLimit) {
if ($fileSizeLimit === -1) {
$sizeLimitExpr = $qb->expr()->neq('fc.size', $qb->expr()->literal('0'));
} else {
// @phpstan-ignore-next-line
$sizeLimitExpr = $qb->expr()->andX(
$qb->expr()->neq('fc.size', $qb->expr()->literal('0')),
$qb->expr()->lt('fc.size', $qb->expr()->literal((string) $fileSizeLimit))
Expand All @@ -77,7 +78,7 @@ public function getCollection($fileSizeLimit) {
'mounts',
'mnt',
/** @phan-suppress-next-line PhanTypeMismatchArgument */
$qb->expr()->andX(
$qb->expr()->andX( // @phpstan-ignore-line
$qb->expr()->eq('fc.storage', 'mnt.storage_id'),
$qb->expr()->eq('mnt.mount_point', $concatFunction)
)
Expand All @@ -86,7 +87,7 @@ public function getCollection($fileSizeLimit) {
$qb->expr()->neq('fc.mimetype', $qb->expr()->literal($dirMimeTypeId))
)
->andWhere(
$qb->expr()->orX(
$qb->expr()->orX( // @phpstan-ignore-line
$qb->expr()->isNull('fa.etag'),
$qb->expr()->neq('fc.etag', 'fa.etag')
)
Expand Down
Loading