class Horde_Db_Migration_Base
{
/**
- * Print messages as migrations happen
- * @var boolean
- */
- public $verbose = false;
-
- /**
* The migration version
* @var integer
*/
public $version = null;
/**
+ * The logger
+ * @var Horde_Log_Logger
+ */
+ protected $_logger;
+
+ /**
* Database connection adapter
* @var Horde_Db_Adapter_Base
*/
/**
*/
- public function __construct(Horde_Db_Adapter_Base $connection, $version = null, $verbose = false)
+ public function __construct(Horde_Db_Adapter_Base $connection, $version = null)
{
$this->_connection = $connection;
$this->version = $version;
- $this->verbose = $verbose;
}
if ($direction == 'up') {
$this->announce("migrated (" . sprintf("%.4fs", $time) . ")");
- $this->write();
+ $this->log();
}
if ($direction == 'down') {
$this->announce("reverted (" . sprintf("%.4fs", $time) . ")");
- $this->write();
+ $this->log();
}
return $result;
}
/**
* @param string $text
*/
- public function write($text = '')
+ public function log($text = '')
{
- if ($this->verbose) {
- echo "$text\n";
+ if ($this->_logger) {
+ $this->_logger->info($text);
}
}
/**
+ * @param Horde_Log_Logger $logger
+ */
+ public function setLogger($logger)
+ {
+ $this->_logger = $logger;
+ }
+
+ /**
* Announce migration
* @param string $message
*/
$text = "$this->version " . get_class($this) . ": $message";
$length = 75 - strlen($text) > 0 ? 75 - strlen($text) : 0;
- $this->write(sprintf("== %s %s", $text, str_repeat('=', $length)));
+ $this->log(sprintf("== %s %s", $text, str_repeat('=', $length)));
}
/**
*/
public function say($message, $subitem = false)
{
- $this->write(($subitem ? " ->" : "--") . " $message");
+ $this->log(($subitem ? " ->" : "--") . " $message");
}
-
}