当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception::getSuccessfulCommands方法代码示例

本文整理汇总了PHP中Exception::getSuccessfulCommands方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getSuccessfulCommands方法的具体用法?PHP Exception::getSuccessfulCommands怎么用?PHP Exception::getSuccessfulCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getSuccessfulCommands方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rename

 public function rename($from, $to)
 {
     $fromUrl = parse_url($from);
     $repoId = $fromUrl["host"];
     $repoObject = ConfService::getRepositoryById($repoId);
     $isViPR = $repoObject->getOption("IS_VIPR");
     $isDir = false;
     if ($isViPR === true) {
         if (is_dir($from . "/")) {
             $from .= '/';
             $to .= '/';
             $isDir = true;
         }
     }
     if ($isDir === true || is_dir($from)) {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Renaming dir {$from} to {$to}");
         require_once "aws.phar";
         $fromUrl = parse_url($from);
         $repoId = $fromUrl["host"];
         $repoObject = ConfService::getRepositoryById($repoId);
         if (!isset($repoObject)) {
             $e = new Exception("Cannot find repository with id " . $repoId);
             self::$lastException = $e;
             throw $e;
         }
         // Get a client
         $options = array('key' => $repoObject->getOption("API_KEY"), 'secret' => $repoObject->getOption("SECRET_KEY"));
         $baseURL = $repoObject->getOption("STORAGE_URL");
         if (!empty($baseURL)) {
             $options["base_url"] = $baseURL;
         } else {
             $options["region"] = $repoObject->getOption("REGION");
         }
         $proxy = $repoObject->getOption("PROXY");
         if (!empty($proxy)) {
             $options['request.options'] = array('proxy' => $proxy);
         }
         $s3Client = S3Client::factory($options);
         $bucket = $repoObject->getOption("CONTAINER");
         $basePath = $repoObject->getOption("PATH");
         $fromKeyname = trim(str_replace("//", "/", $basePath . parse_url($from, PHP_URL_PATH)), '/');
         $toKeyname = trim(str_replace("//", "/", $basePath . parse_url($to, PHP_URL_PATH)), '/');
         if ($isViPR) {
             $toKeyname .= '/';
             $parts = explode('/', $bucket);
             $bucket = $parts[0];
             if (isset($parts[1])) {
                 $fromKeyname = $parts[1] . "/" . $fromKeyname;
             }
         }
         // Perform a batch of CopyObject operations.
         $batch = array();
         $iterator = $s3Client->getIterator('ListObjects', array('Bucket' => $bucket, 'Prefix' => $fromKeyname . "/"));
         $toDelete = array();
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Got iterator looking for prefix " . $fromKeyname . "/ , and toKeyName=" . $toKeyname);
         foreach ($iterator as $object) {
             $currentFrom = $object['Key'];
             $currentTo = $toKeyname . substr($currentFrom, strlen($fromKeyname));
             if ($isViPR) {
                 if (isset($parts[1])) {
                     $currentTo = $parts[1] . "/" . $currentTo;
                 }
             }
             AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Should move one object " . $currentFrom . " to  new key :" . $currentTo);
             $batch[] = $s3Client->getCommand('CopyObject', array('Bucket' => $bucket, 'Key' => "{$currentTo}", 'CopySource' => "{$bucket}/" . rawurlencode($currentFrom)));
             $toDelete[] = $currentFrom;
         }
         try {
             AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Execute batch on " . count($batch) . " objects");
             $successful = $s3Client->execute($batch);
             $failed = array();
             $iterator->rewind();
             $clear = new \Aws\S3\Model\ClearBucket($s3Client, $bucket);
             $clear->setIterator($iterator);
             $clear->clear();
         } catch (\Guzzle\Service\Exception\CommandTransferException $e) {
             $successful = $e->getSuccessfulCommands();
             $failed = $e->getFailedCommands();
         }
         if (count($failed)) {
             foreach ($failed as $c) {
                 // $c is a Aws\S3\Command\S3Command
                 AJXP_Logger::error("S3Wrapper", __FUNCTION__, "Error while copying: " . $c->getOperation()->getServiceDescription());
             }
             self::$lastException = new Exception("Failed moving folder: " . count($failed));
             return false;
         }
         return true;
     } else {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Execute standard rename on " . $from . " to " . $to);
         return parent::rename($from, $to);
     }
 }
开发者ID:floffel03,项目名称:pydio-core,代码行数:93,代码来源:class.s3AccessWrapper.php

