Skip to content

Commit

Permalink
Merge composer/master into availability
Browse files Browse the repository at this point in the history
  • Loading branch information
s-nakajima committed Feb 18, 2021
2 parents bb81157 + edd8afb commit e19bec7
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 38 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '3*'

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: |
NetCommons ${{ github.ref }} released.
draft: false
prerelease: false
58 changes: 50 additions & 8 deletions Model/ActionQuestionnaireAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,40 @@ protected function _getQuestionnaireCloneById($questionnaireId) {
));
// ID値のみクリア
$this->Questionnaire->clearQuestionnaireId($questionnaire);
// Wysiwygエディタ内のファイルの複製処理
$questionnaire = $this->_copyWysiwygFiles($questionnaire);

return $questionnaire;
}
/**
* _copyWysiwygFiles
*
* 引数で指定されたアンケートの中を分析し、
* ウィジウィグに設定されているファイルは複製を作ります
*
* @param array $questionnaire アンケートデータ
* @return array $questionnaire 複製を作り終えたアンケートデータ
*/
protected function _copyWysiwygFiles($questionnaire) {
$wysiswyg = new WysiwygZip();
$flatQuestionnaire = Hash::flatten($questionnaire);
foreach ($flatQuestionnaire as $key => &$value) {
$model = $this->__getModelFromDataName($key);
if (!$model) {
continue;
}
$columnName = substr($key, strrpos($key, '.') + 1);
if ($model->hasField($columnName)) {
if ($model->getColumnType($columnName) == 'text') {
$wysiswygZipFile = $wysiswyg->createWysiwygZip($value);
$value = $wysiswyg->getFromWysiwygZip($wysiswygZipFile);
}
}
}
$questionnaire = Hash::expand($flatQuestionnaire);
return $questionnaire;
}

