mirror of
https://github.com/moparisthebest/wallabag
synced 2024-12-18 05:32:23 -05:00
Import poche v2 schema
This commit is contained in:
parent
95a3b293ae
commit
6f5d4b334c
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ cache/*
|
||||
vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
poche.db
|
||||
|
@ -17,6 +17,10 @@ If you are using PHP 5.4 you can run Poche v2 by using the embedded webserver:
|
||||
|
||||
Poche should now be running at [http://localhost:8080](http://localhost:8080).
|
||||
|
||||
Then you should initialize your database by running:
|
||||
|
||||
./console db:create
|
||||
|
||||
# Test
|
||||
|
||||
To run the test suite just use:
|
||||
|
@ -4,7 +4,8 @@
|
||||
"atoum/atoum" : "dev-master",
|
||||
"twig/twig": ">=1.8,<2.0-dev",
|
||||
"symfony/twig-bridge": "~2.3",
|
||||
"knplabs/console-service-provider": "dev-master"
|
||||
"knplabs/console-service-provider": "dev-master",
|
||||
"doctrine/dbal": "2.2.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Poche\\": "src/" }
|
||||
|
1
console
1
console
@ -8,5 +8,6 @@ require_once __DIR__.'/src/app.php';
|
||||
$console = $app['console'];
|
||||
|
||||
$console->add(new Poche\Command\UnitTestsCommand());
|
||||
$console->add(new Poche\Command\CreateSchemaCommand());
|
||||
|
||||
$console->run();
|
||||
|
36
src/Poche/Command/CreateSchemaCommand.php
Normal file
36
src/Poche/Command/CreateSchemaCommand.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Poche\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Knp\Command\Command as BaseCommand;
|
||||
use Poche\Schema;
|
||||
|
||||
/**
|
||||
* Application aware command
|
||||
*
|
||||
* Provide a silex application in CLI context.
|
||||
*/
|
||||
class CreateSchemaCommand extends BaseCommand
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('db:create')
|
||||
->setDescription('Create default schema')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$app = $this->getSilexApplication();
|
||||
$db = $app['db'];
|
||||
|
||||
Schema::executeSchema($db);
|
||||
|
||||
$output->writeln("<info>Schema created</info>");
|
||||
}
|
||||
}
|
||||
|
88
src/Poche/Schema.php
Normal file
88
src/Poche/Schema.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace Poche;
|
||||
|
||||
use Poche\Util\Token;
|
||||
|
||||
class Schema
|
||||
{
|
||||
public static function executeSchema($db) {
|
||||
|
||||
$db->query("
|
||||
CREATE TABLE config (
|
||||
name TEXT,
|
||||
value TEXT
|
||||
)
|
||||
");
|
||||
|
||||
$db->query("
|
||||
INSERT INTO config (name, value)
|
||||
VALUES ('api_token', '". Token::generateToken()."')
|
||||
");
|
||||
|
||||
|
||||
|
||||
$db->query("
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
||||
username TEXT DEFAULT 'poche',
|
||||
password TEXT,
|
||||
email TEXT,
|
||||
language TEXT DEFAULT 'en_US',
|
||||
items_per_page INTEGER DEFAULT 100,
|
||||
theme TEXT DEFAULT 'original',
|
||||
items_sorting_direction TEXT DEFAULT 'desc',
|
||||
api_token TEXT DEFAULT '". Token::generateToken()."',
|
||||
feed_token TEXT DEFAULT '".Token::generateToken()."',
|
||||
auth_google_token TEXT DEFAULT '',
|
||||
auth_mozilla_token TEXT DEFAULT ''
|
||||
)
|
||||
");
|
||||
|
||||
//$db->query("
|
||||
// INSERT INTO users
|
||||
// (password)
|
||||
// VALUES ('".\password_hash('poche', PASSWORD_BCRYPT)."')
|
||||
//");
|
||||
|
||||
$db->query('
|
||||
CREATE TABLE entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
||||
url TEXT,
|
||||
title TEXT,
|
||||
content TEXT,
|
||||
updated INTEGER,
|
||||
status TEXT,
|
||||
bookmark INTEGER DEFAULT 0,
|
||||
fetched INTEGER DEFAULT 1,
|
||||
user_id INTEGER,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
');
|
||||
|
||||
$db->query('CREATE INDEX idx_status ON entries(status)');
|
||||
|
||||
$db->query('
|
||||
CREATE TABLE tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
||||
value TEXT
|
||||
)
|
||||
');
|
||||
|
||||
$db->query('
|
||||
CREATE TABLE tags_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
|
||||
entry_id INTEGER,
|
||||
tag_id INTEGER,
|
||||
FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE
|
||||
)
|
||||
');
|
||||
|
||||
$db->query("
|
||||
CREATE TABLE plugin_options (
|
||||
name TEXT PRIMARY KEY,
|
||||
value TEXT
|
||||
)
|
||||
");
|
||||
}
|
||||
}
|
22
src/Poche/Util/Token.php
Normal file
22
src/Poche/Util/Token.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Poche\Util;
|
||||
|
||||
class Token
|
||||
{
|
||||
/**
|
||||
* Generates a new token
|
||||
*
|
||||
* @return string a token generated with /dev/urandom or mt_rand()
|
||||
*/
|
||||
public static function generateToken()
|
||||
{
|
||||
if (ini_get('open_basedir') === '') {
|
||||
return substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
|
||||
}
|
||||
else {
|
||||
return substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,3 +13,9 @@ $app->register(new ConsoleServiceProvider(), [
|
||||
'console.project_directory' => __DIR__.'/..',
|
||||
]);
|
||||
|
||||
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
|
||||
'db.options' => array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => __DIR__.'/../poche.db',
|
||||
),
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user