diff --git a/.travis.yml b/.travis.yml index 0453607156..499fbeaf1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,14 @@ env: matrix: include: - - php: 5.4 + - php: 5.6 env: DB=postgres - - php: 5.4 + - php: 5.6 env: DB=sqlite allow_failures: - php: hhvm -dist: precise +dist: trusty sudo: false diff --git a/lib/Baser/Controller/Component/BcGmapsComponent.php b/lib/Baser/Controller/Component/BcGmapsComponent.php index d47cb2928c..18a0ef27f2 100644 --- a/lib/Baser/Controller/Component/BcGmapsComponent.php +++ b/lib/Baser/Controller/Component/BcGmapsComponent.php @@ -19,6 +19,18 @@ */ class BcGmapsComponent extends Component { +/** + * 接続試行回数 + * @var int + */ + const RETRY_TIMES = 3; + +/** + * 接続試行の間隔(ミリ秒) + * @var int + */ + const RETRY_INTERVAL = 250; + /** * Latitude * @@ -77,7 +89,7 @@ class BcGmapsComponent extends Component { /** * Construct - * + * fixme 親クラスのコンストラクタを呼ばないとControllerへのアクセスができない。newしている箇所の修正も必要 * @return void */ public function __construct() { @@ -88,8 +100,6 @@ public function __construct() { * getInfoLocation * * @param string $address - * @param string $city - * @param string $state * @return boolean */ public function getInfoLocation($address) { @@ -112,8 +122,13 @@ protected function _connect($param) { App::uses('Xml', 'Utility'); try { - $xmlArray = Xml::toArray(Xml::build($requestUrl)); - } catch(XmlException $e) { + $xml = retry(self::RETRY_TIMES, function () use ($requestUrl) { + return Xml::build($requestUrl); + }, self::RETRY_INTERVAL); + $xmlArray = Xml::toArray($xml); + } catch (XmlException $e) { + return false; + } catch (\Exception $e) { return false; } diff --git a/lib/Baser/Model/Content.php b/lib/Baser/Model/Content.php index 959da04b20..2a2f3016d2 100644 --- a/lib/Baser/Model/Content.php +++ b/lib/Baser/Model/Content.php @@ -868,7 +868,7 @@ public function findByType($type, $entityId = null) { if($entityId) { $conditions['Content.entity_id'] = $entityId; } - return $this->find('first', ['conditions' => $conditions]); + return $this->find('first', ['conditions' => $conditions, 'order' => ['Content.id']]); } /** @@ -1671,6 +1671,7 @@ public function getRelatedSiteContents($id, $options = []) { $conditions = array_merge($conditions, $this->getConditionAllowPublish()); $contents = $this->find('all', [ 'conditions' => $conditions, + 'order' => ['Content.id'], 'recursive' => 0 ]); $mainSite = $this->Site->getRootMain(); diff --git a/lib/Baser/View/Helper/BcBaserHelper.php b/lib/Baser/View/Helper/BcBaserHelper.php index fbb2c87574..6e9b8561a6 100755 --- a/lib/Baser/View/Helper/BcBaserHelper.php +++ b/lib/Baser/View/Helper/BcBaserHelper.php @@ -2371,7 +2371,7 @@ public function googleMaps($data = [], $options = []) { * @param array $data 読み込むテンプレートに引き継ぐパラメータ(初期値 : array()) * @param array $options オプション(初期値 : array()) * ※ その他のパラメータについては、View::element() を参照 - * @return void + * @return string */ public function getGoogleMaps($data = [], $options = []) { return $this->getElement('google_maps', $data, $options); diff --git a/lib/Baser/View/Helper/BcContentsHelper.php b/lib/Baser/View/Helper/BcContentsHelper.php index 9f7c124a45..9706bf08b3 100644 --- a/lib/Baser/View/Helper/BcContentsHelper.php +++ b/lib/Baser/View/Helper/BcContentsHelper.php @@ -511,7 +511,7 @@ public function isEditable($data = null) { */ public function getContentByEntityId($id, $contentType, $field = null){ $conditions = array_merge($this->_Content->getConditionAllowPublish(), ['type' => $contentType, 'entity_id' => $id]); - $content = $this->_Content->find('first', ['conditions' => $conditions, 'cache' => false]); + $content = $this->_Content->find('first', ['conditions' => $conditions, 'order' => ['Content.id'], 'cache' => false]); if(!empty($content)){ if($field){ return $content ['Content'][$field]; diff --git a/lib/Baser/View/Helper/BcGooglemapsHelper.php b/lib/Baser/View/Helper/BcGooglemapsHelper.php index 021f025e38..d782bea30b 100755 --- a/lib/Baser/View/Helper/BcGooglemapsHelper.php +++ b/lib/Baser/View/Helper/BcGooglemapsHelper.php @@ -185,7 +185,7 @@ public function loadLocation() { * 位置情報を取得する * * @param string $address - * @return boolean + * @return array|boolean */ public function getLocation($address) { diff --git a/lib/Baser/basics.php b/lib/Baser/basics.php index f323a0f82e..6f60775c3e 100644 --- a/lib/Baser/basics.php +++ b/lib/Baser/basics.php @@ -1067,4 +1067,36 @@ function getTableList() { } Cache::write('table_list', $list, '_cake_core_'); return $list; -} \ No newline at end of file +} + +/** + * 処理を実行し、例外が発生した場合は指定した回数だけリトライする + * @param int $times リトライ回数 + * @param callable $callback 実行する処理 + * @param int $interval 試行の間隔(ミリ秒) + * @return mixed + * @throws Exception + */ +function retry($times, callable $callback, $interval = 0) { + + if ($times <= 0) { + throw new \InvalidArgumentException('リトライ回数は正の整数値で指定してください。'); + } + + $times--; + + while (true) { + try { + return $callback(); + } catch (\Exception $e) { + if ($times <= 0) { + throw $e; + } + $times--; + + if ($intervalMs > 0) { + usleep($interval * 1000); + } + } + } +} diff --git a/travis.php.ini b/travis.php.ini index 66b8f68d1c..4a582afa48 100644 --- a/travis.php.ini +++ b/travis.php.ini @@ -1 +1,2 @@ -memory_limit = 512M \ No newline at end of file +memory_limit = 512M +remote_enable=0