/** * @param $filename * @return mixed|void */ public function optimiseImage($filename) { if (file_exists($filename)) { $size = @getimagesize($filename); if (!is_array($size)) { if (null !== $this->logger) { $this->logger->error("Error reading file when attempting to optimize"); } return; } list($width, $height, $type, $attr) = $size; $commands = $this->getCommands($filename, $type = $this->getImageType($type)); foreach ($commands as $command) { try { $process = $this->execCommand($command); $successful = in_array($process->getExitCode(), $this->config->get('successStatuses')); if (null !== $this->logger && (!$successful || $this->config->get('debug'))) { // Do this so the log isn't treated as a web request in raven $requestMethod = $_SERVER['REQUEST_METHOD']; unset($_SERVER['REQUEST_METHOD']); $logType = $successful ? 'info' : 'error'; $this->logger->{$logType}("SilverStripe \"{$type}\" optimisation {$logType}", array('command' => $command, 'exitCode' => $process->getExitCode(), 'output' => $process->getOutput(), 'errorOutput' => $process->getErrorOutput())); $_SERVER['REQUEST_METHOD'] = $requestMethod; } } catch (\Exception $e) { if (null !== $this->logger) { $this->logger->error("SilverStripe \"{$type}\" optimisation exception", array('exception' => $e)); } } } } }
public function normalize() { $this->_loadLogger(); $this->_loadAttributeDefinitions(); $newAttributes = array(); /** * @var string $attributeName * @var array $attributeValues */ foreach ($this->_attributes as $attributeName => $attributeValues) { // Not defined in SURFconext attributes... can't find any aliases. if (!isset($this->_definitions[$attributeName])) { $newAttributes[$attributeName] = $attributeValues; continue; } // Traverse aliases to actual definition $originalAttributeName = $attributeName; $attributesSeen = array($attributeName); while (isset($this->_definitions[$attributeName]) && !is_array($this->_definitions[$attributeName])) { // Circular dependency check (Topological sorting) if (in_array($this->_definitions[$attributeName], $attributesSeen)) { $this->_logger->error("Circular dependency detected in tree: " . implode(' => ', $attributesSeen) . ' => ' . $this->_definitions[$attributeName] . " reverting back to original '{$originalAttributeName}'"); $attributeName = $originalAttributeName; break; } $attributeName = $this->_definitions[$attributeName]; $attributesSeen[] = $attributeName; } if ($attributeName !== $originalAttributeName) { $this->_logger->debug("Attribute Normalization: '{$originalAttributeName}' resolves to '{$attributeName}'"); } // Whoa, a resolved alias that doesn't have a definition? if (!isset($this->_definitions[$attributeName])) { $this->_logger->error("Attribute Normalization: Attribute '{$originalAttributeName}' resolved to '{$attributeName}'" . " but this does not have a definition? Skipping this attribute and it's values"); } if (!isset($newAttributes[$attributeName])) { $newAttributes[$attributeName] = $attributeValues; continue; } // Note that array_diff does not work recursively $valuesDiff = array_diff($newAttributes[$attributeName], $attributeValues); if (empty($valuesDiff)) { $this->_logger->debug("Attribute Normalization: '{$attributeName}' (originally '{$attributeName}') " . "already exists with the same value... doing nothing."); continue; } else { $this->_logger->notice("Attribute Normalization: '{$attributeName}' (originally '{$attributeName}') " . "already exists with a different value... overwriting."); $newAttributes[$attributeName] = $attributeValues; } } return $newAttributes; }