Skip to content

Commit

Permalink
Merge branch 'master' into feature/svg-chart-tooltips-7024
Browse files Browse the repository at this point in the history
  • Loading branch information
majentsch committed Sep 3, 2014
2 parents cd8416b + 1d81211 commit da85112
Show file tree
Hide file tree
Showing 50 changed files with 1,479 additions and 720 deletions.
5 changes: 5 additions & 0 deletions application/controllers/ErrorController.php
Expand Up @@ -4,6 +4,7 @@

// namespace Icinga\Application\Controllers;

use Icinga\Logger\Logger;
use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga;

Expand All @@ -21,6 +22,10 @@ public function errorAction()
{
$error = $this->_getParam('error_handler');
$exception = $error->exception;

Logger::error($exception);
Logger::error('Stacktrace: %s', $exception->getTraceAsString());

switch ($error->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
Expand Down
22 changes: 20 additions & 2 deletions application/controllers/StaticController.php
Expand Up @@ -2,10 +2,11 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

use Zend_Controller_Action_Exception as ActionException;
use Icinga\Web\Controller\ActionController;
use Icinga\Application\Icinga;
use Icinga\Logger\Logger;
use Icinga\Web\FileCache;
use Zend_Controller_Action_Exception as ActionException;

/**
* Delivery static content to clients
Expand All @@ -30,8 +31,25 @@ public function init()

public function gravatarAction()
{
$cache = FileCache::instance();
$filename = md5(strtolower(trim($this->_request->getParam('email'))));
$cacheFile = 'gravatar-' . $filename;
header('Cache-Control: public');
header('Pragma: cache');
if ($etag = $cache->etagMatchesCachedFile($cacheFile)) {
header("HTTP/1.1 304 Not Modified");
return;
}

header('Content-Type: image/jpg');
$img = file_get_contents('http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->_request->getParam('email')))) . '?s=200&d=mm');
if ($cache->has($cacheFile)) {
header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"');
$cache->send($cacheFile);
return;
}
$img = file_get_contents('http://www.gravatar.com/avatar/' . $filename . '?s=200&d=mm');
$cache->store($cacheFile, $img);
header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"');
echo $img;
}

Expand Down
49 changes: 46 additions & 3 deletions library/Icinga/Application/ApplicationBootstrap.php
Expand Up @@ -452,9 +452,8 @@ protected function setupTimezone()
*/
protected function setupInternationalization()
{
$localeDir = $this->getApplicationDir('locale');
if (file_exists($localeDir) && is_dir($localeDir)) {
Translator::registerDomain(Translator::DEFAULT_DOMAIN, $localeDir);
if ($this->hasLocales()) {
Translator::registerDomain(Translator::DEFAULT_DOMAIN, $this->getLocaleDir());
}

try {
Expand All @@ -469,4 +468,48 @@ protected function setupInternationalization()

return $this;
}

/**
* @return string Our locale directory
*/
public function getLocaleDir()
{
return $this->getApplicationDir('locale');
}

/**
* return bool Whether Icinga Web has translations
*/
public function hasLocales()
{
$localedir = $this->getLocaleDir();
return file_exists($localedir) && is_dir($localedir);
}

/**
* List all available locales
*
* NOTE: Might be a candidate for a static function in Translator
*
* return array Locale list
*/
public function listLocales()
{
$locales = array();
if (! $this->hasLocales()) {
return $locales;
}
$localedir = $this->getLocaleDir();

$dh = opendir($localedir);
while (false !== ($file = readdir($dh))) {
$filename = $localedir . DIRECTORY_SEPARATOR . $file;
if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $file) && is_dir($filename)) {
$locales[] = $file;
}
}
closedir($dh);
sort($locales);
return $locales;
}
}
12 changes: 12 additions & 0 deletions library/Icinga/Application/Config.php
Expand Up @@ -85,6 +85,18 @@ public static function app($configname = 'config', $fromDisk = false)
return self::$app[$configname];
}