示例2: rename

 /**
  * @inheritdoc
  */
 public function rename($from, $to)
 {
     $fromUrl = parse_url($from);
     $repoId = $fromUrl["host"];
     $repoObject = ConfService::getRepositoryById($repoId);
     $isViPR = $repoObject->getOption("IS_VIPR");
     $isDir = false;
     if ($isViPR === true) {
         if (is_dir($from . "/")) {
             $from .= '/';
             $to .= '/';
             $isDir = true;
         }
     }
     if ($isDir === true || is_dir($from)) {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Renaming dir {$from} to {$to}");
         require_once "aws-v2.phar";
         $fromUrl = parse_url($from);
         $repoId = $fromUrl["host"];
         $repoObject = ConfService::getRepositoryById($repoId);
         if (!isset($repoObject)) {
             $e = new Exception("Cannot find repository with id " . $repoId);
             self::$lastException = $e;
             throw $e;
         }
         $s3Client = self::getClientForRepository($repoObject, false);
         $bucket = $repoObject->getOption("CONTAINER");
         $basePath = $repoObject->getOption("PATH");
         $fromKeyname = trim(str_replace("//", "/", $basePath . parse_url($from, PHP_URL_PATH)), '/');
         $toKeyname = trim(str_replace("//", "/", $basePath . parse_url($to, PHP_URL_PATH)), '/');
         if ($isViPR) {
             $toKeyname .= '/';
             $parts = explode('/', $bucket);
             $bucket = $parts[0];
             if (isset($parts[1])) {
                 $fromKeyname = $parts[1] . "/" . $fromKeyname;
             }
         }
         // Perform a batch of CopyObject operations.
         $batch = array();
         $failed = array();
         $iterator = $s3Client->getIterator('ListObjects', array('Bucket' => $bucket, 'Prefix' => $fromKeyname . "/"));
         $toDelete = array();
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Got iterator looking for prefix " . $fromKeyname . "/ , and toKeyName=" . $toKeyname);
         foreach ($iterator as $object) {
             $currentFrom = $object['Key'];
             $currentTo = $toKeyname . substr($currentFrom, strlen($fromKeyname));
             if ($isViPR) {
                 if (isset($parts[1])) {
                     $currentTo = $parts[1] . "/" . $currentTo;
                 }
             }
             AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Should move one object " . $currentFrom . " to  new key :" . $currentTo);
             $batch[] = $s3Client->getCommand('CopyObject', array('Bucket' => $bucket, 'Key' => "{$currentTo}", 'CopySource' => "{$bucket}/" . rawurlencode($currentFrom)));
             $toDelete[] = $currentFrom;
         }
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Execute batch on " . count($batch) . " objects");
         ConfService::getConfStorageImpl()->_loadPluginConfig("access.s3", $globalOptions);
         $sdkVersion = $globalOptions["SDK_VERSION"];
         if ($sdkVersion === "v3") {
             foreach ($batch as $command) {
                 $successful = $s3Client->execute($command);
             }
             //We must delete the "/" in $fromKeyname because we want to delete the folder
             $clear = \Aws\S3\BatchDelete::fromIterator($s3Client, $bucket, $s3Client->getIterator('ListObjects', array('Bucket' => $bucket, 'Prefix' => $fromKeyname)));
             $clear->delete();
         } else {
             try {
                 $successful = $s3Client->execute($batch);
                 $clear = new \Aws\S3\Model\ClearBucket($s3Client, $bucket);
                 $iterator->rewind();
                 $clear->setIterator($iterator);
                 $clear->clear();
                 $failed = array();
             } catch (\Guzzle\Service\Exception\CommandTransferException $e) {
                 $successful = $e->getSuccessfulCommands();
                 $failed = $e->getFailedCommands();
             }
         }
         if (count($failed)) {
             foreach ($failed as $c) {
                 // $c is a Aws\S3\Command\S3Command
                 AJXP_Logger::error("S3Wrapper", __FUNCTION__, "Error while copying: " . $c->getOperation()->getServiceDescription());
             }
             self::$lastException = new Exception("Failed moving folder: " . count($failed));
             return false;
         }
         return true;
     } else {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Execute standard rename on " . $from . " to " . $to);
         return parent::rename($from, $to);
     }
 }
开发者ID:Nanomani,项目名称:pydio-core,代码行数:96,代码来源:class.s3AccessWrapper.php


注:本文中的Exception::getSuccessfulCommands方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。