示例#1
0
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
    }
}
示例#2
0
    $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();