-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Task framework & classes. Cron now is task based. Better loadi…
…ng of enviornment
- Loading branch information
Evan Tahler
committed
Apr 16, 2011
1 parent
3bbd144
commit 0dff136
Showing
12 changed files
with
521 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/*********************************************** | ||
DAVE PHP API | ||
https://github.com/evantahler/PHP-DAVE-API | ||
Evan Tahler | 2011 | ||
I am the task runner. | ||
Tasks can be run with the following syntax: php API/TASK.php --task=name_of_task, or by instantitaiting the class directly | ||
***********************************************/ | ||
|
||
$parts = explode("/",__FILE__); | ||
$ThisFile = $parts[count($parts) - 1]; | ||
chdir(substr(__FILE__,0,(strlen(__FILE__) - strlen($ThisFile)))); | ||
require_once("load_enviorment.php"); unset($parts); unset($ThisFile); | ||
|
||
require_once("helper_functions/parseArgs.php"); | ||
|
||
$TaskFiles = load_tasks(); | ||
|
||
$ARGS = __parseArgs(); | ||
|
||
$TaskNames = array(); | ||
foreach($TaskFiles as $class_name) | ||
{ | ||
$parts = explode("/",$class_name); | ||
$parts = explode(".",$parts[(count($parts) - 1)]); | ||
$class_name = $parts[0]; | ||
if ($class_name != "task" && class_exists($class_name)) | ||
{ | ||
$TaskNames[] = $class_name; | ||
} | ||
} | ||
|
||
// help / List | ||
if ($ARGS["h"] == true || $ARGS["help"] == true || $ARGS["l"] == true || $ARGS["list"] == true) | ||
{ | ||
echo "Task List:\r\n\r\n"; | ||
|
||
$max_name_length = 0; | ||
foreach($TaskNames as $class_name) | ||
{ | ||
if (strlen($class_name) > $max_name_length) | ||
{ | ||
$max_name_length = strlen($class_name); | ||
} | ||
} | ||
|
||
foreach($TaskNames as $class_name) | ||
{ | ||
echo $class_name::class_name(); | ||
$i = strlen($class_name); | ||
while ($i < ($max_name_length + 4)) { echo " "; $i++; } | ||
echo $class_name::get_description(); | ||
echo "\r\n"; | ||
} | ||
exit; | ||
} | ||
|
||
// which task? | ||
$ThisTask = ($ARGS["t"]); | ||
if (strlen($ThisTask) == 0){ $ThisTask = ($ARGS["T"]); } | ||
if (strlen($ThisTask) == 0){ $ThisTask = ($ARGS["task"]); } | ||
if (strlen($ThisTask) == 0) | ||
{ | ||
echo "No task provided. Please provide one with -t or --task. Use --list to show available tasks.\r\n"; | ||
exit; | ||
} | ||
else | ||
{ | ||
if (in_array(($ThisTask), $TaskNames)) | ||
{ | ||
echo run_task($ThisTask, $ARGS); | ||
} | ||
else | ||
{ | ||
echo "That task cannot be found. Use --list to show available tasks.\r\n"; | ||
exit; | ||
} | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/*********************************************** | ||
DAVE PHP API | ||
https://github.com/evantahler/PHP-DAVE-API | ||
Evan Tahler | 2011 | ||
I am a task that will clean both the DB and file caches | ||
***********************************************/ | ||
|
||
class CleanCache extends task | ||
{ | ||
protected static $description = "Use me to clean both the DB and file-based cache"; | ||
|
||
public function run($PARAMS = array()) | ||
{ | ||
global $CONFIG, $DBObj; | ||
|
||
if (self::check_DBObj()) | ||
{ | ||
///////////////////////////////////////////////////////////////////////// | ||
// Check the CACHE DB table for old entries, and remove them | ||
$SQL= 'DELETE FROM `'.$CONFIG['DB'].'`.`'.$CONFIG['CacheTable'].'` WHERE (`ExpireTime` < "'.(time() - $CONFIG['CacheTime']).'") ;'; | ||
$Status = $DBObj->GetStatus(); | ||
if ($Status === true) | ||
{ | ||
$DBObj->Query($SQL); | ||
$this->task_log('Deleted '.$DBObj->NumRowsEffected()." entries from the CACHE DB"); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////// | ||
// Check the CACHE Folder table for old entries, and remove them | ||
$files = scandir($CONFIG['CacheFolder']); | ||
$counter = 0; | ||
foreach ($files as $num => $fname) | ||
{ | ||
$ThisFile = $CONFIG['CacheFolder'].$fname; | ||
if (file_exists($ThisFile) && ((time() - filemtime($ThisFile)) > $CONFIG['CacheTime']) && $fname != "." && $fname != ".." && $fname != ".svn") | ||
{ | ||
unlink($ThisFile); | ||
$counter++; | ||
} | ||
} | ||
$this->task_log('Deleted '.$counter." files from the CACHE directory"); | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/*********************************************** | ||
DAVE PHP API | ||
https://github.com/evantahler/PHP-DAVE-API | ||
Evan Tahler | 2011 | ||
I am a task that will clean the LOG db acording to the expire time | ||
***********************************************/ | ||
|
||
class CleanLog extends task | ||
{ | ||
protected static $description = "I will remove old entries from the LOG table in the DB"; | ||
|
||
public function run($PARAMS = array()) | ||
{ | ||
global $CONFIG, $DBObj; | ||
|
||
if (self::check_DBObj()) | ||
{ | ||
$SQL= 'DELETE FROM `'.$CONFIG['LOG_DB'].'`.`'.$CONFIG['LogTable'].'` WHERE (`TimeStamp` < "'.date('Y-m-d H:i:s',(time() - $CONFIG['LogAge'])).'") ;'; | ||
$DBObj->Query($SQL); | ||
$this->task_log('Deleted '.$DBObj->NumRowsEffected()." entries from the LOG Table in the ".$CONFIG['LOG_DB']." DB"); | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/*********************************************** | ||
DAVE PHP API | ||
https://github.com/evantahler/PHP-DAVE-API | ||
Evan Tahler | 2011 | ||
TASK | ||
***********************************************/ | ||
|
||
class CleanSessions extends task | ||
{ | ||
protected static $description = "I will remove old entries from the SESSIONS table in the DB"; | ||
|
||
public function run($PARAMS = array()) | ||
{ | ||
global $CONFIG, $DBObj; | ||
|
||
if (self::check_DBObj()) | ||
{ | ||
$SQL= 'DELETE FROM `SESSIONS` WHERE (`created_at` < "'.date('Y-m-d H:i:s',(time() - $CONFIG['SessionAge'])).'") ;'; | ||
$DBObj->Query($SQL); | ||
$this->task_log('Deleted '.$DBObj->NumRowsEffected()." entries from the SESSIONS Table in the DB"); | ||
} | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.