Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved extra loggers to pandra-contrib repo, columncontainer cleanup

  • Loading branch information...
commit 59719b65923ee27f93a5afeef48b523ecdb3cf22 1 parent 1bc509b
@mjpearson authored
View
49 lib/ColumnContainer.class.php
@@ -437,9 +437,8 @@ public function getReversed() {
}
private function _setStartFinish($value, $attrib = '_start') {
- if (($this->_containerType == self::TYPE_UUID) ) {
- $this->$attrib = $this->typeConvert($value, self::CONTEXT_BIN);
- } elseif (($this->_containerType == self::TYPE_LONG)) {
+ if ($this->_containerType == self::TYPE_UUID ||
+ $this->_containerType == self::TYPE_LONG) {
$this->$attrib = $this->typeConvert($value, self::CONTEXT_BIN);
} else {
$this->$attrib = $value;
@@ -475,21 +474,25 @@ public function getFinish() {
/**
* Converts the given column name to it's expected container type context (UUID or String)
*
- * This stub can also potentially handle long and utf8 cf types
+ * This stub can also potentially handle utf8 cf types
*
* @param string $columnName column name
* @param int $toFmt convert to type CONTEXT_BIN OR CONTEXT_STRING
* @return mixed converted column name
*/
protected function typeConvert($columnName, $toFmt) {
+ // @todo move to generic helper
$bin = UUID::isBinary($columnName);
- if (($this->_containerType == self::TYPE_UUID) ) {
- // Save accidental double-conversions on binaries
- if (($bin && $toFmt == self::CONTEXT_BIN) ||
- (!$bin && $toFmt == self::CONTEXT_STRING)) {
+ // Save accidental double-conversions on binaries
+ if (($bin && $toFmt == self::CONTEXT_BIN) ||
+ (!$bin && $toFmt == self::CONTEXT_STRING)) {
return $columnName;
- } elseif (!$bin && !UUID::validUUID($columnName)) {
+ }
+
+ if (($this->_containerType == self::TYPE_UUID) ) {
+
+ if (!$bin && !UUID::validUUID($columnName)) {
throw new RuntimeException('Column Name ('.$columnName.') cannot be converted');
}
@@ -500,20 +503,16 @@ protected function typeConvert($columnName, $toFmt) {
}
} else if ($this->_containerType == self::TYPE_LONG) {
- // Save accidental double-conversions on binaries
- if (($bin && $toFmt == self::CONTEXT_BIN) ||
- (!$bin && $toFmt == self::CONTEXT_STRING)) {
- return $columnName;
-
- // unpack the long
- } elseif ($bin && $toFmt == self::CONTEXT_STRING) {
+ // unpack the long
+ if ($bin && $toFmt == self::CONTEXT_STRING) {
$columnName = array_pop(unpack('N', $columnName));
- // pack the long
+ // pack the long
} elseif (!$bin && $toFmt == self::CONTEXT_BIN) {
$columnName = pack('NN', $columnName, 0);
}
}
+
return $columnName;
}
@@ -526,11 +525,15 @@ protected function typeConvert($columnName, $toFmt) {
*/
public function addColumn($columnName, $typeDef = array(), $callbackOnSave = NULL) {
- // can't use array_key_exists - it truncates floats on 32 bit systems
- $foundKey = FALSE;
- foreach ($this->_columns as $key => $value) {
- $foundKey = ($key == $columnName);
- if ($foundKey) break;
+ // can't use array_key_exists for longs - floats are truncated
+ if ($this->_containerType == self::TYPE_LONG) {
+ $foundKey = FALSE;
+ foreach ($this->_columns as $key => $value) {
+ $foundKey = ($key == $columnName);
+ if ($foundKey) break;
+ }
+ } else {
+ $foundKey = array_key_exists($columnName, $this->_columns);
}
if (!$foundKey) {
@@ -543,7 +546,7 @@ public function addColumn($columnName, $typeDef = array(), $callbackOnSave = NUL
// pre-save callback
if (!empty($callbackOnSave)) $this->getColumn($columnName)->setCallback($callbackOnSave);
- // php sucks balls, lets lose our precision.
+ // @todo php sucks balls, lets lose our precision.
if (!PANDRA_64 && $this->_containerType == self::TYPE_LONG) {
$columnName = (int) $columnName;
}
View
10 lib/Core.class.php
@@ -214,7 +214,7 @@ static public function connect($connectionID, $host, $keySpace = self::DEFAULT_P
try {
// check connectionid hasn't been marked as down
- if (self::priorFail($connectionID)) {
+ if (self::_priorFail($connectionID)) {
self::registerError($host.'/'.$port.' is marked DOWN', PandraLog::LOG_CRIT);
} else {
// if the connection exists but it is closed, return (getClient will open)
@@ -459,7 +459,7 @@ static public function getClient($writeMode = FALSE, $keySpace = self::DEFAULT_P
case self::MODE_ACTIVE :
default :
// If we're trying to use an explicit connection id and it's down, then bail
- if (self::priorFail(self::$_activeNode)) {
+ if (self::_priorFail(self::$_activeNode)) {
return NULL;
}
@@ -476,7 +476,7 @@ static public function getClient($writeMode = FALSE, $keySpace = self::DEFAULT_P
} catch (TException $te) {
if (++self::$_socketPool[self::$_activePool][self::$_activeNode]['retries'] > self::$_maxRetries) {
- self::setLastFail();
+ self::_setLastFail();
unset(self::$_socketPool[self::$_activePool][self::$_activeNode]);
}
@@ -507,7 +507,7 @@ static private function _authOpen(TBufferedTransport &$transport, $keySpace) {
* Stores the last failure time for a node in the cache (Memcached takes precedence)
* @param string $connectionID connection id
*/
- static private function setLastFail($connectionID = NULL) {
+ static private function _setLastFail($connectionID = NULL) {
$key = 'lastfail_'.md5($connectionID === NULL ? self::$_activeNode : $connectionID);
if (self::$_memcachedAvailable && self::$_memCached instanceof Memcached) {
self::$_memcached->set($key, time(), self::$_retryCooldown);
@@ -521,7 +521,7 @@ static private function setLastFail($connectionID = NULL) {
* @param string $connectionID connection id
* @return bool node marked down
*/
- static private function priorFail($connectionID = NULL) {
+ static private function _priorFail($connectionID = NULL) {
$key = 'lastfail_'.md5($connectionID === NULL ? self::$_activeNode : $connectionID);
$ok = FALSE;
if (self::$_memcachedAvailable && self::$_memCached instanceof Memcached) {
View
63 lib/logging/LoggerFirePHP.class.php
@@ -1,63 +0,0 @@
-<?php
-/**
- * PandraLoggerFirePHP
- *
- * FirePHP implementation of PandraLogger. Handles all priority levels
- * Requires the FirePHP classes be included prior to call
- *
- * @author Michael Pearson <pandra-support@phpgrease.net>
- * @copyright 2010 phpgrease.net
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
- * @version 0.2
- * @package pandra
- */
-class PandraLoggerFirePHP implements PandraLogger {
-
- private $_isOpen = FALSE;
-
- private $_fb = NULL;
-
- public function __construct(array $params) {
- $this->_isOpen = class_exists('FB');
- if ($this->_isOpen) {
- $this->_fb = FirePHP::getInstance(true);
- }
- return $this->_isOpen;
- }
-
- public function isOpen() {
- return $this->_isOpen;
- }
-
- /**
- * FirePHP will log for anything
- * @param int $priority requested priority log
- * @return boolean this logger will log for priority
- */
- public function isPriorityLogger($priority) {
- return TRUE;
- }
-
- public function execute($priority, $message) {
- if ($this->isPriorityLogger($priority) && $this->_isOpen) {
- switch ($priority) {
- case PandraLog::LOG_NOTICE :
- $this->_fb->log($message);
- break;
- case PandraLog::LOG_DEBUG :
- case PandraLog::LOG_INFO :
- $this->_fb->info($message);
- break;
- case PandraLog::LOG_WARNING :
- $this->_fb->warn($message);
- break;
- default:
- $this->_fb->error($message);
- break;
- }
- return TRUE;
- }
- return FALSE;
- }
-}
-?>
View
137 lib/logging/LoggerMail.class.php
@@ -1,137 +0,0 @@
-<?php
-/**
- * PandraLoggerMail
- *
- * Mail implementation of PandraLogger. Handles all log messages crit to emergency
- *
- * @author Michael Pearson <pandra-support@phpgrease.net>
- * @copyright 2010 phpgrease.net
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
- * @version 0.2
- * @package pandra
- */
-class PandraLoggerMail implements PandraLogger {
-
- private $_mailFrom = '';
-
- private $_mailTo = '';
-
- private $_subject = '';
-
- private $_maxPriority = PandraLog::LOG_CRIT;
-
- private $_sendDelay = FALSE;
-
- private $_headers = '';
-
- private $_messages = '';
-
- /**
- *
- * @param array $params 'from', 'to', 'subject', 'delay' (sends on destruct)
- */
- public function __construct(array $params) {
- if (isset($params['from'])) $this->_mailFrom = $params['from'];
- if (isset($params['to'])) $this->_mailFrom = $params['to'];
- if (isset($params['subject'])) $this->_mailFrom = $params['subject'];
- if (isset($params['delay'])) $this->_sendDelay = $params['delay'];
- }
-
- public function isOpen() {
- return function_exists('mail');
- }
-
- /**
- * Mail shouldn't handle notices, info's etc.
- * @param int $priority requested priority log
- * @return boolean this logger will log for priority
- */
- public function isPriorityLogger($priority) {
- return ($priority <= $this->_maxPriority);
- }
-
- /**
- * mailFrom mutator
- * @param string $mailFrom set the email from address
- */
- public function setMailFrom($mailFrom) {
- $this->_mailFrom = $mailFrom;
- }
-
- /**
- * mailFrom accessor
- * @return string email from address
- */
- public function getMailFrom() {
- return $this->_mailFrom;
- }
-
- /**
- * mailTo mutator
- * @param string $mailTo set the email to address
- */
- public function setMailTo($mailTo) {
- $this->_mailTo = $mailTo;
- }
-
- /**
- * mailTo accessor
- * @return string email to address
- */
- public function getMailTo() {
- return $this->_mailTo;
- }
-
-
- /**
- * subject mutator
- * @param string $subject set the email subject line
- */
- public function setSubject($subject) {
- $this->_subject = $subject;
- }
-
- /**
- * subject accessor
- * @return string email subject line
- */
- public function getSubject() {
- return $this->_subject;
- }
-
- public function execute($priority, $message) {
- if ($this->isPriorityLogger($priority) && $this->_isOpen) {
- $this->_message .= $message;
- if (!$this->_sendDelay) {
- return $this->sendMail();
- }
- return TRUE;
- }
- return FALSE;
- }
-
- public function sendMail() {
- if (!empty($this->_messages)) {
- $this->subject = '['.strtoupper(PandraLog::$priorityStr[$priority]).'] '.$this->_subject;
-
- if (!empty($this->_mailFrom)) {
- $this->_headers = "From: ".$this->_mailFrom."\r\n" .
- "Reply-To: ".$this->_mailFrom."\r\n";
- }
- $this->_headers .= "X-Mailer: PHP/".phpversion();
- return mail($this->_mailTo, $this->_subject, $this->messages, $this->_headers);
- }
- return FALSE;
- }
-
- public function close() {
- if ($this->_sendDelay) {
- $this->sendMail();
- }
- }
-
- public function __destruct() {
- $this->close();
- }
-}
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.