ACC SHELL
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cron extends CI_Controller {
public $data; // view data
public $def; // default model
function __construct(){
parent::__construct();
}
function index () {
$this->day();
$this->hour();
$this->minute();
echo "executed /hour, /day, /minute";
}
function day () {
}
function hour () {
$wpath = "./w";
if ($handle = @opendir($wpath)) {
while (false !== ($entry = readdir($handle))) {
if(strlen($entry)>2){
$logpath = $wpath."/".$entry."/log_old.log";
$logpath1 = $wpath."/".$entry."/log.log";
// 1 day old log_old.log deletes and rename it by log.log
if(file_exists($logpath1) && (!file_exists($logpath) || filemtime($logpath) < time()-24*3600)){
if(file_exists($logpath)) unlink($logpath);
rename($logpath1,$logpath);
echo $logpath1 . " -> " . $logpath . "<br/>";
}
}
}
}
}
function minute () {
}
final public function unit_test(){
// nacteni knihovny pro testy
$this->load->library('unit_test');
// zjisteni seznamu tabulek
$tables_raw=$this->db->query('SHOW tables')->result_array();
$tables=array();
foreach($tables_raw as $table){
$tables[]=end($table);
}
// echo '<pre>'.print_r($tables_raw,true).'</pre>';
// echo '<pre>'.print_r($tables,true).'</pre>';
/* ********************************************************************** */
/* prace s relacemi */
/* ********************************************************************** */
if(!in_array('tests',$tables)){
// vytvoreni testovaci tabulky
$test=$this->db->query("CREATE TABLE `tests` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(50) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci COMMENT='testovaci tabulka';");
$expected_result = true;
$test_name = 'Vytvoreni testovaci tabulky';
$this->unit->run($test, $expected_result, $test_name);
// pridani sloupce na udrzeni vazeb s tabulkou tests
$test=$this->db->query("ALTER TABLE `relations`
ADD `id_tests` int(10) unsigned NULL COMMENT 'pouze pro testovaci ucely - nemazat' AFTER `id_sites`,
COMMENT='udržuje stromová data a umožňuje traverzování';");
$expected_result = true;
$test_name = 'pridani sloupce na udrzeni vazeb s tabulkou tests';
$this->unit->run($test, $expected_result, $test_name);
// vytvoreni vazeb s testovaci tabulkou
$test=$this->db->query("ALTER TABLE `relations`
ADD CONSTRAINT `fk_relations_id_tests-tests_id`
FOREIGN KEY (`id_tests`)
REFERENCES `tests`(`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;");
$expected_result = true;
$test_name = 'pridani sloupce na udrzeni vazeb s tabulkou tests';
$this->unit->run($test, $expected_result, $test_name);
}
// Vyprazdneni testovaci tabulky
$test=$this->db->query("DELETE FROM `tests` WHERE `id` LIKE '%';");
$expected_result = true;
$test_name = 'Vyprazdneni testovaci tabulky';
$this->unit->run($test, $expected_result, $test_name);
// naplneni testovaci tabulky
$test=$this->db->query("INSERT INTO `tests` (`id`, `title`) VALUES
(1, 'test 1'),
(2, 'test 2'),
(3, 'test 3'),
(4, 'test 4'),
(5, 'test 5'),
(6, 'test 6'),
(7, 'test 7'),
(8, 'test 8'),
(9, 'test 9'),
(10, 'test 10');");
$expected_result = true;
$test_name = 'naplneni testovaci tabulky';
$this->unit->run($test, $expected_result, $test_name);
// nastaveni table
$this->relations->table='tests';
$test=$this->relations->table;
$expected_result = 'tests';
$test_name = 'nastaveni table';
$this->unit->run($test, $expected_result, $test_name);
// vlozeni root polozky relace
$test=$this->relations->insert_relation(1);
$expected_result = true;
$test_name = 'vlozeni root polozky relace';
$this->unit->run($test, $expected_result, $test_name);
// id rootu
$rid=$this->relations->last_inserted_id;
// pokus o vlozeni druhe root polozky relace
$test=$this->relations->insert_relation(1);
$expected_result = false;
$test_name = 'pokus o vlozeni druhe root polozky relace';
$this->unit->run($test, $expected_result, $test_name);
// zjisteni id relace testovaci root polozky
$root=$this->relations->get_relation_by_site(1,'tests');
$expected_result = 'is_array';
$test_name = 'zjisteni id relace testovaci root polozky';
$this->unit->run($root, $expected_result, $test_name);
// vlozeni 1 potomka rootu
$test=$this->relations->insert_relation(2,$root['id']);
$expected_result = true;
$test_name = 'vlozeni 1 potomka rootu';
$this->unit->run($test, $expected_result, $test_name);
// vlozeni 2 potomka rootu
$test=$this->relations->insert_relation(3,$root['id']);
$expected_result = true;
$test_name = 'vlozeni 2 potomka rootu';
$this->unit->run($test, $expected_result, $test_name);
// vlozeni 3 potomka rootu
$test=$this->relations->insert_relation(4,$root['id']);
$expected_result = true;
$test_name = 'vlozeni 3 potomka rootu';
$this->unit->run($test, $expected_result, $test_name);
// zjisteni id posleniho vlozeneho zaznamu
$lid=$test=$this->relations->last_inserted_id;
$expected_result = 'is_numeric';
$test_name = 'zjisteni id posleniho vlozeneho zaznamu';
$this->unit->run($test, $expected_result, $test_name);
// vlozeni 1 potomka posledniho zaznamu
$test=$this->relations->insert_relation(5,$lid);
$expected_result = true;
$test_name = 'vlozeni 1 potomka posledniho prvku vetve';
$this->unit->run($test, $expected_result, $test_name);
// vlozeni 2 potomka posledniho zaznamu
$test=$this->relations->insert_relation(6,$lid);
$expected_result = true;
$test_name = 'vlozeni 2 potomka posledniho prvku vetve';
$this->unit->run($test, $expected_result, $test_name);
// prvek k presouvani
$mid=$test=$this->relations->last_inserted_id;
// presun polozky
$test=$this->relations->move_relation($mid,$rid,2);
$expected_result = true;
$test_name = 'presun posleni vlozene polozky na jine misto stromu';
$this->unit->run($test, $expected_result, $test_name);
// presun vetve o uroven vys
$test=$this->relations->move_relation($lid,$mid,1);
$expected_result = true;
$test_name = 'presun vetve o uroven vys';
$this->unit->run($test, $expected_result, $test_name);
// vypise vysledky testu
echo $this->unit->report();
}
}
?>
ACC SHELL 2018