Example #1
0
 /**
  * @param Bot $bot
  * @return string
  */
 public static function getHTML($bot)
 {
     $now = time();
     $last = strtotime($bot->get('last_seen'));
     $elapsed = $now - $last;
     if ($last <= 0) {
         return "never";
     }
     $months = floor($elapsed / (60 * 60 * 24 * 30));
     $elapsed = $elapsed - $months * 60 * 60 * 30;
     $days = floor($elapsed / (60 * 60 * 24));
     $elapsed = $elapsed - $days * 60 * 60 * 24;
     $hours = floor($elapsed / (60 * 60));
     $elapsed = $elapsed - $hours * 60 * 60;
     $minutes = floor($elapsed / 60);
     $seconds = $elapsed - $minutes * 60;
     if ($months) {
         return "{$months} months";
     }
     if ($days > 1) {
         return "{$days} days ago";
     }
     if ($days) {
         return "{$days} day ago";
     }
     if ($hours > 1) {
         return "{$hours} hours ago";
     }
     if ($hours) {
         return "{$hours}:{$minutes}:{$seconds} ago";
     }
     if ($minutes > 1) {
         return "{$minutes} minutes ago";
     }
     if ($minutes) {
         return "{$minutes} minute ago";
     }
     return "{$seconds}s ago";
 }
Example #2
0
include "../patches.php";
$patchNumber = 12;
start_patch();
if (!patch_exists($patchNumber)) {
    // Fix the temperature fields:
    $rs = db()->query("SELECT * from jobs");
    while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
        $job = new Job($row['id']);
        $fixed_data = fix_temp_data($job->get('temperature_data'));
        $job->set('temperature_data', $fixed_data);
        $job->save();
    }
    $rs = db()->query("SELECT * from bots");
    while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
        $bot = new Bot($row['id']);
        $fixed_data = fix_temp_data($bot->get('temperature_data'));
        $bot->set('temperature_data', $fixed_data);
        $bot->save();
    }
    $expandTemperatureData = "\n\t\tALTER TABLE jobs\n  \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
    db()->execute($expandTemperatureData);
    $expandTemperatureData = "\n\t\tALTER TABLE bots\n  \t\tMODIFY COLUMN temperature_data longtext NOT NULL";
    finish_patch($patchNumber, "Expanded temperature data fields");
}
function fix_temp_data($data)
{
    if (strlen($data) == 0) {
        return "";
    }
    $data .= "}";
    while (JSON::decode($data) === null) {
Example #3
0
 public function delete()
 {
     $this->assertLoggedIn();
     $this->set('area', 'bots');
     try {
         //how do we find them?
         if ($this->args('id')) {
             $bot = new Bot($this->args('id'));
         } else {
             throw new Exception("Could not find that bot.");
         }
         //did we really get someone?
         if (!$bot->isHydrated()) {
             throw new Exception("Could not find that bot.");
         }
         if ($bot->get('user_id') != User::$me->id) {
             throw new Exception("You do not own this bot.");
         }
         if ($bot->get('status') == 'working' || $bot->get('status') == 'paused') {
             throw new Exception("You cannot delete bots that are currently working.  First, use the client software to cancel the job and then delete the bot.");
         }
         $this->set('bot', $bot);
         $this->setTitle('Delete Bot - ' . $bot->getName());
         if ($this->args('submit')) {
             Activity::log("deleted the bot <strong>" . $bot->getName() . "</strong>.");
             $bot->delete();
             $this->forwardToUrl("/bots");
         }
     } catch (Exception $e) {
         $this->setTitle('Delete Bot - Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Example #4
0
 public function api_findnewjob()
 {
     $bot = new Bot($this->args('bot_id'));
     if (!$bot->isHydrated()) {
         throw new Exception("Bot does not exist.");
     }
     if (!$bot->isMine()) {
         throw new Exception("This bot is not yours.");
     }
     //can we slice?
     $can_slice = $this->args('can_slice') && $bot->get('slice_engine_id') && $bot->get('slice_config_id');
     //load up our data.
     $data = array();
     $job = $bot->findNewJob($can_slice);
     if ($job->isHydrated()) {
         $data = $job->getAPIData();
     }
     //record our bot as having checked in.
     // This returns the new bot, but it's currently not needed
     $this->_markBotAsSeen($bot);
     return $data;
 }
Example #5
0
                <th>Hours</th>
              </tr>
              <?php 
$rank = 0;
?>
              <?php 
foreach ($bot_leaderboard as $row) {
    ?>
                <?php 
    $rank++;
    ?>
                <?php 
    $bot = new Bot($row['bot_id']);
    ?>
                <tr <?php 
    echo $bot->get('user_id') == User::$me->id ? 'class="success"' : '';
    ?>
>
                  <td><?php 
    echo $rank;
    ?>
</td>
                  <td><?php 
    echo $bot->getName();
    ?>
</td>
                  <td><?php 
    echo $bot->getUser()->getName();
    ?>
</td>
                  <td><?php