Skip to content

Commit

Permalink
New cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Apr 29, 2012
1 parent 3c9f138 commit a7f88b9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
12 changes: 8 additions & 4 deletions application/controllers/cronjob/foursquare.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ function index() {
$this->output->enable_profiler(TRUE);
}

$this->users();

if (!$this->input->is_cli_request()) {
$this->output->set_profiler_sections(array('queries' => TRUE));
}
}

function users() {
echo "Cronjob started at " . date('d/m/Y H:i') . "\n";

$limit = $this->input->get('limit') ? $this->input->get('limit') : FALSE;
Expand Down Expand Up @@ -89,10 +97,6 @@ function index() {

echo "Cronjob inserted $count checkins for " . count($users) . " users at " . date('d/m/Y H:i') . "\n";
echo "---------------------------------------------------------------\n";

if (!$this->input->is_cli_request()) {
$this->output->set_profiler_sections(array('queries' => TRUE));
}
}

/**
Expand Down
70 changes: 70 additions & 0 deletions application/controllers/cronjob/updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Jens Segers <jens at iRail.be>
* @author Hannes Van De Vreken <hannes at iRail.be>
*/

if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Updater extends CI_Controller {

function __construct() {
parent::__construct();

$user = $this->auth->current_user();
if (!($user && $user['admin']) && !$this->input->is_cli_request()) {
show_error('You have not permission to access this page');
}
}

function index() {
if (!$this->input->is_cli_request()) {
$this->output->enable_profiler(TRUE);
}

$this->regions();
$this->clans();

if (!$this->input->is_cli_request()) {
$this->output->set_profiler_sections(array('queries' => TRUE));
}
}

function regions() {
$this->load->model('region_model');
$regions = $this->region_model->get_all();

foreach ($regions as $region) {
$leader = $this->region_model->get_leader($region['regionid']);

// no leader, eg: after db reset
if (!$leader) {
$this->region_model->update($region['regionid'], array('leader' => 0));
} else if ($leader['clanid'] != $region['leader']) {
$this->region_model->set_leader($region['regionid'], $leader['clanid'], $region['leader']);
echo $region['name'] . ' -> ' . $leader['name'] . "\n";
}
}
}

function clans() {
$this->load->model('clan_model');
$clans = $this->clan_model->get_all();

foreach ($clans as $clan) {
$capo = $this->clan_model->get_capo($clan['clanid']);

// no capo, eg: after db reset
if (!$capo) {
$this->clan_model->update($clan['clanid'], array('capo' => 0));
} else if ($capo['fsqid'] != $clan['capo']) {
$this->clan_model->set_capo($clan['clanid'], $capo['fsqid']);
echo $clan['name'] . ' -> ' . $capo['firstname'] . ' ' . $capo['lastname'] . "\n";
}
}
}

}
39 changes: 0 additions & 39 deletions application/controllers/scripts/regions.php

This file was deleted.

0 comments on commit a7f88b9

Please sign in to comment.