Permalink
Browse files

refs #2 - attempt to fix a bug on cronLogs file creation

  • Loading branch information...
1 parent a23bd3b commit b1f661cef3102f9e3be6718ff94fb3984e83a603 @n1k0 n1k0 committed Dec 17, 2009
Showing with 27 additions and 17 deletions.
  1. +3 −9 CHANGELOG
  2. +23 −7 lib/TwitterBotsFarm.class.php
  3. +1 −1 test/unit/TwitterBotsFarmTest.php
View
@@ -1,21 +1,15 @@
-v2.0.0alpha3 - 08/05/2009
+v2.0.0alpha1 - 2009-12-16
* Added a command line interface executable to manipulate phptwitterbot
-
-v2.0.0alpha2 - 06/05/2009
-
* Replaced Twitter class by TwitterApiClient, able to use Identi.ca twitter-compliant API
* Added TwitterBot::processBotTimeline() method
* More tests added
-
-v2.0.0alpha1 - 05/31/2009
-
* Added Tweet class to represent a tweet
* Added TwitterBotsFarm class to handle multiple bots configurations, in a fancy YAML file
* Added periodicity check for execution
* Added a way to process direct messages
* Added checks when following followers
-v1.0.0 - 04/22/2009
+v1.0.0 - 2009-04-22
- * Created initial version
+ * Created initial 1.0 version
@@ -30,7 +30,9 @@
*/
class TwitterBotsFarm
{
- const MIN_PERIODICITY = 60;
+ const
+ CRONLOG_DEFAULT_FILENAME = '.phptwitterbot.cronlogs.log',
+ MIN_PERIODICITY = 60;
public static
$botClass = 'TwitterBot';
@@ -248,9 +250,23 @@ protected function loadCronLogs()
{
$this->debug('Loading cronLogs...');
- if (is_null($this->cronLogsFile))
+ $this->checkCronLogsFile();
+
+ $data = sfYaml::load($this->cronLogsFile);
+
+ $this->cronLogs = is_array($data) ? $data : array();
+ }
+
+ /**
+ * Checks the cron logs file, create a default one if none or invalid provided
+ *
+ * @throws RuntimeException on failure
+ */
+ public function checkCronLogsFile()
+ {
+ if (!$this->cronLogsFile)
{
- $this->cronLogsFile = realpath(sys_get_temp_dir() . DIRECTORY_SEPARATOR . '.phptwitterbot.cronlogs.log');
+ $this->cronLogsFile = tempnam(sys_get_temp_dir(), self::CRONLOG_DEFAULT_FILENAME);
$this->debug(sprintf('Default cronLogs file set to "%s"', $this->cronLogsFile));
}
@@ -266,10 +282,6 @@ protected function loadCronLogs()
{
throw new RuntimeException(sprintf('cronLogs file "%s" is not writeable', $this->cronLogsFile));
}
-
- $data = sfYaml::load($this->cronLogsFile);
-
- $this->cronLogs = is_array($data) ? $data : array();
}
/**
@@ -359,6 +371,8 @@ protected function updateCronLogs($botName, $methodName)
{
$this->debug(sprintf('Updating cronlog for bot "%s" for "%s" method', $botName, $methodName));
+ $this->checkCronLogsFile();
+
if (!array_key_exists($botName, $this->cronLogs))
{
$this->cronLogs[$botName] = array();
@@ -376,6 +390,8 @@ protected function writeCronLogsFile()
{
$this->debug(sprintf('Writing cronLogs into file "%s"', $this->cronLogsFile));
+ $this->checkCronLogsFile();
+
if (!@file_put_contents($this->cronLogsFile, sfYaml::dump($this->cronLogs)))
{
throw new RuntimeException(sprintf('Unable to write data in cronLogs file "%s"', $this->cronLogs));
@@ -10,7 +10,7 @@ public function __construct($configFile, $cronLogsFile = null, $debug = false)
{
$this->purgeCronLogsFile();
- parent::__construct($configFile, realpath(sys_get_temp_dir().DIRECTORY_SEPARATOR.'.cronlogs.test.log'), false);
+ parent::__construct($configFile, tempnam(sys_get_temp_dir(), 'test_cronlogs'), false);
}
public function getCronLogsFile()
{

0 comments on commit b1f661c

Please sign in to comment.