Skip to content

Commit

Permalink
travis-ciのテストをtrustyで通す (#843)
Browse files Browse the repository at this point in the history
* TravicCI の環境を trusty に変更
* explicitly set order by
* GoogleMapコンポーネントの処理にリトライ追加
* CIのビルド時間短縮
  • Loading branch information
n1215 authored and ryuring committed Jan 7, 2018
1 parent 07d4af7 commit a4cf98b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -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

Expand Down
25 changes: 20 additions & 5 deletions lib/Baser/Controller/Component/BcGmapsComponent.php
Expand Up @@ -19,6 +19,18 @@
*/
class BcGmapsComponent extends Component {

/**
* 接続試行回数
* @var int
*/
const RETRY_TIMES = 3;

/**
* 接続試行の間隔(ミリ秒)
* @var int
*/
const RETRY_INTERVAL = 250;

/**
* Latitude
*
Expand Down Expand Up @@ -77,7 +89,7 @@ class BcGmapsComponent extends Component {

/**
* Construct
*
* fixme 親クラスのコンストラクタを呼ばないとControllerへのアクセスができない。newしている箇所の修正も必要
* @return void
*/
public function __construct() {
Expand All @@ -88,8 +100,6 @@ public function __construct() {
* getInfoLocation
*
* @param string $address
* @param string $city
* @param string $state
* @return boolean
*/
public function getInfoLocation($address) {
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Baser/Model/Content.php
Expand Up @@ -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']]);
}

/**
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/View/Helper/BcBaserHelper.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/View/Helper/BcContentsHelper.php
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion lib/Baser/View/Helper/BcGooglemapsHelper.php
Expand Up @@ -185,7 +185,7 @@ public function loadLocation() {
* 位置情報を取得する
*
* @param string $address
* @return boolean
* @return array|boolean
*/
public function getLocation($address) {

Expand Down
34 changes: 33 additions & 1 deletion lib/Baser/basics.php
Expand Up @@ -1067,4 +1067,36 @@ function getTableList() {
}
Cache::write('table_list', $list, '_cake_core_');
return $list;
}
}

/**
* 処理を実行し、例外が発生した場合は指定した回数だけリトライする
* @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);
}
}
}
}
3 changes: 2 additions & 1 deletion travis.php.ini
@@ -1 +1,2 @@
memory_limit = 512M
memory_limit = 512M
remote_enable=0

0 comments on commit a4cf98b

Please sign in to comment.