public function __construct() { $table = new DBTable(); $table->column('id')->bigint()->primary()->increment(); $table->column('organisation_id')->bigint()->index(); $table->column('amount')->float()->index(); $table->column('currency')->string(40)->nullable(); $table->column('transaction_id')->string()->nullable()->index(); $table->column('period_start')->date()->index(); $table->column('period_end')->date()->index(); $table->column('payment_date')->datetime()->index(); parent::__construct($table); $this->amount = 0; $this->payment_date = Date::toDateTime(); }
public function __construct() { $table = new DBTable(); $table->column('id')->bigint()->increment()->primary(); $table->column('source_id')->bigint()->index(); $table->column('cdn')->string(255)->index(); $table->column('name')->string(300)->index(); $table->column('original_name')->string(300)->index(); $table->column('path')->string(500)->index(); $table->column('mime')->string(255)->index(); $table->column('size')->integer()->index(); $table->column('identifier')->string(32)->index(); $table->column('last_activity')->datetime()->nullable()->index(); $table->column('created')->datetime()->index(); parent::__construct($table); $this->created = Date::toDateTime(); }
public function __construct() { $table = new DBTable(); $table->column('id')->bigint()->primary()->increment(); $table->column('user_id')->bigint()->index(); $table->column('organisation_id')->bigint()->index(); $table->column('invoice_id')->integer()->index(); $table->column('path')->string(300); $table->column('due_date')->date()->index(); $table->column('amount_total')->integer()->index(); $table->column('payed')->bool()->index(); $table->column('created')->datetime()->index(); parent::__construct($table); if (ModelUser::current()->isLoggedIn()) { $this->user_id = ModelUser::current()->id; } $this->created = Date::toDateTime(); }
public function __construct() { $table = new DBTable('source'); $table->column('id')->bigint()->primary()->increment(); $table->column('organisation_id')->integer()->index(); $table->column('name')->string(255); $table->column('type')->string(255)->index(); $table->column('subdomain')->string(255)->index(); $table->column('require_ssl')->bool(); $table->column('error_image_url')->string(400); $table->column('error_image_parameters')->text(); $table->column('missing_image_url')->string(400); $table->column('missing_image_parameters')->text(); $table->column('default_parameters')->text(); $table->column('last_activity')->datetime()->index(); parent::__construct($table); $this->cloudflareIds = array(); $this->last_activity = Date::toDateTime(); }
function shutdownAccount(\NinjaImg\Model\ModelOrganisation $organisation, $amount) { $lastMonthDate = date('Y-m-01', strtotime('-1 month')); $currency = \NinjaImg\Model\ModelSettings::getInstance()->getCurrency(); $lastPaymentDate = \NinjaImg\Model\ModelPayment::getLastPaymentDate($organisation->id, $lastMonthDate); if (!$lastPaymentDate) { $lastPaymentDate = \Pecee\Date::toDateTime(); savePayment($organisation->id, $amount, $lastMonthDate); } $lastTryDaysAgo = daysAgo($lastPaymentDate, \Pecee\Date::toDateTime()); if ($lastTryDaysAgo > MAX_PAYMENT_ATTEMPTS_DAYS) { echo sprintf('disabled due to no payment in %s days', MAX_PAYMENT_ATTEMPTS_DAYS); mailAdmins('[WARNING] ' . $organisation->name . ' shut down warning', sprintf("Hi bitches!\n\nThe organisation {$organisation->name} has been shut down due to invalid and/or no payment in over %s days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot")); // TODO: Send notification to user about shutting down $organisation->disabled = true; $organisation->update(); } else { $shutdownDays = MAX_PAYMENT_ATTEMPTS_DAYS - $lastTryDaysAgo; echo sprintf('%s days before shutting down account', $shutdownDays); mailAdmins('[INFO] ' . $organisation->name . ' payment not received', sprintf("Hi bitches!\n\nFailed to charge {$organisation->name} and will be automatically disabled in {$shutdownDays} days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot")); // Register try } }
public function __construct() { $table = new DBTable('activity'); $table->column('id')->bigint()->increment()->primary(); $table->column('source_id')->bigint()->index(); $table->column('thumbnail_id')->bigint()->nullable()->index(); $table->column('path')->string(400); $table->column('method')->string(30); $table->column('agent')->string()->nullable(); $table->column('referer')->string()->nullable(); $table->column('ip')->string()->index(); /** * NOTE: identifier is the file's unique id - based on the "path" column. * It is used as a faster way to determinate if a path has been accessed multiple times, * when calculating statistics - and might speed up things when inserting instead of * creating an index to the path column. **/ $table->column('identifier')->string(36)->index(); $table->column('filesize')->integer()->nullable()->index(); $table->column('master')->bool()->index(); $table->column('created')->datetime()->index(); parent::__construct($table); $this->created = Date::toDateTime(); }
$capacity = round(disk_free_space($cdn->path) / 1024 / 1024 / 1024); $leftPercentage = round($capacity / $total * 100); $lastRun = isset($settings['last_run']) ? $settings['last_run'] : 'Not available'; /** * Send warning if the storage left is <= NOTIFY_MIN_SPACE_PERCENTAGE * OTHERWISE * send notification if change is > NOTIFY_PERCENTAGE_CHANGE */ $cdn->active = true; if ($leftPercentage <= NOTIFY_MIN_SPACE_PERCENTAGE) { echo ' - [WARNING] Storage critical: ' . $cdn->capacity_free_gb . '/' . $total . 'GB left' . chr(10); mailAdmins('WARNING: STORAGE ALMOST EMPTY ' . $cdn->name, "Yo, bitches!\n\nWARNING: content-provider \"{$cdn->name}\" has almost exceeded it's disk space and has disabled automatically.\n\nLast recorded date: {$lastRun}\nLast recorded diskspace: " . round($cdn->capacity_free_gb) . "GB\nDiskspace available: " . round($capacity) . "GB\nDiskspace limit: " . round($total) . "GB\n\n- The Ninja Robot"); $cdn->active = false; } else { if ($cdn->capacity_free_gb > 0) { $beforePercentage = round($cdn->capacity_free_gb / $total * 100); $change = $leftPercentage - $beforePercentage; echo ' - [INFO] Storage changed by ' . $change . '%' . chr(10); if ($change >= NOTIFY_PERCENTAGE_CHANGE) { mailAdmins('Storage notification for ' . $cdn->name, "Yo, bitches!\n\nPlease be aware that content-provider \"{$cdn->name}\" has expanded it's storage by {$change}%.\n\nLast recorded date: {$lastRun}\nLast recorded diskspace: " . round($cdn->capacity_free_gb) . "GB\nDiskspace available: " . round($capacity) . "GB\nDiskspace limit: " . round($total) . "GB\nIncrease percentage: {$change}%\n\nA warning will be sent when the storage-provider has " . NOTIFY_MIN_SPACE_PERCENTAGE . "% storage left.\n\n- The Ninja Robot"); } } } echo chr(10); $cdn->capacity_free_gb = $capacity; $cdn->capacity_max_gb = $total; $cdn->update(); } // Update settings $settings['last_run'] = \Pecee\Date::toDateTime(); writeSettings();
public static function getByEmail($email) { return self::fetchOne('SELECT * FROM {table} WHERE `email` = %s && `created` > %s', $email, Date::toDateTime(strtotime('-5 day'))); }