/**
* _createFromTemplate
*
Expand Down Expand Up @@ -343,14 +374,7 @@ protected function _getQuestionnaires($folderPath, $questionnaires, $importKey)
// WysIsWygのデータを入れなおす
$flatQuestionnaire = Hash::flatten($q);
foreach ($flatQuestionnaire as $key => &$value) {
$model = null;
if (strpos($key, 'QuestionnaireQuestion.') !== false) {
$model = $this->QuestionnaireQuestion;
} elseif (strpos($key, 'QuestionnairePage.') !== false) {
$model = $this->QuestionnairePage;
} elseif (strpos($key, 'Questionnaire.') !== false) {
$model = $this->Questionnaire;
}
$model = $this->__getModelFromDataName($key);
if (!$model) {
continue;
}
Expand All @@ -371,6 +395,24 @@ protected function _getQuestionnaires($folderPath, $questionnaires, $importKey)
}
return $questionnaires;
}
/**
* __getModelFromDataName
*
* @param string $keyName モデルのデータのフィールド名
* @return Model
*/
private function __getModelFromDataName($keyName) {
if (strpos($keyName, 'QuestionnaireQuestion.') !== false) {
$model = $this->QuestionnaireQuestion;
} elseif (strpos($keyName, 'QuestionnairePage.') !== false) {
$model = $this->QuestionnairePage;
} elseif (strpos($keyName, 'Questionnaire.') !== false) {
$model = $this->Questionnaire;
} else {
$model = null;
}
return $model;
}
/**
* __checkFingerPrint
*
Expand Down
4 changes: 3 additions & 1 deletion Model/Questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ public function saveQuestionnaire(&$questionnaire) {
$saveQuestionnaire['QuestionnairePage'][$key]['questionnaire_id'] = $questionnaireId;
}

if (! $this->QuestionnairePage->saveQuestionnairePage($saveQuestionnaire['QuestionnairePage'])) {
if (! $this->QuestionnairePage->saveQuestionnairePage(
$saveQuestionnaire['QuestionnairePage'], $saveQuestionnaire['Block']
)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
// フレーム内表示対象アンケートに登録する
Expand Down
47 changes: 25 additions & 22 deletions Model/QuestionnaireFrameSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,34 @@ public function saveFrameSettings($data) {
'Questionnaires.QuestionnaireFrameDisplayQuestionnaire',
]);

//トランザクションBegin
$this->begin();
try {
// 現在のアンケート確認
$questionnaireCount = $this->Questionnaire->find('count', array(
'conditions' => $this->Questionnaire->getBaseCondition()
));
// フレーム設定のバリデート
$this->create();
$this->set($data);
if (! $this->validates()) {
// 現在のアンケート確認
$questionnaireCount = $this->Questionnaire->find('count', array(
'conditions' => $this->Questionnaire->getBaseCondition()
));
// フレーム設定のバリデート
$this->create();
$this->set($data);
if (! $this->validates()) {
return false;
}

// アンケートが存在する場合は
if ($questionnaireCount > 0) {
// フレームに表示するアンケート一覧設定のバリデート
// 一覧表示タイプと単独表示タイプ
//バリデートチェックリストを初期化
$this->QuestionnaireFrameDisplayQuestionnaire->chkQuestionnaireList = array();
$ret = $this->QuestionnaireFrameDisplayQuestionnaire->validateFrameDisplayQuestionnaire($data);
if ($ret === false) {
$this->validationErrors['QuestionnaireFrameDisplayQuestionnaire'] =
$this->QuestionnaireFrameDisplayQuestionnaire->validationErrors;
return false;
}
}

// アンケートが存在する場合は
if ($questionnaireCount > 0) {
// フレームに表示するアンケート一覧設定のバリデート
// 一覧表示タイプと単独表示タイプ
$ret = $this->QuestionnaireFrameDisplayQuestionnaire->validateFrameDisplayQuestionnaire($data);
if ($ret === false) {
$this->validationErrors['QuestionnaireFrameDisplayQuestionnaire'] =
$this->QuestionnaireFrameDisplayQuestionnaire->validationErrors;
return false;
}
}
//トランザクションBegin
$this->begin();
try {

// フレーム設定の登録
if (! $this->save($data, false)) {
Expand Down
5 changes: 3 additions & 2 deletions Model/QuestionnairePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ public function beforeValidate($options = array()) {
* save QuestionnairePage data
*
* @param array &$questionnairePages questionnaire pages
* @param array $block ブロック情報
* @throws InternalErrorException
* @return bool
*/
public function saveQuestionnairePage(&$questionnairePages) {
public function saveQuestionnairePage(&$questionnairePages, $block) {
$this->loadModels([
'QuestionnaireQuestion' => 'Questionnaires.QuestionnaireQuestion',
]);
Expand Down Expand Up @@ -384,7 +385,7 @@ public function saveQuestionnairePage(&$questionnairePages) {
}
// もしもQuestionやChoiceのsaveがエラーになった場合は、
// QuestionやChoiceのほうでInternalExceptionErrorが発行されるのでここでは何も行わない
$this->QuestionnaireQuestion->saveQuestionnaireQuestion($page['QuestionnaireQuestion']);
$this->QuestionnaireQuestion->saveQuestionnaireQuestion($page['QuestionnaireQuestion'], $block);
}
return true;
}
Expand Down
57 changes: 55 additions & 2 deletions Model/QuestionnaireQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,11 @@ public function setQuestionToPage(&$questionnaire, &$page) {
* save QuestionnaireQuestion data
*
* @param array &$questions questionnaire questions
* @param array $block ブロック情報
* @throws InternalErrorException
* @return bool
*/
public function saveQuestionnaireQuestion(&$questions) {
public function saveQuestionnaireQuestion(&$questions, $block) {
$this->loadModels([
'QuestionnaireChoice' => 'Questionnaires.QuestionnaireChoice',
]);
Expand All @@ -374,14 +375,28 @@ public function saveQuestionnaireQuestion(&$questions) {
// 決まり処理は上位で行われる
// ここでは行わない

// ブロック情報の準備
// ここで準備したブロック情報は、saveに含まれ、
// WysiwygBehaviorのafterSaveでblock_keyが設定される
$block = [
'Block' => $block
];

foreach ($questions as &$question) {
// アンケートは履歴を取っていくタイプのコンテンツデータなのでSave前にはID項目はカット
// (そうしないと既存レコードのUPDATEになってしまうから)
// $question['QuestionnaireQuestion']['id']の項目は入ってこないためコメントアウト
// $question = Hash::remove($question, 'QuestionnaireQuestion.id');

// WysiwygBehaviorのafterSaveでblock_keyを参照できるように
// RegistrationQuestionとBlockは同一次元に配置する
$questionForSave = [
$this->alias => $question
];
$questionForSave = array_merge($questionForSave, $block);

$this->create();
if (! $this->save($question, false)) {
if (! $this->save($questionForSave, false)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}

Expand Down Expand Up @@ -481,4 +496,42 @@ public function deleteQuestionnaireQuestion($pageId) {
}
return true;
}

/**
* getAliveCondition
* 現在使用中状態であるか判断する。CleanUpプラグインで使用
*
* @param array $key 判断対象のデータのキー
* @return array
*/
public function getAliveCondition($key) {
return array(
'conditions' => array(
'QuestionnaireQuestion.key' => $key,
'OR' => array(
'Questionnaire.is_active' => true,
'Questionnaire.is_latest' => true,
),
),
'joins' => array(
array(
'table' => 'questionnaire_pages',
'alias' => 'QuestionnairePage',
'type' => 'INNER',
'conditions' => array(
$this->alias . '.questionnaire_page_id = QuestionnairePage.id'
)
),
array(
'table' => 'questionnaires',
'alias' => 'Questionnaire',
'type' => 'INNER',
'conditions' => array(
'QuestionnairePage.questionnaire_id = Questionnaire.id'
)
)
)
);
}

}
6 changes: 6 additions & 0 deletions Test/Case/AllQuestionnairesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AllQuestionnairesTest extends NetCommonsTestSuite {
* All test suite
*
* @return CakeTestSuite
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function suite() {
$plugin = preg_replace('/^All([\w]+)Test$/', '$1', __CLASS__);
Expand All @@ -40,6 +41,11 @@ public static function suite() {
}
}
*/
// ZipDownloaderは用意したテスト用モックを読み込ませるようにする
App::uses('ZipDownloader', 'Questionnaires.Test/test_app/Plugin/TestFiles/Utility');
// 前もって一度newしておかないと、実コードの中で本体側のZipDownloderがインスタンス化
new ZipDownloader();

$suite->addTestDirectoryRecursive(CakePlugin::path($plugin) . 'Test' . DS . 'Case');
/*
$suite->addTestFile(CakePlugin::path($plugin) . 'Test' . DS . 'Case' . '/Controller/Component/QuestionnaireOwnAnswerComponent/GetConfirmSummaryOfThisUserTest.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class QuestionnaireBlocksControllerExportTest extends NetCommonsControllerTestCa
public function setUp() {
parent::setUp();

// テストZipDownloaderに差し替え
//App::uses('ZipDownloader', 'Questionnaires.Test/test_app/Plugin/TestFiles/Utility');
//App::uses('ZipDownloader', 'TestFiles.Utility');

//テストプラグインのロード
NetCommonsCakeTestCase::loadTestPlugin($this, 'Questionnaires', 'TestQuestionnaires');
NetCommonsCakeTestCase::loadTestPlugin($this, 'Questionnaires', 'TestFiles');
Expand Down
1 change: 1 addition & 0 deletions Test/Case/Model/QuestionnaireExport/PutToZipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function testPutToZip($questionnaireKey, $expected) {
$model = $this->_modelName;
$method = $this->_methodName;

//App::uses('ZipDownloader', 'Questionnaires.Test/test_app/Plugin/TestFiles/Utility');
App::uses('ZipDownloader', 'TestFiles.Utility');

$langCount = 2; // 2 = 言語数
Expand Down
12 changes: 10 additions & 2 deletions TestSuite/QuestionnairesSaveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public function testSave($data) {
}

//テスト実行
$result = $this->$model->$method($data[$model]);
if ($method == 'saveQuestionnaireQuestion' || $method == 'saveQuestionnairePage') {
$result = $this->$model->$method($data[$model], $data['Block']);
} else {
$result = $this->$model->$method($data[$model]);
}
$this->assertNotEmpty($result);

//idのチェック
Expand Down Expand Up @@ -119,7 +123,11 @@ public function testSaveOnExceptionError($data, $mockModel, $mockMethod) {
$this->_mockForReturnFalse($model, $mockModel, $mockMethod);

$this->setExpectedException('InternalErrorException');
$this->$model->$method($data);
if ($method == 'saveQuestionnaireQuestion' || $method == 'saveQuestionnairePage') {
$this->$model->$method($data, $data['Block']);
} else {
$this->$model->$method($data);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.2
3.3.3

0 comments on commit e19bec7

Please sign in to comment.