Skip to content

Commit

Permalink
Pass Db instance at construct
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Mar 21, 2023
1 parent e414c4d commit 9c7e278
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion galette/lib/Galette/Core/Install.php
Expand Up @@ -1173,7 +1173,7 @@ public function initObjects(I18n $i18n, Db $zdb, Login $login)
$this->proceedReport(_T("Mails texts"), $res);

//Install titles
$res = $titles->installInit($zdb);
$res = $titles->installInit();
$this->proceedReport(_T("Titles"), $res);

//Install PDF models
Expand Down
26 changes: 18 additions & 8 deletions galette/lib/Galette/Repository/Titles.php
Expand Up @@ -76,6 +76,18 @@ class Titles
)
);

private Db $zdb;

/**
* Default constructor
*
* @param Db $zdb Database instance
*/
public function __construct(Db $zdb)
{
$this->zdb = $zdb;
}

/**
* Get the list of all titles as an array
*
Expand Down Expand Up @@ -119,29 +131,27 @@ public static function getList(Db $zdb)
/**
* Set default titles at install time
*
* @param Db $zdb Database instance
*
* @return boolean
* @throws Throwable
*/
public function installInit(Db $zdb)
public function installInit()
{
try {
//first, we drop all values
$delete = $zdb->delete(self::TABLE);
$zdb->execute($delete);
$delete = $this->zdb->delete(self::TABLE);
$this->zdb->execute($delete);

$insert = $zdb->insert(self::TABLE);
$insert = $this->zdb->insert(self::TABLE);
$insert->values(
array(
'id_title' => ':id',
'short_label' => ':short',
'long_label' => ':long'
)
);
$stmt = $zdb->sql->prepareStatementForSqlObject($insert);
$stmt = $this->zdb->sql->prepareStatementForSqlObject($insert);

$zdb->handleSequence(
$this->zdb->handleSequence(
self::TABLE,
count(self::$defaults)
);
Expand Down
2 changes: 1 addition & 1 deletion phpunit/GaletteTestCase.php
Expand Up @@ -740,7 +740,7 @@ protected function initTitles(): void
{
$titles = new \Galette\Repository\Titles($this->zdb);
if (count($titles->getList($this->zdb)) === 0) {
$res = $titles->installInit($this->zdb);
$res = $titles->installInit();
$this->assertTrue($res);
}
}
Expand Down

0 comments on commit 9c7e278

Please sign in to comment.