本文整理汇总了PHP中OCP\ILogger::error方法的典型用法代码示例。如果您正苦于以下问题:PHP ILogger::error方法的具体用法?PHP ILogger::error怎么用?PHP ILogger::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\ILogger
的用法示例。
在下文中一共展示了ILogger::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onError
public static function onError($number, $message, $file, $line)
{
if (error_reporting() === 0) {
return;
}
$msg = $message . ' at ' . $file . '#' . $line;
self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
}
示例2: afterException
/**
* Log error message and return a response which can be displayed to the user
*
* @param \OCP\AppFramework\Controller $controller
* @param string $methodName
* @param \Exception $exception
* @return JSONResponse
*/
public function afterException($controller, $methodName, \Exception $exception)
{
$this->logger->error($exception->getMessage(), ['app' => $this->appName]);
if ($exception instanceof HintException) {
$message = $exception->getHint();
} else {
$message = $exception->getMessage();
}
return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
}
示例3: schedule
/**
* Event handler for the 'schedule' event.
*
* @param ITip\Message $iTipMessage
* @return void
*/
function schedule(ITip\Message $iTipMessage)
{
// Not sending any emails if the system considers the update
// insignificant.
if (!$iTipMessage->significantChange) {
if (!$iTipMessage->scheduleStatus) {
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
}
return;
}
$summary = $iTipMessage->message->VEVENT->SUMMARY;
if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
return;
}
if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
return;
}
$sender = substr($iTipMessage->sender, 7);
$recipient = substr($iTipMessage->recipient, 7);
$senderName = $iTipMessage->senderName ? $iTipMessage->senderName : null;
$recipientName = $iTipMessage->recipientName ? $iTipMessage->recipientName : null;
$subject = 'SabreDAV iTIP message';
switch (strtoupper($iTipMessage->method)) {
case 'REPLY':
$subject = 'Re: ' . $summary;
break;
case 'REQUEST':
$subject = $summary;
break;
case 'CANCEL':
$subject = 'Cancelled: ' . $summary;
break;
}
$contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
$message = $this->mailer->createMessage();
$message->setReplyTo([$sender => $senderName])->setTo([$recipient => $recipientName])->setSubject($subject)->setBody($iTipMessage->message->serialize(), $contentType);
try {
$failed = $this->mailer->send($message);
if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
} catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
}
示例4: getFile
/**
* @inheritdoc
*/
public function getFile($size)
{
$ext = $this->getExtension();
if ($size === -1) {
$path = 'avatar.' . $ext;
} else {
$path = 'avatar.' . $size . '.' . $ext;
}
try {
$file = $this->folder->get($path);
} catch (NotFoundException $e) {
if ($size <= 0) {
throw new NotFoundException();
}
$avatar = new OC_Image();
/** @var File $file */
$file = $this->folder->get('avatar.' . $ext);
$avatar->loadFromData($file->getContent());
if ($size !== -1) {
$avatar->resize($size);
}
try {
$file = $this->folder->newFile($path);
$file->putContent($avatar->data());
} catch (NotPermittedException $e) {
$this->logger->error('Failed to save avatar for ' . $this->user->getUID());
}
}
return $file;
}
示例5: getApplicationDownload
/**
* Get the download url for an application from the OCS server
* @param string $id
* @param array $targetVersion The target ownCloud version
* @return array|null an array of application data or null
*/
public function getApplicationDownload($id, array $targetVersion)
{
if (!$this->isAppStoreEnabled()) {
return null;
}
$url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1';
$client = $this->httpClientService->newClient();
try {
$response = $client->get($url, ['timeout' => 5, 'query' => ['version' => implode('x', $targetVersion)]]);
} catch (\Exception $e) {
$this->logger->error(sprintf('Could not get application download URL: %s', $e->getMessage()), ['app' => 'core']);
return null;
}
$data = $this->loadData($response->getBody(), 'application download URL');
if ($data === null) {
return null;
}
$tmp = $data->data->content;
$app = [];
if (isset($tmp->downloadlink)) {
$app['downloadlink'] = (string) $tmp->downloadlink;
} else {
$app['downloadlink'] = '';
}
return $app;
}
示例6: create
/**
* @NoAdminRequired
*
* @param string $username
* @param string $password
* @param array $groups
* @param string $email
* @return DataResponse
*/
public function create($username, $password, array $groups = array(), $email = '')
{
if ($email !== '' && !$this->mail->validateAddress($email)) {
return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
}
if (!$this->isAdmin) {
$userId = $this->userSession->getUser()->getUID();
if (!empty($groups)) {
foreach ($groups as $key => $group) {
if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) {
unset($groups[$key]);
}
}
}
if (empty($groups)) {
$groups = $this->subAdminFactory->getSubAdminsOfGroups($userId);
}
}
if ($this->userManager->userExists($username)) {
return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
}
try {
$user = $this->userManager->createUser($username, $password);
} catch (\Exception $exception) {
return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
}
if ($user instanceof User) {
if ($groups !== null) {
foreach ($groups as $groupName) {
$group = $this->groupManager->get($groupName);
if (empty($group)) {
$group = $this->groupManager->createGroup($groupName);
}
$group->addUser($user);
}
}
/**
* Send new user mail only if a mail is set
*/
if ($email !== '') {
$this->config->setUserValue($username, 'settings', 'email', $email);
// data for the mail template
$mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
$mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
$mailContent = $mail->render();
$mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
$plainTextMailContent = $mail->render();
$subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
try {
$this->mail->send($email, $username, $subject, $mailContent, $this->fromMailAddress, $this->defaults->getName(), 1, $plainTextMailContent);
} catch (\Exception $e) {
$this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
}
}
// fetch users groups
$userGroups = $this->groupManager->getUserGroupIds($user);
return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
}
return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
}
示例7: run
protected function run($argument)
{
$target = $argument['url'];
$source = $this->urlGenerator->getAbsoluteURL('/');
$source = rtrim($source, '/');
$token = $argument['token'];
try {
$result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
$status = $result->getStatusCode();
} catch (ClientException $e) {
$status = $e->getCode();
$this->logger->logException($e);
}
// if we received a unexpected response we try again later
if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
$this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', $argument);
} else {
// reset token if we received a valid response
$this->dbHandler->addToken($target, '');
}
if ($status === Http::STATUS_OK) {
$body = $result->getBody();
$result = json_decode($body, true);
if (isset($result['ocs']['data']['sharedSecret'])) {
$this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
} else {
$this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
}
}
}
示例8: __construct
/**
* @param ICalendar $calendar
*/
public function __construct(ICalendar $calendar)
{
$this->calendar = $calendar;
$backend = $this->calendar->getBackend();
if (!$backend instanceof IBackend) {
$identifier = implode('::', [$this->calendar->getUserId(), '?', $this->calendar->getPrivateUri()]);
$this->logger->error('Backend of calendar \'' . $identifier . '\' not found');
} else {
$this->cache = $backend->getObjectCache($calendar);
try {
$this->objectAPI = $backend->getObjectAPI($calendar);
} catch (BackendUtils\Exception $ex) {
//TODO
}
}
}
示例9: draft
/**
* @NoAdminRequired
*
* @param int $accountId
* @param string $subject
* @param string $body
* @param string $to
* @param string $cc
* @param string $bcc
* @param int $uid
* @param string $messageId
* @return JSONResponse
*/
public function draft($accountId, $subject, $body, $to, $cc, $bcc, $uid, $messageId)
{
if (is_null($uid)) {
$this->logger->info("Saving a new draft in account <{$accountId}>");
} else {
$this->logger->info("Updating draft <{$uid}> in account <{$accountId}>");
}
$account = $this->accountService->find($this->currentUserId, $accountId);
if ($account instanceof UnifiedAccount) {
list($account) = $account->resolve($messageId);
}
if (!$account instanceof Account) {
return new JSONResponse(array('message' => 'Invalid account'), Http::STATUS_BAD_REQUEST);
}
$message = $account->newMessage();
$message->setTo(Message::parseAddressList($to));
$message->setSubject($subject ?: '');
$message->setFrom($account->getEMailAddress());
$message->setCC(Message::parseAddressList($cc));
$message->setBcc(Message::parseAddressList($bcc));
$message->setContent($body);
// create transport and save message
try {
$newUID = $account->saveDraft($message, $uid);
} catch (\Horde_Exception $ex) {
$this->logger->error('Saving draft failed: ' . $ex->getMessage());
return new JSONResponse(['message' => $ex->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse(['uid' => $newUID]);
}
示例10: scan
/**
* @param string $dir
* @throws \OC\ForbiddenException
*/
public function scan($dir = '')
{
if (!Filesystem::isValidPath($dir)) {
throw new \InvalidArgumentException('Invalid path to scan');
}
$mounts = $this->getMounts($dir);
foreach ($mounts as $mount) {
if (is_null($mount->getStorage())) {
continue;
}
$storage = $mount->getStorage();
// if the home storage isn't writable then the scanner is run as the wrong user
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files'))) {
throw new ForbiddenException();
}
$relativePath = $mount->getInternalPath($dir);
$scanner = $storage->getScanner();
$scanner->setUseTransactions(false);
$this->attachListener($mount);
$isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider;
if (!$isDbLocking) {
$this->db->beginTransaction();
}
try {
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
} catch (StorageNotAvailableException $e) {
$this->logger->error('Storage ' . $storage->getId() . ' not available');
$this->logger->logException($e);
$this->emit('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', [$e]);
}
if (!$isDbLocking) {
$this->db->commit();
}
}
}
示例11: addToCache
private function addToCache(ICachedMountInfo $mount)
{
if ($mount->getStorageId() !== -1) {
$this->connection->insertIfNotExist('*PREFIX*mounts', ['storage_id' => $mount->getStorageId(), 'root_id' => $mount->getRootId(), 'user_id' => $mount->getUser()->getUID(), 'mount_point' => $mount->getMountPoint()], ['root_id', 'user_id']);
} else {
$this->logger->error('Error getting storage info for mount at ' . $mount->getMountPoint());
}
}
示例12: draft
/**
* @NoAdminRequired
*
* @param int $accountId
* @param string $subject
* @param string $body
* @param string $to
* @param string $cc
* @param string $bcc
* @param int $uid
* @param string $messageId
* @return JSONResponse
*/
public function draft($accountId, $subject, $body, $to, $cc, $bcc, $uid, $messageId)
{
if (is_null($uid)) {
$this->logger->info("Saving a new draft in account <{$accountId}>");
} else {
$this->logger->info("Updating draft <{$uid}> in account <{$accountId}>");
}
$account = $this->accountService->find($this->currentUserId, $accountId);
if ($account instanceof UnifiedAccount) {
list($account) = $account->resolve($messageId);
}
if (!$account instanceof Account) {
return new JSONResponse(array('message' => 'Invalid account'), Http::STATUS_BAD_REQUEST);
}
// get sender data
$headers = [];
$from = new Horde_Mail_Rfc822_Address($account->getEMailAddress());
$from->personal = $account->getName();
$headers['From'] = $from;
$headers['Subject'] = $subject;
if (trim($cc) !== '') {
$headers['Cc'] = trim($cc);
}
if (trim($bcc) !== '') {
$headers['Bcc'] = trim($bcc);
}
$headers['To'] = $to;
$headers['Date'] = Horde_Mime_Headers_Date::create();
// build mime body
$mail = new Horde_Mime_Mail();
$mail->addHeaders($headers);
$bodyPart = new Horde_Mime_Part();
$bodyPart->appendContents($body, ['encoding' => \Horde_Mime_Part::ENCODE_8BIT]);
$mail->setBasePart($bodyPart);
// create transport and save message
try {
// save the message in the drafts folder
$draftsFolder = $account->getDraftsFolder();
/** @var resource $raw */
$raw = $mail->getRaw();
$raw = stream_get_contents($raw);
$newUid = $draftsFolder->saveDraft($raw);
// delete old version if one exists
if (!is_null($uid)) {
$folderId = $draftsFolder->getFolderId();
$this->logger->debug("deleting outdated draft <{$uid}> in folder <{$folderId}>");
$draftsFolder->setMessageFlag($uid, \Horde_Imap_Client::FLAG_DELETED, true);
$account->deleteDraft($uid);
$this->logger->debug("draft <{$uid}> deleted");
}
} catch (\Horde_Exception $ex) {
$this->logger->error('Saving draft failed: ' . $ex->getMessage());
return new JSONResponse(['message' => $ex->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse(['uid' => $newUid]);
}
示例13: scan
/**
* @param string $dir
* @throws \OC\ForbiddenException
*/
public function scan($dir = '')
{
if (!Filesystem::isValidPath($dir)) {
throw new \InvalidArgumentException('Invalid path to scan');
}
$mounts = $this->getMounts($dir);
foreach ($mounts as $mount) {
if (is_null($mount->getStorage())) {
continue;
}
$storage = $mount->getStorage();
// if the home storage isn't writable then the scanner is run as the wrong user
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files'))) {
if ($storage->file_exists('') or $storage->getCache()->inCache('')) {
throw new ForbiddenException();
} else {
// if the root exists in neither the cache nor the storage the user isn't setup yet
break;
}
}
$relativePath = $mount->getInternalPath($dir);
$scanner = $storage->getScanner();
$scanner->setUseTransactions(false);
$this->attachListener($mount);
$isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider;
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'removeFromCache', function ($path) use($storage) {
$this->triggerPropagator($storage, $path);
});
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'updateCache', function ($path) use($storage) {
$this->triggerPropagator($storage, $path);
});
$scanner->listen('\\OC\\Files\\Cache\\Scanner', 'addToCache', function ($path) use($storage) {
$this->triggerPropagator($storage, $path);
});
if (!$isDbLocking) {
$this->db->beginTransaction();
}
try {
$storage->getPropagator()->beginBatch();
$scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
$cache = $storage->getCache();
if ($cache instanceof Cache) {
// only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner
$cache->correctFolderSize($relativePath);
}
$storage->getPropagator()->commitBatch();
} catch (StorageNotAvailableException $e) {
$this->logger->error('Storage ' . $storage->getId() . ' not available');
$this->logger->logException($e);
$this->emit('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', [$e]);
}
if (!$isDbLocking) {
$this->db->commit();
}
}
}
示例14: copyBetweenStorage
/**
* copy file between two storages
*
* @param Storage $sourceStorage
* @param string $sourceInternalPath
* @param string $targetInternalPath
* @param bool $preserveMtime
* @param bool $isRename
* @return bool
*/
private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename)
{
// first copy the keys that we reuse the existing file key on the target location
// and don't create a new one which would break versions for example.
$mount = $this->mountManager->findByStorageId($sourceStorage->getId());
if (count($mount) === 1) {
$mountPoint = $mount[0]->getMountPoint();
$source = $mountPoint . '/' . $sourceInternalPath;
$target = $this->getFullPath($targetInternalPath);
$this->copyKeys($source, $target);
} else {
$this->logger->error('Could not find mount point, can\'t keep encryption keys');
}
if ($sourceStorage->is_dir($sourceInternalPath)) {
$dh = $sourceStorage->opendir($sourceInternalPath);
$result = $this->mkdir($targetInternalPath);
if (is_resource($dh)) {
while ($result and ($file = readdir($dh)) !== false) {
if (!Filesystem::isIgnoredDir($file)) {
$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
}
}
}
} else {
try {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
fclose($source);
fclose($target);
} catch (\Exception $e) {
fclose($source);
fclose($target);
throw $e;
}
if ($result) {
if ($preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
}
$isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0;
// in case of a rename we need to manipulate the source cache because
// this information will be kept for the new target
if ($isRename) {
$sourceStorage->getCache()->put($sourceInternalPath, ['encrypted' => $isEncrypted]);
} else {
$this->getCache()->put($targetInternalPath, ['encrypted' => $isEncrypted]);
}
} else {
// delete partially written target file
$this->unlink($targetInternalPath);
// delete cache entry that was created by fopen
$this->getCache()->remove($targetInternalPath);
}
}
return (bool) $result;
}
示例15: decrypt
/**
* decrypt data
*
* @param string $data you want to decrypt
* @param int $position
* @return string decrypted data
* @throws DecryptionFailedException
*/
public function decrypt($data, $position = 0)
{
if (empty($this->fileKey)) {
$msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.';
$hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
$this->logger->error($msg);
throw new DecryptionFailedException($msg, $hint);
}
return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position);
}