2015-08-16 15:49:45 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-08-16 15:49:45 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\App\CodeChecker;
|
|
|
|
|
|
|
|
use OC\App\InfoParser;
|
|
|
|
use OC\Hooks\BasicEmitter;
|
|
|
|
|
|
|
|
class InfoChecker extends BasicEmitter {
|
|
|
|
|
|
|
|
/** @var InfoParser */
|
|
|
|
private $infoParser;
|
|
|
|
|
|
|
|
private $mandatoryFields = [
|
|
|
|
'author',
|
|
|
|
'description',
|
2017-05-22 07:54:44 +00:00
|
|
|
'dependencies',
|
2015-08-16 15:49:45 +00:00
|
|
|
'id',
|
|
|
|
'licence',
|
|
|
|
'name',
|
2017-05-22 07:54:44 +00:00
|
|
|
'version',
|
2015-08-16 15:49:45 +00:00
|
|
|
];
|
|
|
|
private $optionalFields = [
|
|
|
|
'bugs',
|
|
|
|
'category',
|
2015-09-24 14:47:00 +00:00
|
|
|
'default_enable',
|
2015-08-16 15:49:45 +00:00
|
|
|
'documentation',
|
|
|
|
'namespace',
|
|
|
|
'ocsid',
|
2015-09-24 14:47:00 +00:00
|
|
|
'public',
|
|
|
|
'remote',
|
2015-08-16 15:49:45 +00:00
|
|
|
'repository',
|
|
|
|
'types',
|
|
|
|
'website',
|
|
|
|
];
|
|
|
|
private $deprecatedFields = [
|
2015-09-24 10:48:44 +00:00
|
|
|
'info',
|
2016-02-11 10:25:50 +00:00
|
|
|
'require',
|
|
|
|
'requiremax',
|
|
|
|
'requiremin',
|
2015-08-16 15:49:45 +00:00
|
|
|
'shipped',
|
|
|
|
'standalone',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct(InfoParser $infoParser) {
|
|
|
|
$this->infoParser = $infoParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appId
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function analyse($appId) {
|
|
|
|
$appPath = \OC_App::getAppPath($appId);
|
|
|
|
if ($appPath === false) {
|
|
|
|
throw new \RuntimeException("No app with given id <$appId> known.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors = [];
|
|
|
|
|
|
|
|
$info = $this->infoParser->parse($appPath . '/appinfo/info.xml');
|
|
|
|
|
2017-05-22 07:54:44 +00:00
|
|
|
if (!isset($info['dependencies']['nextcloud']['@attributes']['min-version'])) {
|
2015-11-09 10:10:37 +00:00
|
|
|
$errors[] = [
|
2017-05-22 07:54:44 +00:00
|
|
|
'type' => 'missingRequirement',
|
2015-11-09 10:10:37 +00:00
|
|
|
'field' => 'min',
|
|
|
|
];
|
2016-01-07 14:04:36 +00:00
|
|
|
$this->emit('InfoChecker', 'missingRequirement', ['min']);
|
2015-11-09 10:10:37 +00:00
|
|
|
}
|
2016-01-07 14:04:36 +00:00
|
|
|
|
2017-05-22 07:54:44 +00:00
|
|
|
if (!isset($info['dependencies']['nextcloud']['@attributes']['max-version'])) {
|
2015-11-09 10:10:37 +00:00
|
|
|
$errors[] = [
|
2017-05-22 07:54:44 +00:00
|
|
|
'type' => 'missingRequirement',
|
2015-11-09 10:10:37 +00:00
|
|
|
'field' => 'max',
|
|
|
|
];
|
2016-01-07 14:04:36 +00:00
|
|
|
$this->emit('InfoChecker', 'missingRequirement', ['max']);
|
2015-11-09 10:10:37 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 15:49:45 +00:00
|
|
|
foreach ($info as $key => $value) {
|
2015-09-24 10:48:44 +00:00
|
|
|
if(is_array($value)) {
|
|
|
|
$value = json_encode($value);
|
|
|
|
}
|
2015-08-16 15:49:45 +00:00
|
|
|
if (in_array($key, $this->mandatoryFields)) {
|
|
|
|
$this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($key, $this->optionalFields)) {
|
|
|
|
$this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($key, $this->deprecatedFields)) {
|
|
|
|
// skip empty arrays - empty arrays for remote and public are always added
|
2015-09-24 10:48:44 +00:00
|
|
|
if($value === '[]' && in_array($key, ['public', 'remote', 'info'])) {
|
2015-08-16 15:49:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->mandatoryFields as $key) {
|
|
|
|
if(!isset($info[$key])) {
|
|
|
|
$this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]);
|
|
|
|
$errors[] = [
|
|
|
|
'type' => 'mandatoryFieldMissing',
|
|
|
|
'field' => $key,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$versionFile = $appPath . '/appinfo/version';
|
|
|
|
if (is_file($versionFile)) {
|
|
|
|
$version = trim(file_get_contents($versionFile));
|
2017-05-22 07:54:44 +00:00
|
|
|
$this->emit('InfoChecker', 'migrateVersion', [$version]);
|
2015-08-16 15:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
}
|