/**
* Set module config
*
* @param string $moduleName
* @param string $configName
* @param Zend_Config $config
*/
public static function setModuleConfig($moduleName, $configName, Zend_Config $config)
{
self::$modules[$moduleName][$configName] = $config;
}

/**
* Retrieve a module config instance
*
Expand Down
49 changes: 39 additions & 10 deletions library/Icinga/Application/Modules/Module.php
Expand Up @@ -177,7 +177,6 @@ public function getPaneItems()
/**
* Add a pane to dashboard
*
* @param $id
* @param $name
* @return Pane
*/
Expand All @@ -201,21 +200,19 @@ public function getMenuItems()
/**
* Add a menu Section to the Sidebar menu
*
* @param string $id
* @param string $name
* @param $name
* @param array $properties
* @return mixed
*/
protected function menuSection($id, $name, array $properties = array())
protected function menuSection($name, array $properties = array())
{
if (array_key_exists($id, $this->menuItems)) {
$this->menuItems[$id]->setProperties($properties);
if (array_key_exists($name, $this->menuItems)) {
$this->menuItems[$name]->setProperties($properties);
} else {
$this->menuItems[$id] = new Menu($id, new Zend_Config($properties));
$this->menuItems[$id]->setTitle($name);
$this->menuItems[$name] = new Menu($name, new Zend_Config($properties));
}

return $this->menuItems[$id];
return $this->menuItems[$name];
}

/**
Expand Down Expand Up @@ -711,12 +708,44 @@ protected function registerAutoloader()
*/
protected function registerLocales()
{
if (file_exists($this->localedir) && is_dir($this->localedir)) {
if ($this->hasLocales()) {
Translator::registerDomain($this->name, $this->localedir);
}
return $this;
}

/**
* return bool Whether this module has translations
*/
public function hasLocales()
{
return file_exists($this->localedir) && is_dir($this->localedir);
}

/**
* List all available locales
*
* return array Locale list
*/
public function listLocales()
{
$locales = array();
if (! $this->hasLocales()) {
return $locales;
}

$dh = opendir($this->localedir);
while (false !== ($file = readdir($dh))) {
$filename = $this->localedir . DIRECTORY_SEPARATOR . $file;
if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $file) && is_dir($filename)) {
$locales[] = $file;
}
}
closedir($dh);
sort($locales);
return $locales;
}

/**
* Register web integration
*
Expand Down
22 changes: 0 additions & 22 deletions library/Icinga/Application/Web.php
Expand Up @@ -13,8 +13,6 @@
use Icinga\Web\Request;
use Icinga\Web\Response;
use Icinga\Web\View;
use Icinga\Web\Session\Session as BaseSession;
use Icinga\Web\Session;
use Icinga\User;
use Icinga\Util\Translator;
use Icinga\Util\DateTimeFactory;
Expand Down Expand Up @@ -59,13 +57,6 @@ class Web extends ApplicationBootstrap
*/
private $request;

/**
* Session object
*
* @var BaseSession
*/
private $session;

/**
* User object
*
Expand All @@ -92,7 +83,6 @@ protected function bootstrap()
->setupErrorHandling()
->loadConfig()
->setupResourceFactory()
->setupSession()
->setupUser()
->setupTimezone()
->setupLogger()
Expand Down Expand Up @@ -172,7 +162,6 @@ private function setupZendMvc()

$this->setupFrontController();
$this->setupViewRenderer();

return $this;
}

Expand All @@ -192,17 +181,6 @@ private function setupUser()
return $this;
}

/**
* Initialize a session provider
*
* @return self
*/
private function setupSession()
{
$this->session = Session::create();
return $this;
}

