Skip to content

Commit

Permalink
Work on composer scripts for install/update/remove module
Browse files Browse the repository at this point in the history
  • Loading branch information
voltan committed Mar 20, 2022
1 parent ab3c37b commit 785b0be
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
10 changes: 2 additions & 8 deletions bin/post-install.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Laminas\Config\Config;
use Laminas\Db\Adapter\Adapter;
use User\Installer\Install;
Expand All @@ -19,7 +15,5 @@
$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php'));
$adapter = new Adapter($config->db->toArray());
$install = new Install($adapter);
$result['init'] = $install->database();
$result['config'] = $install->config();

var_dump($result);
echo $install->database();
echo $install->config();
14 changes: 8 additions & 6 deletions bin/post-remove.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

use Laminas\Config\Config;
use Laminas\Db\Adapter\Adapter;
use User\Installer\Remove;

// Composer autoloading
include __DIR__ . '/../../../vendor/autoload.php';
include realpath(__DIR__ . '/../../../vendor/autoload.php');

$result = [
'init' => false,
'config' => false,
];

$install = new Remove();
$result['init'] = $install->init();
$result['config'] = $install->manageConfig();

var_dump($result);
$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php'));
$adapter = new Adapter($config->db->toArray());
$install = new Remove($adapter);
echo $install->database();
echo $install->config();
14 changes: 8 additions & 6 deletions bin/post-update.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

use Laminas\Config\Config;
use Laminas\Db\Adapter\Adapter;
use User\Installer\Update;

// Composer autoloading
include __DIR__ . '/../../../vendor/autoload.php';
include realpath(__DIR__ . '/../../../vendor/autoload.php');

$result = [
'init' => false,
'config' => false,
];

$install = new Update();
$result['init'] = $install->init();
$result['config'] = $install->manageConfig();

var_dump($result);
$config = new Config(include realpath(__DIR__ . '/../../../config/autoload/global.php'));
$adapter = new Adapter($config->db->toArray());
$install = new Update($adapter);
echo $install->database();
echo $install->config();
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
],
"post-update-cmd": [
"php -r 'if (file_exists(\"bin/post-update.php\")) include \"bin/post-update.php\";'"
],
"post-package-uninstall": [
"php -r 'if (file_exists(\"bin/post-remove.php\")) include \"bin/post-remove.php\";'"
]
},

Expand Down
12 changes: 6 additions & 6 deletions src/Installer/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public function __construct(
$this->db = $db;
}

public function database($version = ''): bool
public function database($version = ''): string
{
// Set and check
$sqlFile = realpath(__DIR__ . '/../../data/schema.sql');
if (!file_exists($sqlFile)) {
return false;
return 'Error to find or read schema.sql';

}

// read query
$sql = file_get_contents($sqlFile);
$sql = file_get_contents($sqlFile);
$statement = $this->db->createStatement($sql);
$statement->execute();
return true;
return 'User module database install successfully !';
}

public function config($file = ''): bool
public function config($file = ''): string
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Installer/InstallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface InstallerInterface
{
public function database($version = ''): bool;
public function database($version = ''): string;

public function config($file = ''): bool;
public function config($file = ''): string;
}
4 changes: 2 additions & 2 deletions src/Installer/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public function __construct(
$this->db = $db;
}

public function database($version = ''): bool
public function database($version = ''): string
{
return true;
}

public function config($file = ''): bool
public function config($file = ''): string
{
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Installer/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public function __construct(
$this->db = $db;
}

public function database($version = ''): bool
public function database($version = ''): string
{
return true;
return 'User module database update successfully !';
}

public function config($file = ''): bool
public function config($file = ''): string
{
return true;
}
Expand Down

0 comments on commit 785b0be

Please sign in to comment.