Fixed installer errors

This commit is contained in:
Sergio Brighenti 2020-04-05 14:53:22 +02:00
parent 7e9d43ec71
commit a253234bd4
14 changed files with 56 additions and 77 deletions

View file

@ -73,6 +73,6 @@ class TagController extends Controller
return make(ValidationHelper::class) return make(ValidationHelper::class)
->failIf(empty(param($request, 'mediaId'))) ->failIf(empty(param($request, 'mediaId')))
->failIf($this->database->query('SELECT COUNT(*) AS `count` FROM `uploads` WHERE `id` = ?', param($request, 'mediaId'))->fetch()->count == 0) ->failIf($this->database->query('SELECT COUNT(*) AS `count` FROM `uploads` WHERE `id` = ?', param($request, 'mediaId'))->fetch()->count == 0)
->failIf($this->session->get('admin', false) || $this->database->query('SELECT * FROM `uploads` WHERE `id` = ? LIMIT 1', param($request, 'mediaId'))->fetch()->user_id !== $this->session->get('user_id')); ->failIf(!$this->session->get('admin', false) && $this->database->query('SELECT `user_id` FROM `uploads` WHERE `id` = ? LIMIT 1', param($request, 'mediaId'))->fetch()->user_id != $this->session->get('user_id'));
} }
} }

View file

@ -16,23 +16,17 @@ class Migrator
* @var string * @var string
*/ */
private $schemaPath; private $schemaPath;
/**
* @var bool
*/
private $firstMigrate;
/** /**
* Migrator constructor. * Migrator constructor.
* *
* @param DB $db * @param DB $db
* @param string $schemaPath * @param string $schemaPath
* @param bool $firstMigrate
*/ */
public function __construct(DB $db, ?string $schemaPath, bool $firstMigrate = false) public function __construct(DB $db, ?string $schemaPath)
{ {
$this->db = $db; $this->db = $db;
$this->schemaPath = $schemaPath; $this->schemaPath = $schemaPath;
$this->firstMigrate = $firstMigrate;
} }
public function migrate() public function migrate()
@ -43,9 +37,7 @@ class Migrator
$this->firstMigrate = true; $this->firstMigrate = true;
} }
if ($this->firstMigrate) { $this->db->getPdo()->exec(file_get_contents($this->schemaPath.DIRECTORY_SEPARATOR.'migrations.sql'));
$this->db->getPdo()->exec(file_get_contents($this->schemaPath.DIRECTORY_SEPARATOR.'migrations.sql'));
}
$files = glob($this->schemaPath.'/'.$this->db->getCurrentDriver().'/*.sql'); $files = glob($this->schemaPath.'/'.$this->db->getCurrentDriver().'/*.sql');

View file

@ -464,14 +464,11 @@ if (!function_exists('dsnFromConfig')) {
* *
* @param array $config * @param array $config
* *
* @param string $baseDir
* @return string * @return string
*/ */
function dsnFromConfig(array $config, $baseDir = BASE_DIR): string function dsnFromConfig(array $config): string
{ {
$dsn = $config['db']['connection'] === 'sqlite' ? $baseDir.$config['db']['dsn'] : $config['db']['dsn']; return $config['db']['connection'].':'.$config['db']['dsn'];
return $config['db']['connection'].':'.$dsn;
} }
} }

View file

