Skip to content

Commit

Permalink
Revert "Add option to only validate the schemas"
Browse files Browse the repository at this point in the history
This reverts commit d7f2a53.
  • Loading branch information
caendesilva committed Jan 18, 2023
1 parent 8ec0267 commit dee1660
Showing 1 changed file with 1 addition and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

namespace Hyde\Publications\Commands;

use Hyde\Hyde;
use function basename;
use function collect;
use Exception;
use function filled;
use function glob;
use Hyde\Hyde;
use Hyde\Publications\Actions\ValidatesPublicationField;
use Hyde\Publications\Models\PublicationFieldDefinition;
use Hyde\Publications\Models\PublicationPage;
Expand Down Expand Up @@ -39,8 +35,7 @@ class ValidatePublicationsCommand extends ValidatingCommand
/** @var string */
protected $signature = 'validate:publications
{publicationType? : The name of the publication type to validate.}
{--json : Display results as JSON.}
{--schemas : Only validate the publication schema files.}';
{--json : Display results as JSON.}';

/** @var string */
protected $description = 'Validate all or the specified publication type(s)';
Expand All @@ -66,18 +61,6 @@ public function safeHandle(): int
$this->title('Validating publications!');
}

if ($this->option('schemas')) {
$this->validateSchemaFiles();

$this->newLine();
$this->info(sprintf('All done in %sms using %sMB peak memory!',
round((microtime(true) - $timeStart) * 1000),
round(memory_get_peak_usage() / 1024 / 1024)
));

return Command::SUCCESS;
}

$publicationTypesToValidate = $this->getPublicationTypesToValidate();

foreach ($publicationTypesToValidate as $publicationType) {
Expand Down Expand Up @@ -266,30 +249,4 @@ protected function outputJson(): void
{
$this->output->writeln(json_encode($this->results, JSON_PRETTY_PRINT));
}

protected function validateSchemaFiles(): void
{
/** @see PublicationService::getSchemaFiles() */
$schemaFiles = glob(Hyde::path(Hyde::getSourceRoot()).'/*/schema.json');

foreach ($schemaFiles as $number => $schemaFile) {
$name = basename(dirname($schemaFile));
$this->infoComment('Validating schema file for', $name);

$errors = PublicationService::validateSchemaFile($schemaFile, false);

if (empty($errors['schema'])) {
$this->line('<info> No top-level schema errors found</info>');
} else {
$this->line(sprintf(" <fg=red>Found %s errors:</>", count($errors['schema'])));
foreach ($errors['schema'] as $error) {
$this->line(sprintf(' <fg=red>%s</> <comment>%s</comment>', self::CROSS_MARK, implode(' ', $error)));
}
}

if ($number !== count($schemaFiles) - 1) {
$this->newLine();
}
}
}
}

0 comments on commit dee1660

Please sign in to comment.