Skip to content

Commit

Permalink
コンフィグセットに対応 & リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu666 committed Mar 24, 2021
1 parent 34e972f commit 80d5c00
Show file tree
Hide file tree
Showing 13 changed files with 1,046 additions and 41 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
composer.phar
/vendor/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
/node_modules/
.DS_Store
12 changes: 11 additions & 1 deletion Api.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

namespace Acms\Plugins\Base;

use RuntimeException;
use SQL;
use DB;
use App;
use Config;

class Api
{
/**
* @var \Field
*/
protected $config;

/**
* @var string
*/
Expand Down Expand Up @@ -51,6 +59,8 @@ class Api
*/
public function __construct($client_id, $client_secret, $callback_uri)
{
$this->config = App::make('app-the-base-config');

$this->setClientId($client_id);
$this->setClientSecret($client_secret);
$this->setCallbackUri($callback_uri);
Expand Down Expand Up @@ -318,7 +328,7 @@ protected function saveCache($key, $value)
$SQL = SQL::newInsert('base_cache');
$SQL->addInsert('id', $key);
$SQL->addInsert('data', $value);
$SQL->addInsert('expire', date('Y-m-d H:i:s', REQUEST_TIME + config('base_cache_time', 0)));
$SQL->addInsert('expire', date('Y-m-d H:i:s', REQUEST_TIME + $this->config->get('base_cache_time', 0)));
DB()->query($SQL->get(dsn()), 'exec');
}

Expand Down
8 changes: 5 additions & 3 deletions GET/Base/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Acms\Plugins\Base\GET\Base;

use ACMS_GET;
use App;
use Acms\Plugins\Base\Api as BaseApi;


class Api extends ACMS_GET
{
/**
Expand All @@ -30,9 +30,11 @@ public function getClient()

public static function create()
{
$config = App::make('app-the-base-config');

return new BaseApi(
config('base_client_id'),
config('base_client_secret'),
$config->get('base_client_id'),
$config->get('base_client_secret'),
BASE_URL. 'bid/' .BID .'/admin/app_base_index/'
);
}
Expand Down
2 changes: 1 addition & 1 deletion GET/Base/Api/Callback.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Acms\Plugins\Base\GET\Base\Api;

use Acms\Plugins\Base\GET\Base\Api;
use ACMS_GET;
use ACMS_Corrector;
use Template;
use Exception;
Expand Down
4 changes: 2 additions & 2 deletions GET/Base/Detail.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace Acms\Plugins\Base\GET\Base;
use Acms\Plugins\Base\GET\Base\Api;

use ACMS_Corrector;
use ACMS_GET;
use Template;
use RuntimeException;
use Exception;
Expand All @@ -22,6 +21,7 @@ function get()
$error = '';
$item = array();


try {
$fieldType = config('base_detail_field_type', 'entry');
$fieldName = config('base_detail_field_name', 'base_item_id');
Expand Down
4 changes: 2 additions & 2 deletions GET/Base/Items.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Acms\Plugins\Base\GET\Base;
use Acms\Plugins\Base\GET\Base\Api;

use ACMS_Corrector;
use ACMS_GET;
use App;
use Template;
use Exception;

Expand Down
20 changes: 14 additions & 6 deletions GET/Base/Search.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Acms\Plugins\Base\GET\Base;
use Acms\Plugins\Base\GET\Base\Api;

use ACMS_Corrector;
use ACMS_GET;
use App;
use Template;
use Exception;

Expand All @@ -16,30 +16,38 @@ class Search extends Api
function get()
{
$Tpl = new Template($this->tpl, new ACMS_Corrector());
$config = App::make('app-the-base-config');
$items = array();
$error = '';
$found = 0;
$start = 0;

try {
$client = $this->getClient();
$json = $client->get('search', array(
'client_id' => config('base_search_client_id'),
'client_secret' => config('base_search_client_secret'),
'client_id' => $config->get('base_search_client_id'),
'client_secret' => $config->get('base_search_client_secret'),
'q' => $this->keyword,
'sort' => config('base_search_order', 'item') . ' ' . config('base_search_sort', 'asc'), // (item_id|price|stock|order_count|modified) + (asc|desc)
'start' => config('base_search_offset', 0),
'size' => config('base_search_limit', 20),
'fields' => config('base_search_fields', 'shop_name,title.detail,categories'),
'shop_id' => config('base_search_shop_id', ''),
));
if (empty($json)) {
throw new \RuntimeException('Failed to get json.');
}
$items = $json->items;
$found = $json->found;
$start = $json->start;
} catch ( Exception $e ) {
$error = $e->getMessage();
}

return $Tpl->render(array(
'error' => $error,
'found' => $json->found,
'start' => $json->start,
'found' => $found,
'start' => $start,
'items' => $items,
));
}
Expand Down
24 changes: 3 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Base
# The Base


## ダウンロード・設置

ここから[Base](https://github.com/appleple/acms-base/archive/master.zip)をダウンロードしてください。
ここから[The Base](https://github.com/appleple/acms-base/raw/master/build/the-base.zip)をダウンロードしてください。

ここにディレクトリを設置してください。

extension/plugins/Base
ダウンロード後、/extension/pluginsに設置します。

## 拡張アプリインストール

Expand All @@ -27,9 +25,6 @@ The BASEのインストールボタンを押してください。
* 利用権限: ユーザー情報を見る / 商品情報を見る にチェック
* 検索APIの利用: 利用するにチェック


![](https://developer.a-blogcms.jp/archives/009/201610/large-0f8906cda5ec5d0e9b5804360e27cedd.png)

## The BASE 設定画面(a-blog cms側)

アプリ登録が完了するとアプリ用と検索用の **client_id****client_secret** が発行されていると思います。
Expand All @@ -47,8 +42,6 @@ The BASEのインストールボタンを押してください。
メールアドレスとパスワードをいれて認証してください。認証後、自動的にリダイレクトされa-blog cmsの管理画面に戻ってきます。
**認証に成功しました** と表示されていれば連携成功です。

![](https://developer.a-blogcms.jp/archives/009/201610/large-2268cd51e95971907d6b20223de685b6.png)

## モジュールを利用してみる

連携が成功したので実際にa-blog cmsのモジュールを利用してみます。以下3つのモジュールが用意されています。
Expand All @@ -70,12 +63,6 @@ The BASEのインストールボタンを押してください。
* 表示数: 表示数
* オフセット: 開始位置を指定

![](https://developer.a-blogcms.jp/archives/009/201610/tiny-5a46fe40a2aaa535e5952d44d0517fd1.png)

![](https://developer.a-blogcms.jp/archives/009/201610/large-e3dd0507b81e52b5cae5f11fc45b0fc2.png)

![](https://developer.a-blogcms.jp/archives/009/201610/large-5e1f071784ad43b9e40a7e42a287d267.png)


### 商品検索(Base_Search)

Expand All @@ -87,10 +74,5 @@ The BASEのインストールボタンを押してください。
* ショップID: ショップIDで絞り込み可能。空だとThe BASEにある別ショップの商品も検索対象に
* 検索対象: 検索を行うフィールドを指定

![](https://developer.a-blogcms.jp/archives/009/201610/large-2feeb81baf21cdc44f66bc0ca21a8189.png)

![](https://developer.a-blogcms.jp/archives/009/201610/large-6a322d47568422f70a7613cc47d54976.png)

![](https://developer.a-blogcms.jp/archives/009/201610/large-ae05d9973e94e180eae0935aeddbd72e.png)

The BASE は無料で簡単にネットショップを開設できるサービスです。本格的なECサイトは難しいですが、簡単にショップを開設し、a-blog cmsで商品の紹介を行う事ができるようになります。
10 changes: 9 additions & 1 deletion ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

namespace Acms\Plugins\Base;

use ACMS_App;
use App;
use Config;
use Acms\Services\Common\InjectTemplate;

class ServiceProvider extends ACMS_App
{
public $version = '1.0.0';
public $version = '1.0.1';
public $name = 'The BASE';
public $author = 'com.appleple';
public $module = false;
Expand All @@ -32,6 +34,12 @@ public function init()
$inject->add('admin-module-config-Base_Detail', PLUGIN_DIR . 'Base/theme/detail_body.html');
$inject->add('admin-module-config-Base_Search', PLUGIN_DIR . 'Base/theme/search_body.html');
$inject->add('admin-module-select', PLUGIN_DIR . 'Base/theme/select.user.html');

App::singleton('app-the-base-config', function () {
$config = Config::loadDefaultField();
$config->overload(Config::loadBlogConfig(BID));
return $config;
});
}

/**
Expand Down
Binary file added build/the-base.zip
Binary file not shown.
73 changes: 73 additions & 0 deletions deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const cmd = require('node-cmd');
const fs = require('fs-extra');
const co = require('co');
const archiver = require('archiver');
const pkg = fs.readJsonSync('./package.json');

/**
* Run system command
*
* @param cmdString
* @returns {Promise}
*/
const systemCmd = cmdString => {
return new Promise((resolve) => {
cmd.get(
cmdString,
(data, err, stderr) => {
console.log(cmdString);
console.log(data);
if (err) {
console.log(err);
}
if (stderr) {
console.log(stderr);
}
resolve(data);
}
);
});
}

const zipPromise = (src, dist) => {
return new Promise((resolve, reject) => {
const archive = archiver.create('zip', {});
const output = fs.createWriteStream(dist);

// listen for all archive data to be written
output.on('close', () => {
console.log(archive.pointer() + ' total bytes');
console.log('Archiver has been finalized and the output file descriptor has closed.');
resolve();
});

// good practice to catch this error explicitly
archive.on('error', (err) => {
reject(err);
});

archive.pipe(output);
archive.directory(src).finalize();
});
}

co(function* () {
try {
fs.mkdirsSync(`Base`);
fs.mkdirsSync(`build`);
fs.copySync(`./LICENSE`, `Base/LICENSE`);
fs.copySync(`./README.md`, `Base/README.md`);
fs.copySync(`./Api.php`, `Base/Api.php`);
fs.copySync(`./ServiceProvider.php`, `Base/ServiceProvider.php`);
fs.copySync(`./db`, `Base/db`);
fs.copySync(`./GET`, `Base/GET`);
fs.copySync(`./theme`, `Base/theme`);
yield zipPromise(`Base`, `./build/the-base.zip`);
fs.removeSync(`Base`);
yield systemCmd('git add -A');
yield systemCmd(`git commit -m "v${pkg.version}"`);
yield systemCmd('git push');
} catch (err) {
console.log(err);
}
});
Loading

0 comments on commit 80d5c00

Please sign in to comment.