Automatic actions

This commit is contained in:
Frédéric Guillot
2014-03-09 23:21:23 -04:00
parent 7bd4697dfc
commit 7749b8ed56
49 changed files with 1678 additions and 190 deletions

View File

@@ -13,45 +13,22 @@ require __DIR__.'/../vendor/SimpleValidator/Validators/Equals.php';
require __DIR__.'/../vendor/SimpleValidator/Validators/AlphaNumeric.php';
require __DIR__.'/../vendor/SimpleValidator/Validators/GreaterThan.php';
require __DIR__.'/../vendor/SimpleValidator/Validators/Date.php';
require __DIR__.'/../vendor/PicoDb/Database.php';
require __DIR__.'/schema.php';
abstract class Base
{
const APP_VERSION = 'master';
const DB_VERSION = 9;
private static $dbInstance = null;
protected $db;
protected $event;
public function __construct()
public function __construct(\PicoDb\Database $db, \Core\Event $event)
{
if (self::$dbInstance === null) {
self::$dbInstance = $this->getDatabaseInstance();
}
$this->db = self::$dbInstance;
}
public function getDatabaseInstance()
{
$db = new \PicoDb\Database(array(
'driver' => 'sqlite',
'filename' => DB_FILENAME
));
if ($db->schema()->check(self::DB_VERSION)) {
return $db;
}
else {
die('Unable to migrate database schema!');
}
$this->db = $db;
$this->event = $event;
}
// Generate a random token from /dev/urandom or with uniqid()
public static function generateToken()
{
if (ini_get('open_basedir') === '' and strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
if (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$token = file_get_contents('/dev/urandom', false, null, 0, 30);
}
else {
@@ -60,19 +37,4 @@ abstract class Base
return hash('crc32b', $token);
}
public function getTimestampFromDate($value, $format)
{
$date = \DateTime::createFromFormat($format, $value);
if ($date !== false) {
$errors = \DateTime::getLastErrors();
if ($errors['error_count'] === 0 && $errors['warning_count'] === 0) {
$timestamp = $date->getTimestamp();
return $timestamp > 0 ? $timestamp : 0;
}
}
return 0;
}
}