Skip to content

Commit e53a414

Browse files
committed
added an option to generate the daos from lock file
1 parent 3ed959d commit e53a414

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/Commands/GenerateCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TheCodingMachine\TDBM\Commands;
55

6+
use Symfony\Component\Console\Input\InputOption;
67
use TheCodingMachine\TDBM\ConfigurationInterface;
78
use TheCodingMachine\TDBM\TDBMService;
89
use Mouf\Utils\Log\Psr\MultiLogger;
@@ -30,6 +31,9 @@ protected function configure()
3031
$this->setName('tdbm:generate')
3132
->setDescription('Generates DAOs and beans.')
3233
->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
34+
->addOption(
35+
'from-lock',null,InputOption::VALUE_OPTIONAL, 'Load the schema from the lock file instead of database',false
36+
);
3337
;
3438
}
3539

@@ -39,6 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3943

4044
$alteredConf = new AlteredConfiguration($this->configuration);
4145

46+
$fromLock = (bool) $input->getOption('from-lock');
4247

4348
$loggers = [ new ConsoleLogger($output) ];
4449

@@ -54,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5459
$multiLogger->notice('Starting regenerating DAOs and beans');
5560

5661
$tdbmService = new TDBMService($this->configuration);
57-
$tdbmService->generateAllDaosAndBeans();
62+
$tdbmService->generateAllDaosAndBeans($fromLock);
5863

5964
$multiLogger->notice('Finished regenerating DAOs and beans');
6065
}

src/TDBMSchemaAnalyzer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function getCachePrefix(): string
7878
return $this->cachePrefix;
7979
}
8080

81+
//todo: in config
8182
public static function getLockFilePath(): string
8283
{
8384
return RootProjectLocator::getRootLocationPath().self::schemaFileName;

src/TDBMService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,15 @@ public function _addToToSaveObjectList(DbRow $myObject): void
527527
/**
528528
* Generates all the daos and beans.
529529
*/
530-
public function generateAllDaosAndBeans() : void
530+
public function generateAllDaosAndBeans(bool $fromLock = false) : void
531531
{
532532
// Purge cache before generating anything.
533533
if ($this->cache instanceof ClearableCache) {
534534
$this->cache->deleteAll();
535535
}
536536

537537
$tdbmDaoGenerator = new TDBMDaoGenerator($this->configuration, $this->tdbmSchemaAnalyzer);
538-
$tdbmDaoGenerator->generateAllDaosAndBeans();
538+
$tdbmDaoGenerator->generateAllDaosAndBeans($fromLock);
539539
}
540540

541541
/**

src/Utils/TDBMDaoGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ public function __construct(ConfigurationInterface $configuration, TDBMSchemaAna
7171
*
7272
* @throws TDBMException
7373
*/
74-
public function generateAllDaosAndBeans(): void
74+
public function generateAllDaosAndBeans(bool $fromLock = false): void
7575
{
76-
$this->tdbmSchemaAnalyzer->generateLockFile();
76+
if (!$fromLock) {
77+
$this->tdbmSchemaAnalyzer->generateLockFile();
78+
}
7779
$schema = $this->tdbmSchemaAnalyzer->getSchema();
7880

7981
// TODO: check that no class name ends with "Base". Otherwise, there will be name clash.

0 commit comments

Comments
 (0)