/** * Commits the changes to the adapter and parses the result. * If any errors occurred then optionally log them and throw an exception. * * @param SHAdapter $adapter Adapter. * @param boolean $log Log any errors directly to SHLog. * @param boolean $throw Throws an exception on error OR return array on error. * * @return true|SHAdapterResponseCommits * * @since 2.1 */ public static function commitChanges($adapter, $log = false, $throw = true) { $results = $adapter->commitChanges(); $adapterName = $adapter->getName(); if ($log) { // Lets log all the commits foreach ($results->getCommits() as $commit) { if ($commit->status === JLog::INFO) { SHLog::addAdapter($adapter, $commit->getSummary(), 10634, JLog::INFO); } else { SHLog::addAdapter($adapter, $commit->getSummary(), 10636, JLog::ERROR); SHLog::add($commit->exception, 10637, JLog::ERROR, $adapterName); } } } // Check if any of the commits failed if (!$results->status) { if ($throw) { throw new RuntimeException(JText::_('LIB_SHADAPTERHELPER_ERR_10638'), 10638); } else { return $results; } } return true; }
/** * Constructor * * @param SHAdapter $adapter Adapter for log. * @param string $message The message to log. * @param integer $id Internal ID code of entry. * @param string $priority Message priority based on {$this->priorities}. * @param string $category Type of entry. * @param string $date Date of entry (defaults to now if not specified or blank). * * @since 2.1 */ public function __construct(SHAdapter $adapter, $message, $id, $priority = JLog::INFO, $category = null, $date = null) { // Get the adapter type and transform it to human readable $type = $adapter::TYPE; if ($type === SHAdapter::TYPE_USER) { $this->adapterType = 'User'; $this->adapterId = $adapter->loginUser; } elseif ($type === SHAdapter::TYPE_GROUP) { $this->adapterType = 'Group'; //$this->adapterId = $adapter->getId(); } else { $this->adapterType = 'Generic'; $this->adapterId = 'N/A'; } // Domain of the adapter user/group $this->adapterDomain = $adapter->getDomain(); if (empty($category)) { $category = strtolower($adapter->getName()); } parent::__construct($id, $message, $priority, $category, $date); // Creates a one liner for everything $this->full = JText::sprintf('(%1$s::%2$s::%3$s) %4$s', $this->adapterType, $this->adapterDomain, $this->adapterId, $this->message); }
/** * Returns the name of this adapter. * * @param string $name An optional string to compare against the adapter name. * * @return string|false Adapter name or False on non-matching parameter. * * @since 2.0 * @deprecated [2.1] Use SHUserAdapterLdap::getName instead */ public static function getType($name = null) { return parent::getName($name); }