Fixed installer errors
This commit is contained in:
parent
7e9d43ec71
commit
a253234bd4
14 changed files with 56 additions and 77 deletions
|
@ -73,6 +73,6 @@ class TagController extends Controller
|
|||
return make(ValidationHelper::class)
|
||||
->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->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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,23 +16,17 @@ class Migrator
|
|||
* @var string
|
||||
*/
|
||||
private $schemaPath;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $firstMigrate;
|
||||
|
||||
/**
|
||||
* Migrator constructor.
|
||||
*
|
||||
* @param DB $db
|
||||
* @param string $schemaPath
|
||||
* @param bool $firstMigrate
|
||||
* @param DB $db
|
||||
* @param string $schemaPath
|
||||
*/
|
||||
public function __construct(DB $db, ?string $schemaPath, bool $firstMigrate = false)
|
||||
public function __construct(DB $db, ?string $schemaPath)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->schemaPath = $schemaPath;
|
||||
$this->firstMigrate = $firstMigrate;
|
||||
}
|
||||
|
||||
public function migrate()
|
||||
|
@ -43,9 +37,7 @@ class Migrator
|
|||
$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');
|
||||
|
||||
|
|
|
@ -464,14 +464,11 @@ if (!function_exists('dsnFromConfig')) {
|
|||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @param string $baseDir
|
||||
* @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'].':'.$dsn;
|
||||
return $config['db']['connection'].':'.$config['db']['dsn'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
bin/migrate
12
bin/migrate
|
@ -18,15 +18,9 @@ if (!$config) {
|
|||
|
||||
chdir(__DIR__.'/../');
|
||||
|
||||
$firstMigrate = false;
|
||||
if ($config['db']['connection'] === 'sqlite' && !file_exists(__DIR__.'/../'.$config['db']['dsn'])) {
|
||||
touch(__DIR__.'/../'.$config['db']['dsn']);
|
||||
$firstMigrate = true;
|
||||
}
|
||||
$db = new DB(dsnFromConfig($config), $config['db']['username'], $config['db']['password']);
|
||||
|
||||
$db = new DB(dsnFromConfig($config, getcwd().DIRECTORY_SEPARATOR), $config['db']['username'], $config['db']['password']);
|
||||
|
||||
$migrator = new Migrator($db, 'resources/schemas', $firstMigrate);
|
||||
$migrator = new Migrator($db, 'resources/schemas');
|
||||
$migrator->migrate();
|
||||
|
||||
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'])) {
|
||||
removeDirectory(__DIR__.'/../install');
|
||||
//removeDirectory(__DIR__.'/../install');
|
||||
}
|
||||
|
||||
echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL;
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Factories\ViewFactory;
|
|||
use App\Middleware\InjectMiddleware;
|
||||
use App\Middleware\LangMiddleware;
|
||||
use App\Middleware\RememberMiddleware;
|
||||
use App\Web\Session;
|
||||
use App\Web\View;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
use DI\ContainerBuilder;
|
||||
|
@ -58,6 +59,10 @@ if (!$config['debug']) {
|
|||
}
|
||||
|
||||
$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) {
|
||||
return ViewFactory::createAppInstance($container);
|
||||
}),
|
||||
|
|
|
@ -36,11 +36,6 @@ return [
|
|||
}),
|
||||
'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) {
|
||||
$config = $container->get('config');
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sergix44/xbackbone",
|
||||
"version": "3.1",
|
||||
"version": "3.1.RC1",
|
||||
"description": "A lightweight ShareX PHP backend",
|
||||
"type": "project",
|
||||
"require": {
|
||||
|
@ -21,8 +21,7 @@
|
|||
"slim/slim": "^4.0",
|
||||
"spatie/flysystem-dropbox": "^1.0",
|
||||
"superbalist/flysystem-google-storage": "^7.2",
|
||||
"twig/twig": "^2.12",
|
||||
"ext-ldap": "*"
|
||||
"twig/twig": "^2.12"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
|
|
23
composer.lock
generated
23
composer.lock
generated
|
@ -4,20 +4,20 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "17be54724e0928ed7049b18bbcb181b9",
|
||||
"content-hash": "979e04cb72a48a50d7872132f8efa29f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
"version": "3.133.46",
|
||||
"version": "3.134.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/aws/aws-sdk-php.git",
|
||||
"reference": "98d359e61b365f3040ca61c66ae8883334cf5d74"
|
||||
"reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/98d359e61b365f3040ca61c66ae8883334cf5d74",
|
||||
"reference": "98d359e61b365f3040ca61c66ae8883334cf5d74",
|
||||
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3de2711a47e7c3f5e93a5c83f019188fd23f852f",
|
||||
"reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -88,7 +88,7 @@
|
|||
"s3",
|
||||
"sdk"
|
||||
],
|
||||
"time": "2020-03-27T18:15:32+00:00"
|
||||
"time": "2020-04-03T18:11:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "firebase/php-jwt",
|
||||
|
@ -255,16 +255,16 @@
|
|||
},
|
||||
{
|
||||
"name": "google/cloud-storage",
|
||||
"version": "v1.19.0",
|
||||
"version": "v1.20.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/googleapis/google-cloud-php-storage.git",
|
||||
"reference": "49dc19608ebea54023c2b3910e72b91393235d82"
|
||||
"reference": "d09ef3d47079e4a3cac1419856302cc5c07c5e1f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/49dc19608ebea54023c2b3910e72b91393235d82",
|
||||
"reference": "49dc19608ebea54023c2b3910e72b91393235d82",
|
||||
"url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/d09ef3d47079e4a3cac1419856302cc5c07c5e1f",
|
||||
"reference": "d09ef3d47079e4a3cac1419856302cc5c07c5e1f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -302,7 +302,7 @@
|
|||
"Apache-2.0"
|
||||
],
|
||||
"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",
|
||||
|
@ -765,6 +765,7 @@
|
|||
"serialize",
|
||||
"tokenizer"
|
||||
],
|
||||
"abandoned": "opis/closure",
|
||||
"time": "2018-03-21T22:21:57+00:00"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ return [
|
|||
'base_url' => 'https://localhost', // no trailing slash
|
||||
'db' => [
|
||||
'connection' => 'sqlite',
|
||||
'dsn' => 'resources/database/xbackbone.db',
|
||||
'dsn' => realpath(__DIR__).'/resources/database/xbackbone.db',
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
],
|
||||
|
|
|
@ -44,7 +44,7 @@ return [
|
|||
],
|
||||
'db' => [
|
||||
'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
|
||||
'password' => null,
|
||||
]
|
||||
|
|
|
@ -29,7 +29,7 @@ $config = [
|
|||
'debug' => true,
|
||||
'db' => [
|
||||
'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,
|
||||
'password' => null,
|
||||
],
|
||||
|
@ -51,6 +51,10 @@ $builder->addDefinitions([
|
|||
return ViewFactory::createInstallerInstance($container);
|
||||
}),
|
||||
'view' => get(View::class),
|
||||
Session::class => factory(function () {
|
||||
return new Session('xbackbone_session');
|
||||
}),
|
||||
'session' => get(Session::class),
|
||||
]);
|
||||
$builder->addDefinitions(__DIR__.'/../bootstrap/container.php');
|
||||
|
||||
|
@ -95,7 +99,6 @@ $app->get('/', function (Response $response, View $view, Session $session) use (
|
|||
})->setName('install');
|
||||
|
||||
$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
|
||||
$installed = true;
|
||||
|
||||
|
@ -180,13 +183,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
|
|||
|
||||
// Build the dns string and run the migrations
|
||||
try {
|
||||
$firstMigrate = false;
|
||||
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 = new Migrator($db, __DIR__.'/../resources/schemas');
|
||||
$migrator->migrate();
|
||||
$migrator->reSyncQuotas($storage);
|
||||
} catch (PDOException $e) {
|
||||
|
@ -201,7 +198,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
|
|||
}
|
||||
|
||||
// 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) {
|
||||
$content = file_get_contents($css);
|
||||
if ($content !== false) {
|
||||
|
@ -230,9 +227,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor
|
|||
cleanDirectory(__DIR__.'/../resources/cache');
|
||||
cleanDirectory(__DIR__.'/../resources/sessions');
|
||||
|
||||
if (!isset($config['debug']) || !$config['debug']) {
|
||||
removeDirectory(__DIR__.'/../install');
|
||||
}
|
||||
//removeDirectory(__DIR__.'/../install');
|
||||
|
||||
// Installed successfully, destroy the installer session
|
||||
$session->destroy();
|
||||
|
|
|
@ -157,7 +157,7 @@ Se non sei stato tu a richiedere la reimpostazione della password, ignora sempli
|
|||
'recaptcha_site_key' => 'reCAPTCHA Site Key',
|
||||
'recaptcha_secret_key' => 'reCAPTCHA Secret Key',
|
||||
'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.',
|
||||
'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!
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{% include 'comp/navbar.twig' %}
|
||||
<div class="container">
|
||||
{% 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]) }}
|
||||
</div>
|
||||
<div class="card shadow-sm">
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
$(document).ready(function () {
|
||||
var $connection = $('#connection');
|
||||
var $all_database_options = $('.hook-database');
|
||||
var $all_database_inputs = $('.hook-database-input');
|
||||
var $allDatabaseOptions = $('.hook-database');
|
||||
var $allDatabaseInputs = $('.hook-database-input');
|
||||
var sqliteDSN = $('#dsn').val();
|
||||
|
||||
var $storage_driver = $('#storage_driver');
|
||||
var $all_storage_inputs = $('.hook-storage-input');
|
||||
var $all_storage_options = $('.hook-storage');
|
||||
var $storageDriver = $('#storage_driver');
|
||||
var $allStorageInputs = $('.hook-storage-input');
|
||||
var $allStorageOptions = $('.hook-storage');
|
||||
|
||||
$connection.change(function () {
|
||||
$all_database_options.hide();
|
||||
$all_database_inputs.prop('required', '');
|
||||
$allDatabaseOptions.hide();
|
||||
$allDatabaseInputs.prop('required', '');
|
||||
switch ($(this).val()) {
|
||||
case 'sqlite':
|
||||
$('#dsn').val('resources/database/xbackbone.db');
|
||||
$('#dsn').val(sqliteDSN);
|
||||
break;
|
||||
case 'mysql':
|
||||
$('#dsn').val('host=localhost;port=3306;dbname=xbackbone');
|
||||
|
@ -22,9 +23,9 @@ $(document).ready(function () {
|
|||
}
|
||||
});
|
||||
|
||||
$storage_driver.change(function () {
|
||||
$all_storage_options.hide();
|
||||
$all_storage_inputs.prop('required', '');
|
||||
$storageDriver.change(function () {
|
||||
$allStorageOptions.hide();
|
||||
$allStorageInputs.prop('required', '');
|
||||
switch ($(this).val()) {
|
||||
case 'local':
|
||||
$('#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();
|
||||
$all_storage_options.hide();
|
||||
$storage_driver.trigger('change');
|
||||
$allDatabaseOptions.hide();
|
||||
$allStorageOptions.hide();
|
||||
$storageDriver.trigger('change');
|
||||
$connection.trigger('change');
|
||||
});
|
Loading…
Reference in a new issue