@ -18,15 +18,9 @@ if (!$config) {
chdir(__DIR__.'/../'); chdir(__DIR__.'/../');
$firstMigrate = false; $db = new DB(dsnFromConfig($config), $config['db']['username'], $config['db']['password']);
if ($config['db']['connection'] === 'sqlite' && !file_exists(__DIR__.'/../'.$config['db']['dsn'])) {
touch(__DIR__.'/../'.$config['db']['dsn']);
$firstMigrate = true;
}
$db = new DB(dsnFromConfig($config, getcwd().DIRECTORY_SEPARATOR), $config['db']['username'], $config['db']['password']); $migrator = new Migrator($db, 'resources/schemas');
$migrator = new Migrator($db, 'resources/schemas', $firstMigrate);
$migrator->migrate(); $migrator->migrate();
if (isset($argv[1]) && $argv[1] === '--install') { if (isset($argv[1]) && $argv[1] === '--install') {
@ -34,7 +28,7 @@ if (isset($argv[1]) && $argv[1] === '--install') {
} }
if (file_exists(__DIR__.'/../install') && (!isset($config['debug']) || !$config['debug'])) { if (file_exists(__DIR__.'/../install') && (!isset($config['debug']) || !$config['debug'])) {
removeDirectory(__DIR__.'/../install'); //removeDirectory(__DIR__.'/../install');
} }
echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL; echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL;

View file

@ -6,6 +6,7 @@ use App\Factories\ViewFactory;
use App\Middleware\InjectMiddleware; use App\Middleware\InjectMiddleware;
use App\Middleware\LangMiddleware; use App\Middleware\LangMiddleware;
use App\Middleware\RememberMiddleware; use App\Middleware\RememberMiddleware;
use App\Web\Session;
use App\Web\View; use App\Web\View;
use DI\Bridge\Slim\Bridge; use DI\Bridge\Slim\Bridge;
use DI\ContainerBuilder; use DI\ContainerBuilder;
@ -58,6 +59,10 @@ if (!$config['debug']) {
} }
$builder->addDefinitions([ $builder->addDefinitions([
Session::class => factory(function () {
return new Session('xbackbone_session', BASE_DIR.'resources/sessions');
}),
'session' => get(Session::class),
View::class => factory(function (Container $container) { View::class => factory(function (Container $container) {
return ViewFactory::createAppInstance($container); return ViewFactory::createAppInstance($container);
}), }),

View file

@ -36,11 +36,6 @@ return [
}), }),
'logger' => get(Logger::class), 'logger' => get(Logger::class),
Session::class => factory(function () {
return new Session('xbackbone_session', BASE_DIR.'resources/sessions');
}),
'session' => get(Session::class),
DB::class => factory(function (Container $container) { DB::class => factory(function (Container $container) {
$config = $container->get('config'); $config = $container->get('config');

View file

@ -1,6 +1,6 @@
{ {
"name": "sergix44/xbackbone", "name": "sergix44/xbackbone",
"version": "3.1", "version": "3.1.RC1",
"description": "A lightweight ShareX PHP backend", "description": "A lightweight ShareX PHP backend",
"type": "project", "type": "project",
"require": { "require": {
@ -21,8 +21,7 @@
"slim/slim": "^4.0", "slim/slim": "^4.0",
"spatie/flysystem-dropbox": "^1.0", "spatie/flysystem-dropbox": "^1.0",
"superbalist/flysystem-google-storage": "^7.2", "superbalist/flysystem-google-storage": "^7.2",
"twig/twig": "^2.12", "twig/twig": "^2.12"
"ext-ldap": "*"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,

23
composer.lock generated
View file

@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "17be54724e0928ed7049b18bbcb181b9", "content-hash": "979e04cb72a48a50d7872132f8efa29f",
"packages": [ "packages": [
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.133.46", "version": "3.134.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "98d359e61b365f3040ca61c66ae8883334cf5d74" "reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/98d359e61b365f3040ca61c66ae8883334cf5d74", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3de2711a47e7c3f5e93a5c83f019188fd23f852f",
"reference": "98d359e61b365f3040ca61c66ae8883334cf5d74", "reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -88,7 +88,7 @@
"s3", "s3",
"sdk" "sdk"
], ],
"time": "2020-03-27T18:15:32+00:00" "time": "2020-04-03T18:11:51+00:00"
}, },
{ {
"name": "firebase/php-jwt", "name": "firebase/php-jwt",
@ -255,16 +255,16 @@
}, },
{ {
"name": "google/cloud-storage", "name": "google/cloud-storage",
"version": "v1.19.0", "version": "v1.20.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/googleapis/google-cloud-php-storage.git", "url": "https://github.com/googleapis/google-cloud-php-storage.git",
"reference": "49dc19608ebea54023c2b3910e72b91393235d82" "reference": "d09ef3d47079e4a3cac1419856302cc5c07c5e1f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/49dc19608ebea54023c2b3910e72b91393235d82", "url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/d09ef3d47079e4a3cac1419856302cc5c07c5e1f",
"reference": "49dc19608ebea54023c2b3910e72b91393235d82", "reference": "d09ef3d47079e4a3cac1419856302cc5c07c5e1f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -302,7 +302,7 @@
"Apache-2.0" "Apache-2.0"
], ],
"description": "Cloud Storage Client for PHP", "description": "Cloud Storage Client for PHP",
"time": "2020-03-25T23:00:37+00:00" "time": "2020-03-30T20:36:58+00:00"
}, },
{ {
"name": "google/crc32", "name": "google/crc32",
@ -765,6 +765,7 @@
"serialize", "serialize",
"tokenizer" "tokenizer"
], ],
"abandoned": "opis/closure",
"time": "2018-03-21T22:21:57+00:00" "time": "2018-03-21T22:21:57+00:00"
}, },
{ {

View file

@ -4,7 +4,7 @@ return [
'base_url' => 'https://localhost', // no trailing slash 'base_url' => 'https://localhost', // no trailing slash
'db' => [ 'db' => [
'connection' => 'sqlite', 'connection' => 'sqlite',
'dsn' => 'resources/database/xbackbone.db', 'dsn' => realpath(__DIR__).'/resources/database/xbackbone.db',
'username' => null, 'username' => null,
'password' => null, 'password' => null,
], ],

View file

@ -44,7 +44,7 @@ return [
], ],
'db' => [ 'db' => [
'connection' => 'sqlite', // current support for sqlite and mysql 'connection' => 'sqlite', // current support for sqlite and mysql
'dsn' => 'resources/database/xbackbone.db', 'dsn' => realpath(__DIR__).'/resources/database/xbackbone.db', // if sqlite, this must be an absolute path
'username' => null, // username and password not needed for sqlite 'username' => null, // username and password not needed for sqlite
'password' => null, 'password' => null,
] ]

View file

@ -29,7 +29,7 @@ $config = [
'debug' => true, 'debug' => true,
'db' => [ 'db' => [
'connection' => 'sqlite', 'connection' => 'sqlite',
'dsn' => realpath(__DIR__.'/../').implode(DIRECTORY_SEPARATOR, ['resources', 'database', 'xbackbone.db']), 'dsn' => realpath(__DIR__.'/../').DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, ['resources', 'database', 'xbackbone.db']),
'username' => null, 'username' => null,
'password' => null, 'password' => null,
], ],
@ -51,6 +51,10 @@ $builder->addDefinitions([
return ViewFactory::createInstallerInstance($container); return ViewFactory::createInstallerInstance($container);
}), }),
'view' => get(View::class), 'view' => get(View::class),
Session::class => factory(function () {
return new Session('xbackbone_session');
}),
'session' => get(Session::class),
]); ]);
$builder->addDefinitions(__DIR__.'/../bootstrap/container.php'); $builder->addDefinitions(__DIR__.'/../bootstrap/container.php');
@ -95,7 +99,6 @@ $app->get('/', function (Response $response, View $view, Session $session) use (
})->setName('install'); })->setName('install');
$app->post('/', function (Request $request, Response $response, Filesystem $storage, Session $session, DB $db) use (&$config) { $app->post('/', function (Request $request, Response $response, Filesystem $storage, Session $session, DB $db) use (&$config) {
// Check if there is a previous installation, if not, setup the config file // Check if there is a previous installation, if not, setup the config file
$installed = true; $installed = true;
@ -180,13 +183,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
// Build the dns string and run the migrations // Build the dns string and run the migrations
try { try {
$firstMigrate = false; $migrator = new Migrator($db, __DIR__.'/../resources/schemas');
if ($config['db']['connection'] === 'sqlite' && !file_exists(__DIR__.'/../'.$config['db']['dsn'])) {
touch(__DIR__.'/../'.$config['db']['dsn']);
$firstMigrate = true;
}
$migrator = new Migrator($db, __DIR__.'/../resources/schemas', $firstMigrate);
$migrator->migrate(); $migrator->migrate();
$migrator->reSyncQuotas($storage); $migrator->reSyncQuotas($storage);
} catch (PDOException $e) { } catch (PDOException $e) {
@ -201,7 +198,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
} }
// re-apply the previous theme if is present // re-apply the previous theme if is present
$css = $db->query('SELECT `value` FROM `settings` WHERE `key` = \'css\'')->fetch()->value; $css = $db->query('SELECT `value` FROM `settings` WHERE `key` = \'css\'')->fetch()->value ?? null;
if ($css) { if ($css) {
$content = file_get_contents($css); $content = file_get_contents($css);
if ($content !== false) { if ($content !== false) {
@ -230,9 +227,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
cleanDirectory(__DIR__.'/../resources/cache'); cleanDirectory(__DIR__.'/../resources/cache');
cleanDirectory(__DIR__.'/../resources/sessions'); cleanDirectory(__DIR__.'/../resources/sessions');
if (!isset($config['debug']) || !$config['debug']) { //removeDirectory(__DIR__.'/../install');
removeDirectory(__DIR__.'/../install');
}
// Installed successfully, destroy the installer session // Installed successfully, destroy the installer session
$session->destroy(); $session->destroy();

View file

@ -157,7 +157,7 @@ Se non sei stato tu a richiedere la reimpostazione della password, ignora sempli
'recaptcha_site_key' => 'reCAPTCHA Site Key', 'recaptcha_site_key' => 'reCAPTCHA Site Key',
'recaptcha_secret_key' => 'reCAPTCHA Secret Key', 'recaptcha_secret_key' => 'reCAPTCHA Secret Key',
'no_tags' => 'Nessun tag aggiunto', 'no_tags' => 'Nessun tag aggiunto',
'upload_max_file_size' => 'La dimensione massima del file è attualmente %s.', 'upload_max_file_size' => 'La dimensione massima di un file caricabile è %s.',
'ldap_cant_connect' => 'Impossibile connettersi al server di autenticazione LDAP.', 'ldap_cant_connect' => 'Impossibile connettersi al server di autenticazione LDAP.',
'user_create_password' => 'Se lasciato vuoto, si consiglia di inviare una notifica all\'utente via e-mail.', 'user_create_password' => 'Se lasciato vuoto, si consiglia di inviare una notifica all\'utente via e-mail.',
'mail.new_account_text_with_pw' => 'Ciao %s! 'mail.new_account_text_with_pw' => 'Ciao %s!

View file

@ -6,7 +6,7 @@
{% include 'comp/navbar.twig' %} {% include 'comp/navbar.twig' %}
<div class="container"> <div class="container">
{% include 'comp/alert.twig' %} {% include 'comp/alert.twig' %}
<div class="alert alert-info alert-permanent"> <div class="alert alert-success alert-permanent">
{{ lang('upload_max_file_size', [max_file_size]) }} {{ lang('upload_max_file_size', [max_file_size]) }}
</div> </div>
<div class="card shadow-sm"> <div class="card shadow-sm">

View file

@ -1,18 +1,19 @@
$(document).ready(function () { $(document).ready(function () {
var $connection = $('#connection'); var $connection = $('#connection');
var $all_database_options = $('.hook-database'); var $allDatabaseOptions = $('.hook-database');
var $all_database_inputs = $('.hook-database-input'); var $allDatabaseInputs = $('.hook-database-input');
var sqliteDSN = $('#dsn').val();
var $storage_driver = $('#storage_driver'); var $storageDriver = $('#storage_driver');
var $all_storage_inputs = $('.hook-storage-input'); var $allStorageInputs = $('.hook-storage-input');
var $all_storage_options = $('.hook-storage'); var $allStorageOptions = $('.hook-storage');
$connection.change(function () { $connection.change(function () {
$all_database_options.hide(); $allDatabaseOptions.hide();
$all_database_inputs.prop('required', ''); $allDatabaseInputs.prop('required', '');
switch ($(this).val()) { switch ($(this).val()) {
case 'sqlite': case 'sqlite':
$('#dsn').val('resources/database/xbackbone.db'); $('#dsn').val(sqliteDSN);
break; break;
case 'mysql': case 'mysql':
$('#dsn').val('host=localhost;port=3306;dbname=xbackbone'); $('#dsn').val('host=localhost;port=3306;dbname=xbackbone');
@ -22,9 +23,9 @@ $(document).ready(function () {
} }
}); });
$storage_driver.change(function () { $storageDriver.change(function () {
$all_storage_options.hide(); $allStorageOptions.hide();
$all_storage_inputs.prop('required', ''); $allStorageInputs.prop('required', '');
switch ($(this).val()) { switch ($(this).val()) {
case 'local': case 'local':
$('#storage_path').val($('#storage_path').data('default-local')).prop('required', 'required').parent().parent().show(); $('#storage_path').val($('#storage_path').data('default-local')).prop('required', 'required').parent().parent().show();
@ -56,8 +57,8 @@ $(document).ready(function () {
} }
}); });
$all_database_options.hide(); $allDatabaseOptions.hide();
$all_storage_options.hide(); $allStorageOptions.hide();
$storage_driver.trigger('change'); $storageDriver.trigger('change');
$connection.trigger('change'); $connection.trigger('change');
}); });