Add kiosk mode, public board access with read-only and auto-refresh
This commit is contained in:
@@ -17,7 +17,7 @@ require __DIR__.'/schema.php';
|
||||
abstract class Base
|
||||
{
|
||||
const APP_VERSION = 'master';
|
||||
const DB_VERSION = 2;
|
||||
const DB_VERSION = 3;
|
||||
const DB_FILENAME = 'data/db.sqlite';
|
||||
|
||||
private static $dbInstance = null;
|
||||
@@ -46,4 +46,17 @@ abstract class Base
|
||||
die('Unable to migrate database schema!');
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a random token from /dev/urandom or with uniqid()
|
||||
public static function generateToken()
|
||||
{
|
||||
if (ini_get('open_basedir') === '') {
|
||||
$token = file_get_contents('/dev/urandom', false, null, 0, 30);
|
||||
}
|
||||
else {
|
||||
$token = uniqid(mt_rand(), true);
|
||||
}
|
||||
|
||||
return hash('crc32b', $token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,16 +66,6 @@ class Config extends Base
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public function optimizeDatabase()
|
||||
{
|
||||
$this->db->getconnection()->exec("VACUUM");
|
||||
|
||||
@@ -16,6 +16,11 @@ class Project extends Base
|
||||
return $this->db->table(self::TABLE)->eq('id', $project_id)->findOne();
|
||||
}
|
||||
|
||||
public function getByToken($token)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('token', $token)->findOne();
|
||||
}
|
||||
|
||||
public function getFirst()
|
||||
{
|
||||
return $this->db->table(self::TABLE)->findOne();
|
||||
@@ -92,12 +97,12 @@ class Project extends Base
|
||||
{
|
||||
$this->db->startTransaction();
|
||||
|
||||
$values['token'] = self::generateToken();
|
||||
$this->db->table(self::TABLE)->save($values);
|
||||
|
||||
$project_id = $this->db->getConnection()->getLastId();
|
||||
|
||||
$boardModel = new \Model\Board;
|
||||
|
||||
$boardModel->create($project_id, array(
|
||||
t('Backlog'),
|
||||
t('Ready'),
|
||||
|
||||
@@ -2,11 +2,27 @@
|
||||
|
||||
namespace Schema;
|
||||
|
||||
function version_3($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE projects ADD column token TEXT');
|
||||
|
||||
// For each existing project, assign a different token
|
||||
$rq = $pdo->prepare("SELECT id FROM projects WHERE token IS NULL");
|
||||
$rq->execute();
|
||||
$results = $rq->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if ($results !== false) {
|
||||
|
||||
foreach ($results as &$result) {
|
||||
$rq = $pdo->prepare('UPDATE projects SET token=? WHERE id=?');
|
||||
$rq->execute(array(\Model\Base::generateToken(), $result['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function version_2($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE tasks ADD column date_completed INTEGER');
|
||||
|
||||
// For all existing completed tasks, set the date of creation as a date of completion
|
||||
$pdo->exec('UPDATE tasks SET date_completed=date_creation WHERE is_active=0');
|
||||
}
|
||||
|
||||
@@ -74,6 +90,6 @@ function version_1($pdo)
|
||||
$pdo->exec("
|
||||
INSERT INTO config
|
||||
(language, webhooks_token)
|
||||
VALUES ('en_US', '".\Model\Config::generateToken()."')
|
||||
VALUES ('en_US', '".\Model\Base::generateToken()."')
|
||||
");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user