/**
* Inject dependencies into request
*
Expand Down
12 changes: 12 additions & 0 deletions library/Icinga/Data/Db/DbQuery.php
Expand Up @@ -89,6 +89,17 @@ protected function dbSelect()
public function getSelectQuery()
{
$select = $this->dbSelect();

// Add order fields to select for postgres distinct queries (#6351)
if ($this->hasOrder()
&& $this->getDatasource()->getDbType() === 'pgsql'
&& $select->getPart(Zend_Db_Select::DISTINCT) === true) {
foreach ($this->getOrder() as $fieldAndDirection) {
list($alias, $field) = explode('.', $fieldAndDirection[0]);
$this->columns[$field] = $fieldAndDirection[0];
}
}

$select->columns($this->columns);
$this->applyFilterSql($select);

Expand All @@ -102,6 +113,7 @@ public function getSelectQuery()
);
}
}

return $select;
}

Expand Down
4 changes: 2 additions & 2 deletions library/Icinga/Data/Filter/Filter.php
Expand Up @@ -132,12 +132,12 @@ public static function where($col, $filter)
public static function expression($col, $op, $expression)
{
switch ($op) {
case '=': return new FilterEqual($col, $op, $expression);
case '=': return new FilterMatch($col, $op, $expression);
case '<': return new FilterLessThan($col, $op, $expression);
case '>': return new FilterGreaterThan($col, $op, $expression);
case '>=': return new FilterEqualOrGreaterThan($col, $op, $expression);
case '<=': return new FilterEqualOrLessThan($col, $op, $expression);
case '!=': return new FilterNotEqual($col, $op, $expression);
case '!=': return new FilterMatchNot($col, $op, $expression);
default: throw new ProgrammingError(
'There is no such filter sign: %s',
$op
Expand Down
22 changes: 22 additions & 0 deletions library/Icinga/Data/Filter/FilterMatch.php
@@ -0,0 +1,22 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Data\Filter;

class FilterMatch extends FilterExpression
{
public function matches($row)
{
$expression = (string) $this->expression;
if (strpos($expression, '*') === false) {
return (string) $row->{$this->column} === $expression;
} else {
$parts = array();
foreach (preg_split('/\*/', $expression) as $part) {
$parts[] = preg_quote($part);
}
return preg_match('/^' . implode('.*', $parts) . '$/', $row->{$this->column});
}
}
}
22 changes: 22 additions & 0 deletions library/Icinga/Data/Filter/FilterMatchNot.php
@@ -0,0 +1,22 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Data\Filter;

class FilterMatchNot extends FilterExpression
{
public function matches($row)
{
$expression = (string) $this->expression;
if (strpos($expression, '*') === false) {
return (string) $row->{$this->column} !== $expression;
} else {
$parts = array();
foreach (preg_split('/\*/', $expression) as $part) {
$parts[] = preg_quote($part);
}
return ! preg_match('/^' . implode('.*', $parts) . '$/', $row->{$this->column});
}
}
}
13 changes: 13 additions & 0 deletions library/Icinga/Data/Filter/FilterNotEqual.php
@@ -0,0 +1,13 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Data\Filter;

class FilterNotEqual extends FilterExpression
{
public function matches($row)
{
return (string) $row->{$this->column} !== (string) $this->expression;
}
}
Expand Up @@ -2,9 +2,9 @@

namespace Icinga\Protocol\File;

use RuntimeException;
use Icinga\Exception\IcingaException;

/**
* Exception thrown if a file reader specific error occurs
*/
class FileReaderException extends RuntimeException {}
class FileReaderException extends IcingaException {}
2 changes: 1 addition & 1 deletion library/Icinga/Protocol/File/Reader.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(Zend_Config $config)
{
foreach (array('filename', 'fields') as $key) {
if (! isset($config->{$key})) {
throw new FileReaderException('The directive `' . $key . '\' is required');
throw new FileReaderException('The directive `%s\' is required', $key);
}
}
$this->fields = $config->fields;
Expand Down

0 comments on commit da85112

Please sign in to comment.