Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Generate database documentation via typo3 command #1486

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
35 changes: 0 additions & 35 deletions Build/Documentation/dbdocs/generate.php

This file was deleted.

1 change: 0 additions & 1 deletion Build/Documentation/dbdocs/public/typo3

This file was deleted.

15 changes: 0 additions & 15 deletions Build/Documentation/dbdocs/public/typo3conf/LocalConfiguration.php

This file was deleted.

31 changes: 0 additions & 31 deletions Build/Documentation/dbdocs/public/typo3conf/PackageStates.php

This file was deleted.

1 change: 0 additions & 1 deletion Build/Documentation/dbdocs/public/typo3conf/ext/dlf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\DbDocs;
namespace Kitodo\Dlf\Command\DbDocs;

use Doctrine\DBAL\Schema\Table;
use Kitodo\Dlf\Common\Helper;
Expand Down Expand Up @@ -72,7 +72,7 @@ public function injectDataMapper(DataMapper $dataMapper)
/**
* @param SqlReader $sqlReader
*/
public function injectSqlReader(DataMapper $sqlReader)
public function injectSqlReader(SqlReader $sqlReader)
{
$this->sqlReader = $sqlReader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\DbDocs;
namespace Kitodo\Dlf\Command\DbDocs;

/**
* Simple utility to write .rst (reStructuredText).
Expand Down Expand Up @@ -55,7 +55,7 @@

public function subsection()
{
$section = new static();

Check failure on line 58 in Classes/Command/DbDocs/RstSection.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Unsafe usage of new static().
$this->subsections[] = $section;
return $section;
}
Expand Down
96 changes: 96 additions & 0 deletions Classes/Command/DbDocsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Command;

use Kitodo\Dlf\Common\AbstractDocument;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Command\DbDocs\Generator;
use Kitodo\Dlf\Domain\Model\Document;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

/**
* CLI Command for generating the reStructuredText file containing documentation

Check notice on line 29 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L29

Whitespace found at end of line
* about the database schema.
*
* @package TYPO3
* @subpackage dlf
*
* @access public
*/
class DbDocsCommand extends Command
{

protected Generator $generator;

public function __construct(
Generator $generator
) {

Check notice on line 44 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L44

Opening brace should be on a new line
parent::__construct();

$this->generator = $generator;

Check notice on line 47 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L47

Line indented incorrectly; expected at least 8 spaces, found 7
}

/**
* Configure the command by defining the name, options and arguments
*
* @access public
*
* @return void
*/
public function configure(): void
{
$this
->setDescription('Generate database rst file.')
->setHelp('')
->addArgument('outputPath', InputArgument::OPTIONAL, 'the path to the output rst file');
}

/**
* Executes the command to generate the documentation.
*
* @access protected
*
* @param InputInterface $input The input parameters
* @param OutputInterface $output The Symfony interface for outputs on console
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title($this->getDescription());

$outputPath = "kitodo-presentation/Documentation/Developers/Database.rst";
if ($input->getArgument('outputPath')) {
$outputPath = $input->getArgument('outputPath');
}

// $generator = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\DbDocs\Generator::class);
$tables = $this->generator->collectTables();
$page = $this->generator->generatePage($tables);
// file_put_contents($outputPath, $page->render());

file_put_contents($outputPath, $page->render());

Check warning on line 90 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L90

The use of function file_put_contents() is discouraged

Check notice on line 91 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L91

Whitespace found at end of line
$io->write("Database documentation written to output file:\n" . $outputPath . "\n");
return Command::SUCCESS;
}

}

Check notice on line 96 in Classes/Command/DbDocsCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DbDocsCommand.php#L96

The closing brace for the class must go on the next line after the body
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ services:
Kitodo\Dlf\:
resource: '../Classes/*'

Kitodo\Dlf\Command\DbDocsCommand:
tags:
- name: console.command
command: 'kitodo:dbdocs'

Kitodo\Dlf\Command\DeleteCommand:
tags:
- name: console.command
Expand Down
Loading
Loading