From ffdba8cc0d2b71329894e2d5ed0ade68d6f394be Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 8 Oct 2019 16:32:55 +0900 Subject: [PATCH 01/28] =?UTF-8?q?fix:=20blocks=E3=82=84frames=E3=81=AE?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C=E6=B6=88=E3=81=88=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=81=9F=E3=82=81=E3=80=81frames.key?= =?UTF-8?q?=E3=80=81blocks.key=E3=82=82=E5=89=8A=E9=99=A4=E7=94=A8?= =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E3=81=AE=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=BF=85=E8=A6=81=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3=20https://github.com/NetCo?= =?UTF-8?q?mmons3/NetCommons3/issues/735?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/RoomDeleteRelatedTable.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Model/RoomDeleteRelatedTable.php b/Model/RoomDeleteRelatedTable.php index e3572f5..08a87a3 100644 --- a/Model/RoomDeleteRelatedTable.php +++ b/Model/RoomDeleteRelatedTable.php @@ -80,9 +80,11 @@ public function insertByRoomId($roomId) { ); foreach ($targetTables as $table) { - $this->__execInsertQuery( - $roomId, 'room_id', $roomId, $table, 'id', $this->__defaultConditions[$table] - ); + foreach ($this->__defaultConditions[$table] as $field => $condition) { + $this->__execInsertQuery( + $roomId, 'room_id', $roomId, $table, $field, [$field => $condition] + ); + } } //トランザクションCommit From c42063ee8a9aa9181f9e6241caabd54ecff104ea Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 8 Oct 2019 21:39:31 +0900 Subject: [PATCH 02/28] =?UTF-8?q?add:=20=E3=83=AB=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=81=AB=E3=82=88=E3=82=8A=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E9=96=A2=E9=80=A3=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=82=92=E5=89=8A=E9=99=A4=E3=82=B7=E3=82=A7?= =?UTF-8?q?=E3=83=AB=E8=BF=BD=E5=8A=A0=20https://github.com/NetCommons3/Ne?= =?UTF-8?q?tCommons3/issues/735?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Command/DeleteRoomAssociationsShell.php | 133 +++++++ Lib/RoomsLibCache.php | 63 ++++ Lib/RoomsLibDataSourceExecute.php | 281 ++++++++++++++ Lib/RoomsLibDeleteRoomTables.php | 348 ++++++++++++++++++ Lib/RoomsLibForeignConditionsParser.php | 88 +++++ Locale/jpn/LC_MESSAGES/rooms.po | 15 + Model/RoomDeleteRelatedTable.php | 40 +- 7 files changed, 935 insertions(+), 33 deletions(-) create mode 100644 Console/Command/DeleteRoomAssociationsShell.php create mode 100644 Lib/RoomsLibCache.php create mode 100644 Lib/RoomsLibDataSourceExecute.php create mode 100644 Lib/RoomsLibDeleteRoomTables.php create mode 100644 Lib/RoomsLibForeignConditionsParser.php diff --git a/Console/Command/DeleteRoomAssociationsShell.php b/Console/Command/DeleteRoomAssociationsShell.php new file mode 100644 index 0000000..8041d59 --- /dev/null +++ b/Console/Command/DeleteRoomAssociationsShell.php @@ -0,0 +1,133 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('AppShell', 'Console/Command'); +App::uses('RoomsLibForeignConditionsParser', 'Rooms.Lib'); +App::uses('RoomsLibDeleteRoomTables', 'Rooms.Lib'); + +/** + * ルーム削除した際の関連テーブルのデータを削除する + * + * @property RoomDeleteRelatedTable $RoomDeleteRelatedTable + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Console\Command + */ +class DeleteRoomAssociationsShell extends AppShell { + +/** + * 使用するモデル + * + * @var array + */ + public $uses = [ + 'Rooms.RoomDeleteRelatedTable', + ]; + +/** + * DeleteRoomTablesを操作するライブラリ + * + * @var RoomsLibDeleteRoomTables + */ + private $__RoomsLibDeleteRoomTables; + +/** + * Override startup + * + * @return void + */ + public function startup() { + $this->out(__d('rooms', 'Delete room associations Shell')); + $this->hr(); + } + +/** + * 処理実行 + * + * @return void + */ + public function main() { + $this->__RoomsLibDeleteRoomTables = new RoomsLibDeleteRoomTables($this->RoomDeleteRelatedTable); + + $conditions = []; + if ($this->param('all')) { + $conditions = []; + } elseif ($this->param('room-id')) { + $conditions = [ + 'room_id' => $this->param('room-id'), + ]; + } else { + return; + } + + $records = $this->RoomDeleteRelatedTable->find('all', [ + 'recursive' => -1, + 'conditions' => $conditions + ]); + + //トランザクションBegin + $this->RoomDeleteRelatedTable->begin(); +//\CakeLog::debug(__METHOD__ . '(' . __LINE__ . ') ' . var_export($records, true)); + + try { + foreach ($records as $record) { + $this->__RoomsLibDeleteRoomTables->deleteRelatedTables( + $record['RoomDeleteRelatedTable']['delete_table_name'], + $record['RoomDeleteRelatedTable']['field_name'], + $record['RoomDeleteRelatedTable']['value'], + $record['RoomDeleteRelatedTable']['foreign_field_conditions'] + ); + } + + //トランザクションCommit + $this->RoomDeleteRelatedTable->rollback(); + //$this->RoomDeleteRelatedTable->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->RoomDeleteRelatedTable->rollback($ex); + } + + $this->hr(); + } + +/** + * 引数の使い方の取得 + * + * @return ConsoleOptionParser + */ + public function getOptionParser() { + $parser = parent::getOptionParser(); + return $parser->description(__d('rooms', 'The Delete room associations Shell')) + ->addOption( + 'room-id', + [ + 'help' => __d('rooms', 'Process room id'), + ] + ) + ->addOption( + 'limit', + [ + 'help' => __d('rooms', 'Process limit'), + 'default' => 100, + ] + ) + ->addOption( + 'all', + array( + 'short' => 'a', + 'boolean' => true, + 'help' => __d('rooms', 'All records'), + ) + ); + } + +} diff --git a/Lib/RoomsLibCache.php b/Lib/RoomsLibCache.php new file mode 100644 index 0000000..e6dabaf --- /dev/null +++ b/Lib/RoomsLibCache.php @@ -0,0 +1,63 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsCache', 'NetCommons.Utility'); + +/** + * ルーム削除時の関連テーブル削除処理に関するライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + */ +class RoomsLibCache { + +/** + * NetCommonsキャッシュオブジェクト + * + * @var NetCommonsCache + */ + private $__NetCommonsCache; + +/** + * コンストラクタ + * + * @param Model $Model モデル(当モデルは、MySQLのModelであれば何でも良い) + * @return void + */ + public function __construct(Model $Model) { + $cacheName = 'delete_rooms_' . $Model->useDbConfig; + $isTest = ($Model->useDbConfig === 'test'); + $this->__NetCommonsCache = new NetCommonsCache($cacheName, $isTest, 'netcommons_model'); + } + +/** + * キャッシュに登録 + * + * @param string $key キャッシュキー + * @param array $value キャッシュに保存する値 + * @return array + */ + public function saveCache($key, $subKey, $value) { + $this->__NetCommonsCache->write($value, $key, $subKey); + } + +/** + * カラム名に対するテーブルリストを取得する + * + * @param string $key キャッシュキー + * @param string $subKey キャッシュサブキー + * @return array + */ + public function readCache($key, $subKey = null) { + return $this->__NetCommonsCache->read($key, $subKey); + } + +} diff --git a/Lib/RoomsLibDataSourceExecute.php b/Lib/RoomsLibDataSourceExecute.php new file mode 100644 index 0000000..ed07fc0 --- /dev/null +++ b/Lib/RoomsLibDataSourceExecute.php @@ -0,0 +1,281 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * ルーム削除時の関連テーブル削除処理に関するライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + */ +class RoomsLibDataSourceExecute { + +/** + * データソースオブジェクト + * + * @var DataSource + */ + private $__DataSource; + +/** + * 使用するモデル + * + * @var Model + */ + private $__Model; + +/** + * コンストラクタ + * + * @param Model $Model モデル(当モデルは、MySQLのModelであれば何でも良い) + * @return void + */ + public function __construct(Model $Model) { + $this->__Model = $Model; + $this->__DataSource = $Model->getDataSource(); + $this->__RoomsLibCache = new RoomsLibCache($Model); + } + +/** + * テーブルリストをキャッシュから取得する。なければ、最新情報から取得し、キャッシュに保存する + * + * @return array + */ + public function showTables() { + //キャッシュから取得 + $cacheTables = $this->__RoomsLibCache->readCache('tables', null); + if ($cacheTables) { + return $cacheTables; + } + + $schemaTables = $this->__findAllSchemeFileTables(); + $tablePrefix = $this->__Model->tablePrefix; + + //LIKEで多少の絞り込みを行う。ただし、tablePrefixがない場合は、全テーブルが対象となってしまう。 + $tables = $this->__Model->query("SHOW TABLES LIKE '{$tablePrefix}%s'"); + + $retTables = []; + foreach ($tables as $table) { + $realTableName = array_shift($table['TABLE_NAMES']); + $realPrefix = substr($realTableName, 0, strlen($tablePrefix)); + $tableName = substr($realTableName, strlen($tablePrefix)); + + if ($tablePrefix !== $realPrefix || + ! in_array($tableName, $schemaTables)) { + continue; + } + $retTables[$tableName] = $this->__showDbTableColumns($realTableName); + } + + //キャッシュに登録 + $this->__RoomsLibCache->saveCache('tables', null, $retTables); + + return $retTables; + } + +/** + * schemaファイルからテーブルリストを取得する + * + * @return array + */ + private function __findAllSchemeFileTables() { + App::uses('CakeSchema', 'Model'); + $plugins = App::objects('plugins'); + + $allTables = []; + foreach ($plugins as $plugin) { + $tables = $this->__getSchemeFileTablesByPlugin($plugin); + if ($tables) { + $allTables = array_merge($allTables, $tables); + } + } + + return $allTables; + } + +/** + * プラグイン名に対してschemaファイルのテーブルリストを取得する + * + * @param string $plugin プラグイン + * @return array|false + */ + private function __getSchemeFileTablesByPlugin($plugin) { + $class = $plugin . 'Schema'; + $filePath = App::pluginPath($plugin) . 'Config' . DS . 'Schema' . DS . 'schema.php'; + if (! file_exists($filePath)) { + return false; + } + include_once $filePath; + if (! class_exists($class)) { + return false; + } + $classVars = get_class_vars($class); + + $tables = []; + foreach ($classVars as $key => $value) { + if (is_array($value) && !empty($value)) { + $tables[] = $key; + } + } + + return $tables; + } + +/** + * DBからカラムリストを取得する + * + * @param string $realTableName テーブルPrefix付きの実際のテーブル名 + * @return array + */ + public function showTableColumns($realTableName) { + $columns = $this->__Model->query('SHOW COLUMNS FROM ' . $realTableName); + + $retColumns = []; + foreach ($columns as $column) { + $name = $column['COLUMNS']['Field']; + $retColumns[$name] = $column['COLUMNS']; + } + return $retColumns; + } + +/** + * SELECTのSQLを実行する + * + * @param string $tableName テーブル名 + * @param array $selectFieldNames SELECTのカラム名リスト + * @param string $whereFieldName WHEREのカラム名 + * @param array $values 取得する値 + * @return array + */ + public function selectQuery($tableName, $selectFieldNames, $whereFieldName, $values) { + $tablePrefix = $this->__Model->tablePrefix; + $realTableName = $tablePrefix . $tableName; + $tableAlias = Inflector::classify($tableName); + + $fields = array_map(function ($fieldName) use ($tableAlias) { + return $this->__Model->escapeField($fieldName, $tableAlias); + }, $selectFieldNames); + + $sql = sprintf( + 'SELECT %s FROM `%s` AS `%s` WHERE %s', + implode(', ', $fields), + $realTableName, + $tableAlias, + $this->__makeWhereSql($tableAlias, $whereFieldName, $values) + ); + + $queryResults = $this->__Model->query($sql); + return $this->__flattenForDeleteTargetValues($tableName, $tableAlias, $queryResults); + } + +/** + * SELECT COUNT(*)のSQLを実行する + * + * @param string $tableName テーブル名 + * @param string $whereFieldName WHEREのカラム名 + * @param array $values 取得する値 + * @return array + */ + public function countQuery($tableName, $whereFieldName, $values) { + $tablePrefix = $this->__Model->tablePrefix; + $realTableName = $tablePrefix . $tableName; + $tableAlias = Inflector::classify($tableName); + + $sql = sprintf( + 'SELECT COUNT(*) AS count_num FROM `%s` AS `%s` WHERE %s', + $realTableName, + $tableAlias, + $this->__makeWhereSql($tableAlias, $whereFieldName, $values) + ); + + $queryResults = $this->__Model->query($sql); + if (isset($queryResults[0][0]['count_num'])) { + $count = (int)$queryResults[0][0]['count_num']; + } else { + $count = 0; + } + + return $count; + } + +/** + * DELETEのSQLを実行する + * + * @param string $tableName テーブル名 + * @param string $whereFieldName WHEREのカラム名 + * @param array $values 取得する値 + * @return array + */ + public function deleteQuery($tableName, $whereFieldName, $values) { + $tablePrefix = $this->__Model->tablePrefix; + $realTableName = $tablePrefix . $tableName; + $tableAlias = Inflector::classify($tableName); + + $sql = sprintf( + 'DELETE FROM `%s` WHERE %s', + $realTableName, + $this->__makeWhereSql($realTableName, $whereFieldName, $values) + ); + +\CakeLog::debug(__METHOD__ . '(' . __LINE__ . ') ' . var_export($sql, true)); + + $queryResults = $this->__Model->query($sql); + return $queryResults; + } + +/** + * 外部フィードキーに対して、削除対象データを取得する + * + * @param string $tableName テーブル名 + * @param string $forienConditions 外部フィールドの条件(変換後) + * @return array + */ + private function __makeWhereSql($tableAlias, $fieldName, $values) { + $whereField = $this->__Model->escapeField($fieldName, $tableAlias); + + if (is_array($values)) { + $escapeValuesArr = array_map(function ($value) { + return $this->__DataSource->value($value, 'string'); + }, $values); + $escapeValues = implode(', ', $escapeValuesArr); + $whereCondition = $whereField . ' IN (' . $escapeValues . ')'; + } else { + $escapeValues = $this->__DataSource->value($values, 'string'); + $whereCondition = $whereField . '=' . $escapeValues; + } + return $whereCondition; + } + +/** + * 外部フィードキーに対して、削除対象データを取得する + * + * @param string $tableName テーブル名 + * @param string $forienConditions 外部フィールドの条件(変換後) + * @return array + */ + private function __flattenForDeleteTargetValues($tableName, $tableAlias, $queryResults) { + $retResults = []; + if (empty($queryResults)) { + return $retResults; + } + + foreach ($queryResults as $result){ + foreach ($result[$tableAlias] as $field => $value) { + if (! isset($retResults[$tableName . '.' . $field])) { + $retResults[$tableName . '.' . $field] = []; + } + $retResults[$tableName . '.' . $field][] = $value; + } + } + + return $retResults; + } + +} diff --git a/Lib/RoomsLibDeleteRoomTables.php b/Lib/RoomsLibDeleteRoomTables.php new file mode 100644 index 0000000..01bcfba --- /dev/null +++ b/Lib/RoomsLibDeleteRoomTables.php @@ -0,0 +1,348 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('RoomsLibCache', 'Rooms.Lib'); +App::uses('RoomsLibDataSourceExecute', 'Rooms.Lib'); + +/** + * ルーム削除時の関連テーブル削除処理に関するライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + */ +class RoomsLibDeleteRoomTables { + +/** + * データソースオブジェクト + * + * @var DataSource + */ + private $__DataSource; + +/** + * 使用するモデル + * + * @var Model + */ + private $__Model; + +/** + * キャッシュオブジェクト + * + * @var RoomsLibCache + */ + private $__RoomsLibCache; + +/** + * キャッシュオブジェクト + * + * @var RoomsLibDataSourceExecute + */ + private $__RoomsLibDataSourceExecute; + +/** + * テーブル情報 + * + * @var array + */ + private $__tables = []; + +/** + * 除外するテーブル + * + * ※定数扱いだが、php7からconstに配列が使用できるが、php5はconstに配列が使えないためprivateのメンバー変数とする + * + * @var array + */ + private $__defIgnoreTables = [ + 'rooms', 'pages', 'blocks', 'frames', 'room_delete_related_tables', 'roles_rooms' + ]; + +/** + * コンストラクタ + * + * @param Model $Model モデル(当モデルは、MySQLのModelであれば何でも良い) + * @return void + */ + public function __construct(Model $Model) { + $this->__Model = $Model; + $this->__DataSource = $Model->getDataSource(); + $this->__RoomsLibCache = new RoomsLibCache($Model); + $this->__RoomsLibDataSourceExecute = new RoomsLibDataSourceExecute($Model); + + $this->__tables = $this->__RoomsLibDataSourceExecute->showTables(); + } + +/** + * テーブルリストを取得する + * + * @return array + */ + public function getTableList() { + if ($this->__tables) { + return array_keys($this->__tables); + } else { + return []; + } + } + +/** + * カラム情報を取得する + * + * @param string $tableName テーブル名 + * @return array + */ + private function __getColumns($tableName) { + if (isset($this->__tables[$tableName])) { + return $this->__tables[$tableName]; + } else { + return []; + } + } + +/** + * テーブルに対する関連するテーブルリストを取得する + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param string $foreignKey 外部キーフィールド名 + * @return array + */ + public function findDeleteTargetRelatedTables($tableName, $fieldName, $foreignKey) { + //キャッシュから取得 + $cacheTables = $this->__RoomsLibCache->readCache( + 'delete_related_tables', + $tableName . '_' . $fieldName . '_' . $foreignKey + ); + if ($cacheTables) { + return $cacheTables; + } + + //戻り値の関連テーブルリストを取得する + $retRelatedTables = []; + $ignoreTables = []; + if (isset($this->__tables[$tableName][$fieldName])) { + $this->__setRecursiveReletedTables( + $tableName, $fieldName, $foreignKey, $retRelatedTables, $ignoreTables + ); + } + + //キャッシュに登録 + $this->__RoomsLibCache->saveCache( + 'delete_related_tables', + $tableName . '_' . $fieldName . '_' . $foreignKey, + $retRelatedTables + ); + + return $retRelatedTables; + } + +/** + * テーブルに対する関連するテーブルリストを再帰的に取得する + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param string $foreignKey 外部キーフィールド名 + * @param array &$retRelatedTables 戻り値の関連テーブルリスト + * @param array &$ignoreTables 除外するテーブルリスト(一度設定したものを除外するため) + * @return void + */ + private function __setRecursiveReletedTables( + $tableName, $fieldName, $foreignKey, &$retRelatedTables, &$ignoreTables) { + $relatedTableNames = array_keys($this->__tables); + foreach ($relatedTableNames as $relatedTableName) { + if (in_array($relatedTableName, $ignoreTables, true) || + in_array($relatedTableName, $this->__defIgnoreTables, true)) { + continue; + } + + $columns = $this->__getColumns($relatedTableName); + if (! isset($columns[$foreignKey])) { + continue; + } + + //戻り値の関連テーブルリストにセットする + if (! isset($retRelatedTables[$tableName][$fieldName])) { + $retRelatedTables[$tableName][$fieldName] = []; + } + $retRelatedTables[$tableName][$fieldName][] = $relatedTableName . '.' . $foreignKey; + $ignoreTables[] = $relatedTableName; + + //idカラムがある場合、再帰的に取得する + if (isset($columns['id'])) { + $relatedForeignKey = $this->__makeForeignKey($relatedTableName, 'id'); + $this->__setRecursiveReletedTables( + $relatedTableName, 'id', $relatedForeignKey, $retRelatedTables, $ignoreTables + ); + } + //keyカラムがある場合、再帰的に取得する + if (isset($columns['key'])) { + $relatedForeignKey = $this->__makeForeignKey($relatedTableName, 'key'); + $this->__setRecursiveReletedTables( + $relatedTableName, 'key', $relatedForeignKey, $retRelatedTables, $ignoreTables + ); + } + } + + return $retRelatedTables; + } + +/** + * 外部キーのテーブル名、カラム名を取得する + * + * @param string $fieldName カラム名 + * @return array $ret = [テーブル名, カラム名] + */ + private function __getTableAndFieldByForeignKey($fieldName) { + if (substr($fieldName, -3) === '_id') { + if (substr($fieldName, 0, -3) === 'bbs') { + return ['bbses', 'id']; + } else { + return [Inflector::pluralize(substr($fieldName, 0, -3)), 'id']; + } + } elseif (substr($fieldName, -4) === '_key') { + if (substr($fieldName, 0, -4) === 'bbs') { + return ['bbses', 'key']; + } else { + return [Inflector::pluralize(substr($fieldName, 0, -4)), 'key']; + } + } else { + return [null, null]; + } + } + +/** + * 外部キーのカラム名を生成する + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @return string + */ + private function __makeForeignKey($tableName, $fieldName) { + $foreignKey = Inflector::singularize($tableName) . '_' . $fieldName; + if ($tableName === 'bbses') { + $foreignKey = 'bbs_' . $fieldName; + } else { + $foreignKey = Inflector::singularize($tableName) . '_' . $fieldName; + } + return $foreignKey; + } + +/** + * 外部フィールドキーの条件からテーブルリストに展開する + * + * @param string $tableName テーブル名 + * @param string $forienConditions 外部フィールドの条件(変換後) + * @return array + */ + public function expandToTablesFromForienConditions($tableName, $forienConditions) { + //キャッシュから取得 + $cacheTables = $this->__RoomsLibCache->readCache('expand_to_tables', $tableName); + if ($cacheTables) { + return $cacheTables; + } + + //外部フィールドキーの条件からテーブルリストに展開する + $retTables = []; + foreach ($forienConditions as $fieldName => $conditions) { + foreach ($conditions as $condition) { + list($relatedTableName, $foriegnKey) = explode('.', $condition); + if ($relatedTableName === '*') { + $retTables = array_merge( + $retTables, + $this->findDeleteTargetRelatedTables($tableName, $fieldName, $foriegnKey) + ); + } else { + if (! isset($retTables[$tableName][$fieldName])) { + $retTables[$tableName][$fieldName] = []; + } + $retTables[$tableName][$fieldName][] = $relatedTableName . '.' . $foriegnKey; + } + } + } + + //キャッシュに登録 + $this->__RoomsLibCache->saveCache('expand_to_tables', $tableName, $retTables); + + return $retTables; + } + +/** + * 関連データを削除する + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param string $value 値 + * @param string $forienConditions 外部フィールドの条件 + * @return void + */ + public function deleteRelatedTables($tableName, $fieldName, $value, $foreignConditions) { + $retRelatedValues = []; + + $targetTableList = $this->expandToTablesFromForienConditions( + $tableName, + RoomsLibForeignConditionsParser::invertDbValue($foreignConditions) + ); + + $this->__runDeleteRecursiveRelatedTables( + $tableName, $fieldName, [$value], $targetTableList + ); + } + +/** + * 再帰的に削除処理を実行する + * + * @param string $tableFieldName テーブル名とカラム名を連結したもの + * @param array $values 値 + * @param array $targetTableList 対象テーブルリスト + * @return array + */ + private function __runDeleteRecursiveRelatedTables( + $tableName, $fieldName, $values, $targetTableList) { + //テーブルリストに対象のテーブルがあれば、 + if (! isset($targetTableList[$tableName][$fieldName])) { + return; + } + foreach ($targetTableList[$tableName][$fieldName] as $relatedTableField) { + list($relatedTableName, $relatedFieldName) = explode('.', $relatedTableField); + + if (isset($targetTableList[$relatedTableName])) { + //再帰する場合 + $results = $this->__RoomsLibDataSourceExecute->selectQuery( + $relatedTableName, + array_keys($targetTableList[$relatedTableName]), + $relatedFieldName, + $values + ); + + if ($results) { + foreach ($results as $recursiveTableField => $recursiveValues) { + list($recursiveTableName, $recursiveFieldName) = explode('.', $recursiveTableField); + $this->__runDeleteRecursiveRelatedTables( + $recursiveTableName, + $recursiveFieldName, + $recursiveValues, + $targetTableList + ); + } + $this->__RoomsLibDataSourceExecute->deleteQuery($relatedTableName, $relatedFieldName, $values); + } + } else { + //再帰しない場合 + if ($this->__RoomsLibDataSourceExecute->countQuery($relatedTableName, $relatedFieldName, $values)) { + $this->__RoomsLibDataSourceExecute->deleteQuery($relatedTableName, $relatedFieldName, $values); + } + } + + } + } + +} diff --git a/Lib/RoomsLibForeignConditionsParser.php b/Lib/RoomsLibForeignConditionsParser.php new file mode 100644 index 0000000..0434eab --- /dev/null +++ b/Lib/RoomsLibForeignConditionsParser.php @@ -0,0 +1,88 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('RoomsLibDeleteRoomTables', 'Rooms.Lib'); + +/** + * ルーム削除時の関連テーブルのforeign_field_conditionsのパーサ処理に関するライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + */ +class RoomsLibForeignConditionsParser { + +/** + * 条件のデフォルト値 + * + * ※定数扱いだが、php7からconstに配列が使用できるが、php5はconstに配列が使えないためprivateのメンバー変数とする + * + * @var array + */ + private static $__defaultConditions = [ + 'rooms' => [ + 'id' => ['*.room_id'], + ], + 'blocks' => [ + 'id' => ['*.block_id'], + 'key' => ['*.block_key'], + ], + 'pages' => [ + 'id' => ['*.page_id'], + ], + 'users' => [ + 'id' => [ + '*.user_id', + 'calendar_event_share_users.share_user', + 'groups.created_user', + 'reservation_event_share_users.share_user' + ], + ], + 'frames' => [ + 'id' => ['*.frame_id'], + 'key' => ['*.frame_key'], + ], + ]; + +/** + * foreign_field_conditionsのデータ取得する + * + * @param string $tableName テーブル名 + * @return array + */ + public static function getForeignCondition($tableName) { + if (isset(self::$__defaultConditions[$tableName])) { + return self::$__defaultConditions[$tableName]; + } else { + return []; + } + } + +/** + * 外部フィールドのDBに登録する値に変換する + * + * @param array $value 外部フィールドの条件(変換前) + * @return string + */ + public static function convertDbValue($value) { + return json_encode($value); + } + +/** + * 外部フィールドのDBに登録するから処理できる型に変換する + * + * @param string $value 外部フィールドの条件(変換後) + * @return array + */ + public static function invertDbValue($value) { + return json_decode($value, true); + } + +} diff --git a/Locale/jpn/LC_MESSAGES/rooms.po b/Locale/jpn/LC_MESSAGES/rooms.po index 98dac67..beaa33e 100644 --- a/Locale/jpn/LC_MESSAGES/rooms.po +++ b/Locale/jpn/LC_MESSAGES/rooms.po @@ -233,3 +233,18 @@ msgstr "%sに変更する" #: Rooms/View/Elements/Rooms/edit_form.ctp:64 msgid "Last access datetime" msgstr "最終アクセス日時" + +# +# 削除ルームに対する関連テーブル削除シェル +# +msgid "Delete room associations Shell" +msgstr "削除ルームに対する関連テーブルのデータ削除" + +msgid "Process limit" +msgstr "処理件数" + +msgid "Process room id" +msgstr "処理するルームID" + +msgid "All records" +msgstr "全レコード" diff --git a/Model/RoomDeleteRelatedTable.php b/Model/RoomDeleteRelatedTable.php index 08a87a3..0063e30 100644 --- a/Model/RoomDeleteRelatedTable.php +++ b/Model/RoomDeleteRelatedTable.php @@ -10,6 +10,7 @@ */ App::uses('RoomsAppModel', 'Rooms.Model'); +App::uses('RoomsLibForeignConditionsParser', 'Rooms.Lib'); /** * ルーム削除時に関連して削除するテーブル Model @@ -19,36 +20,6 @@ */ class RoomDeleteRelatedTable extends RoomsAppModel { -/** - * 削除 - * - * @var array - */ - private $__defaultConditions = [ - 'rooms' => [ - 'id' => ['*.room_id'], - ], - 'blocks' => [ - 'id' => ['*.block_id'], - 'key' => ['*.block_key'], - ], - 'pages' => [ - 'id' => ['*.page_id'], - ], - 'users' => [ - 'id' => [ - '*.user_id', - 'calendar_event_share_users.share_user', - 'groups.created_user', - 'reservation_event_share_users.share_user' - ], - ], - 'frames' => [ - 'id' => ['*.frame_id'], - 'key' => ['*.frame_key'], - ], - ]; - /** * ルームIDを基にルーム削除関連データを追加 * @@ -76,11 +47,13 @@ public function insertByRoomId($roomId) { try { $table = $this->Room->table; $this->__execInsertQuery( - $roomId, 'id', $roomId, $table, 'id', $this->__defaultConditions[$table] + $roomId, 'id', $roomId, $table, 'id', + RoomsLibForeignConditionsParser::getForeignCondition($table) ); foreach ($targetTables as $table) { - foreach ($this->__defaultConditions[$table] as $field => $condition) { + $foreignConditions = RoomsLibForeignConditionsParser::getForeignCondition($table); + foreach ($foreignConditions as $field => $condition) { $this->__execInsertQuery( $roomId, 'room_id', $roomId, $table, $field, [$field => $condition] ); @@ -114,7 +87,8 @@ public function insertUser($userId, $roomId) { try { $table = $this->User->table; $this->__execInsertQuery( - $roomId, 'id', $userId, $table, 'id', $this->__defaultConditions[$table] + $roomId, 'id', $userId, $table, 'id', + RoomsLibForeignConditionsParser::getForeignCondition($table) ); //トランザクションCommit From 3642ca958ca5c0165c192d1b6786e92245cc3d35 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 12 Oct 2019 10:12:48 +0900 Subject: [PATCH 03/28] =?UTF-8?q?fix:=20=E5=89=8A=E9=99=A4=E5=87=A6?= =?UTF-8?q?=E7=90=86=E8=BF=BD=E5=8A=A0=20https://github.com/NetCommons3/Ne?= =?UTF-8?q?tCommons3/issues/735?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1570717849_add_column_end_time.php | 67 +++++ Config/Schema/schema.php | 49 ++-- Console/Command/DeleteNotUsedUsersShell.php | 268 ++++++++++++++++++ Console/Command/DeleteRelatedRoomsShell.php | 67 +++++ .../Command/DeleteRoomAssociationsShell.php | 133 --------- .../Command/Task/DeleteRelatedRoomsTask.php | 141 +++++++++ Lib/RoomsLibCache.php | 4 +- Lib/RoomsLibCommandExec.php | 59 ++++ Lib/RoomsLibDataSourceExecute.php | 92 +++--- Lib/RoomsLibDeleteRoomTables.php | 207 +++++++++----- Lib/RoomsLibLog.php | 219 ++++++++++++++ Locale/jpn/LC_MESSAGES/rooms.po | 3 + Model/Room.php | 4 + Model/RoomDeleteRelatedTable.php | 77 +++++ 14 files changed, 1130 insertions(+), 260 deletions(-) create mode 100644 Config/Migration/1570717849_add_column_end_time.php create mode 100644 Console/Command/DeleteNotUsedUsersShell.php create mode 100644 Console/Command/DeleteRelatedRoomsShell.php delete mode 100644 Console/Command/DeleteRoomAssociationsShell.php create mode 100644 Console/Command/Task/DeleteRelatedRoomsTask.php create mode 100644 Lib/RoomsLibCommandExec.php create mode 100644 Lib/RoomsLibLog.php diff --git a/Config/Migration/1570717849_add_column_end_time.php b/Config/Migration/1570717849_add_column_end_time.php new file mode 100644 index 0000000..9e7e797 --- /dev/null +++ b/Config/Migration/1570717849_add_column_end_time.php @@ -0,0 +1,67 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); + +/** + * ルーム削除時に不要データを削除するために使用するテーブルに終了日時を追加 + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Config\Migration + */ +class AddColumnEndTime extends CakeMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'add_column_end_time'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'create_field' => array( + 'room_delete_related_tables' => array( + 'end_time' => array('type' => 'datetime', 'null' => true, 'default' => null, 'after' => 'start_time'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'room_delete_related_tables' => array('end_time'), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 59c9052..4cbf0d7 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -92,6 +92,31 @@ public function after($event = array()) { 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); +/** + * room_delete_related_tables table + * + * @var array + */ + public $room_delete_related_tables = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), + 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => 'ルームID'), + 'delete_table_name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '削除するテーブル名 rooms|blokcs|pages|users|frames|roles_rooms', 'charset' => 'utf8'), + 'field_name' => array('type' => 'string', 'null' => false, 'default' => 'id', 'collate' => 'utf8_general_ci', 'comment' => 'カラム名', 'charset' => 'utf8'), + 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '値', 'charset' => 'utf8'), + 'foreign_field_conditions' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 1200, 'collate' => 'utf8_general_ci', 'comment' => '対象とするカラムリストをJSON形式で保持 ex) {"id":["*.block_id"], "key":["*.block_key"]}', 'charset' => 'utf8'), + 'start_time' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'end_time' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'room_id' => array('column' => 'room_id', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + /** * room_role_permissions table * @@ -171,30 +196,6 @@ public function after($event = array()) { 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); -/** - * room_delete_related_tables table - * - * @var array - */ - public $room_delete_related_tables = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), - 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => 'ルームID'), - 'delete_table_name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '削除するテーブル名 rooms|blokcs|pages|users|frames|roles_rooms', 'charset' => 'utf8'), - 'field_name' => array('type' => 'string', 'null' => false, 'default' => 'id', 'collate' => 'utf8_general_ci', 'comment' => 'カラム名', 'charset' => 'utf8'), - 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '値', 'charset' => 'utf8'), - 'foreign_field_conditions' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 1200, 'collate' => 'utf8_general_ci', 'comment' => '対象とするカラムリストをJSON形式で保持 ex) {"id":["*.block_id"], "key":["*.block_key"]}', 'charset' => 'utf8'), - 'start_time' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'room_id' => array('column' => 'room_id', 'unique' => 0) - ), - 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') - ); - /** * rooms_languages table * diff --git a/Console/Command/DeleteNotUsedUsersShell.php b/Console/Command/DeleteNotUsedUsersShell.php new file mode 100644 index 0000000..938627b --- /dev/null +++ b/Console/Command/DeleteNotUsedUsersShell.php @@ -0,0 +1,268 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('AppShell', 'Console/Command'); +App::uses('RoomsLibForeignConditionsParser', 'Rooms.Lib'); +App::uses('RoomsLibDeleteRoomTables', 'Rooms.Lib'); +App::uses('RoomsLibLog', 'Rooms.Lib'); +App::uses('SiteSettingUtil', 'SiteManager.Utility'); + +/** + * ルーム削除した際の関連テーブルのデータを削除する + * + * @property Room $Room + * @property RolesRoomsUser $RolesRoomsUser + * @property User $User + * @property PrivateSpace $PrivateSpace + * @property RoomDeleteRelatedTable $RoomDeleteRelatedTable + * + * @property DeleteRelatedRoomsTask $DeleteRelatedRooms + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Console\Command + */ +class DeleteNotUsedUsersShell extends AppShell { + +/** + * 使用するモデル + * + * @var array + */ + public $uses = [ + 'Rooms.Room', + 'Rooms.RolesRoomsUser', + 'Users.User', + 'PrivateSpace.PrivateSpace', + 'Rooms.RoomDeleteRelatedTable', + ]; + +/** + * 使用するタスク + * + * @var array + */ + public $tasks = [ + 'Rooms.DeleteRelatedRooms', + ]; + +/** + * 一度の処理する件数 + * + * @var int + */ + const PROCESS_COUNT = 10; + +/** + * Override startup + * + * @return void + */ + public function startup() { + $this->out(__d('rooms', 'Delete room associations Shell')); + $this->hr(); + } + +/** + * 処理実行 + * + * @return void + */ + public function main() { + //ログ出力 + RoomsLibLog::shellStartLog($this); + + //プライベートルームのデータ削除 + $result = $this->Room->query( + $this->__makeSqlDeletedPrivateRoom('COUNT(*)') + ); + $totalCount = $result[0][0]['count_num']; + $maxLoop = ceil($totalCount / self::PROCESS_COUNT); + $procCount = 0; + + for ($i = 0; $i < $maxLoop; $i++) { + //ログ出力 + RoomsLibLog::processStartLog( + $this, + sprintf('Delete Private Rooms[%s]', ($i * self::PROCESS_COUNT + 1) . '/' . $totalCount) + ); + + $records = $this->Room->query( + $this->__makeSqlDeletedPrivateRoom($this->Room->alias . '.id') + ); + foreach ($records as $record) { + //$this->out(sprintf('room_id=%s', $record[$this->Room->alias]['id']), 1, self::VERBOSE); + $this->__deleteRoom($record[$this->Room->alias]['id']); + $procCount++; + } + + //ログ出力 + RoomsLibLog::processEndLog( + $this, + sprintf('Delete Private Rooms[%s]', $procCount . '/' . $totalCount) + ); + } + + //ユーザのデータ削除 + $result = $this->User->query( + $this->__makeSqlDeletedUser('COUNT(*)') + ); + $totalCount = $result[0][0]['count_num']; + $maxLoop = ceil($totalCount / self::PROCESS_COUNT); + $procCount = 0; + + for ($i = 0; $i < $maxLoop; $i++) { + //ログ出力 + RoomsLibLog::processStartLog( + $this, + sprintf('Delete Users[%s]', ($i * self::PROCESS_COUNT + 1) . '/' . $totalCount) + ); + + $records = $this->User->query( + $this->__makeSqlDeletedUser($this->User->alias . '.id') + ); + + $this->RoomDeleteRelatedTable->begin(); + foreach ($records as $record) { + try { + //プライベートルーム削除 + //ルーム削除情報を登録する + $this->RoomDeleteRelatedTable->insertUser($record[$this->User->alias]['id'], '0'); + + //トランザクションCommit + $this->RoomDeleteRelatedTable->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->RoomDeleteRelatedTable->rollback($ex); + } + + $procCount++; + } + + //ログ出力 + RoomsLibLog::processEndLog( + $this, + sprintf('Delete Users[%s]', $procCount . '/' . $totalCount) + ); + } + + //関連データの削除 + $this->DeleteRelatedRooms->execute(); + + RoomsLibLog::shellEndLog($this); + } + +/** + * 既に削除されているユーザに対するプライベートルームIDを取得するSQLの生成 + * + * @param string $columnName 取得するカラム名 + * @return void + */ + private function __makeSqlDeletedPrivateRoom($columnName) { + $roomTableName = $this->Room->tablePrefix . $this->Room->table; + $roomAliasName = $this->Room->alias; + $userRoomTableName = $this->RolesRoomsUser->tablePrefix . $this->RolesRoomsUser->table; + $userRoomAliasName = $this->RolesRoomsUser->alias; + + $sqlFromWhere = "{$roomTableName} AS {$roomAliasName} " . + "LEFT JOIN {$userRoomTableName} AS {$userRoomAliasName} " . + "ON ({$roomAliasName}.id = {$userRoomAliasName}.room_id) " . + "WHERE {$roomAliasName}.space_id = " . Space::PRIVATE_SPACE_ID . " " . + "AND {$roomAliasName}.page_id_top IS NOT NULL " . + "AND {$userRoomAliasName}.id IS NULL"; + + if ($columnName === 'COUNT(*)') { + $sql = "SELECT {$columnName} count_num FROM {$sqlFromWhere}"; + } else { + $sql = "SELECT {$columnName} FROM {$sqlFromWhere} LIMIT " . self::PROCESS_COUNT; + } + + return $sql; + } + +/** + * 既に削除されているユーザに対するプライベートルームIDを取得するSQLの生成 + * + * @param string $columnName 取得するカラム名 + * @return void + */ + private function __makeSqlDeletedUser($columnName) { + $userTableName = $this->User->tablePrefix . $this->User->table; + $usetAliasName = $this->User->alias; + $delRoomTableName = $this->RoomDeleteRelatedTable->tablePrefix . + $this->RoomDeleteRelatedTable->table; + $delRoomAliasName = $this->RoomDeleteRelatedTable->alias; + + $sqlFromWhere = "{$userTableName} AS {$usetAliasName} " . + "LEFT JOIN {$delRoomTableName} AS {$delRoomAliasName} " . + "ON (" . + "{$delRoomAliasName}.delete_table_name = 'users' " . + "AND {$delRoomAliasName}.field_name = 'id' " . + "AND {$delRoomAliasName}.value = {$usetAliasName}.id" . + ") " . + "WHERE {$usetAliasName}.is_deleted = 1 " . + "AND {$delRoomAliasName}.id IS NULL"; + + if ($columnName === 'COUNT(*)') { + $sql = "SELECT {$columnName} count_num FROM {$sqlFromWhere}"; + } else { + $sql = "SELECT {$columnName} FROM {$sqlFromWhere} LIMIT " . self::PROCESS_COUNT; + } + + return $sql; + } + +/** + * ルーム削除 + * + * @param int|string $roomId ルームID + * @return void + */ + private function __deleteRoom($roomId) { + $this->RoomDeleteRelatedTable->begin(); + try { + //プライベートルーム削除 + //ルーム削除情報を登録する + $this->RoomDeleteRelatedTable->insertByRoomId($roomId); + + //roles_roomsデータ削除 + $this->Room->deleteRolesRoomByRoom($roomId); + + //frameデータの削除 + $this->Room->deleteFramesByRoom($roomId); + + //pageデータの削除 + $this->Room->deletePagesByRoom($roomId); + + //blockデータの削除 + $this->Room->deleteBlocksByRoom($roomId); + + //トランザクションCommit + //$this->RoomDeleteRelatedTable->rollback(); + $this->RoomDeleteRelatedTable->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->RoomDeleteRelatedTable->rollback($ex); + } + } + +/** + * 引数の使い方の取得 + * + * @return ConsoleOptionParser + */ + public function getOptionParser() { + $parser = parent::getOptionParser(); + return $parser->description(__d('rooms', 'The Delete room associations Shell')); + } + +} diff --git a/Console/Command/DeleteRelatedRoomsShell.php b/Console/Command/DeleteRelatedRoomsShell.php new file mode 100644 index 0000000..bf96cf7 --- /dev/null +++ b/Console/Command/DeleteRelatedRoomsShell.php @@ -0,0 +1,67 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('AppShell', 'Console/Command'); +App::uses('RoomsLibLog', 'Rooms.Lib'); + +/** + * ルーム削除した際の関連テーブルのデータを削除する + * + * @property DeleteRelatedRoomsTask $DeleteRelatedRooms + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Console\Command + */ +class DeleteRelatedRoomsShell extends AppShell { + +/** + * 使用するタスク + * + * @var array + */ + public $tasks = [ + 'Rooms.DeleteRelatedRooms', + ]; + +/** + * Override startup + * + * @return void + */ + public function startup() { + $this->out(__d('rooms', 'Delete room associations Shell')); + $this->hr(); + } + +/** + * 処理実行 + * + * @return void + */ + public function main() { + RoomsLibLog::shellStartLog($this); + + $this->DeleteRelatedRooms->execute(); + + RoomsLibLog::shellEndLog($this); + } + +/** + * 引数の使い方の取得 + * + * @return ConsoleOptionParser + */ + public function getOptionParser() { + $parser = parent::getOptionParser(); + return $parser->description(__d('rooms', 'The Delete room associations Shell')); + } + +} diff --git a/Console/Command/DeleteRoomAssociationsShell.php b/Console/Command/DeleteRoomAssociationsShell.php deleted file mode 100644 index 8041d59..0000000 --- a/Console/Command/DeleteRoomAssociationsShell.php +++ /dev/null @@ -1,133 +0,0 @@ - - * @author Shohei Nakajima - * @link http://www.netcommons.org NetCommons Project - * @license http://www.netcommons.org/license.txt NetCommons License - * @copyright Copyright 2014, NetCommons Project - */ - -App::uses('AppShell', 'Console/Command'); -App::uses('RoomsLibForeignConditionsParser', 'Rooms.Lib'); -App::uses('RoomsLibDeleteRoomTables', 'Rooms.Lib'); - -/** - * ルーム削除した際の関連テーブルのデータを削除する - * - * @property RoomDeleteRelatedTable $RoomDeleteRelatedTable - * - * @author Shohei Nakajima - * @package NetCommons\Rooms\Console\Command - */ -class DeleteRoomAssociationsShell extends AppShell { - -/** - * 使用するモデル - * - * @var array - */ - public $uses = [ - 'Rooms.RoomDeleteRelatedTable', - ]; - -/** - * DeleteRoomTablesを操作するライブラリ - * - * @var RoomsLibDeleteRoomTables - */ - private $__RoomsLibDeleteRoomTables; - -/** - * Override startup - * - * @return void - */ - public function startup() { - $this->out(__d('rooms', 'Delete room associations Shell')); - $this->hr(); - } - -/** - * 処理実行 - * - * @return void - */ - public function main() { - $this->__RoomsLibDeleteRoomTables = new RoomsLibDeleteRoomTables($this->RoomDeleteRelatedTable); - - $conditions = []; - if ($this->param('all')) { - $conditions = []; - } elseif ($this->param('room-id')) { - $conditions = [ - 'room_id' => $this->param('room-id'), - ]; - } else { - return; - } - - $records = $this->RoomDeleteRelatedTable->find('all', [ - 'recursive' => -1, - 'conditions' => $conditions - ]); - - //トランザクションBegin - $this->RoomDeleteRelatedTable->begin(); -//\CakeLog::debug(__METHOD__ . '(' . __LINE__ . ') ' . var_export($records, true)); - - try { - foreach ($records as $record) { - $this->__RoomsLibDeleteRoomTables->deleteRelatedTables( - $record['RoomDeleteRelatedTable']['delete_table_name'], - $record['RoomDeleteRelatedTable']['field_name'], - $record['RoomDeleteRelatedTable']['value'], - $record['RoomDeleteRelatedTable']['foreign_field_conditions'] - ); - } - - //トランザクションCommit - $this->RoomDeleteRelatedTable->rollback(); - //$this->RoomDeleteRelatedTable->commit(); - - } catch (Exception $ex) { - //トランザクションRollback - $this->RoomDeleteRelatedTable->rollback($ex); - } - - $this->hr(); - } - -/** - * 引数の使い方の取得 - * - * @return ConsoleOptionParser - */ - public function getOptionParser() { - $parser = parent::getOptionParser(); - return $parser->description(__d('rooms', 'The Delete room associations Shell')) - ->addOption( - 'room-id', - [ - 'help' => __d('rooms', 'Process room id'), - ] - ) - ->addOption( - 'limit', - [ - 'help' => __d('rooms', 'Process limit'), - 'default' => 100, - ] - ) - ->addOption( - 'all', - array( - 'short' => 'a', - 'boolean' => true, - 'help' => __d('rooms', 'All records'), - ) - ); - } - -} diff --git a/Console/Command/Task/DeleteRelatedRoomsTask.php b/Console/Command/Task/DeleteRelatedRoomsTask.php new file mode 100644 index 0000000..a3348ba --- /dev/null +++ b/Console/Command/Task/DeleteRelatedRoomsTask.php @@ -0,0 +1,141 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('AppShell', 'Console/Command'); +App::uses('RoomsLibDeleteRoomTables', 'Rooms.Lib'); +App::uses('RoomsLibLog', 'Rooms.Lib'); +App::uses('SiteSettingUtil', 'SiteManager.Utility'); + +/** + * 関連テーブルのデータを削除する + * + * @property RoomDeleteRelatedTable $RoomDeleteRelatedTable + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Console\Command + */ +class DeleteRelatedRoomsTask extends AppShell { + +/** + * 使用するモデル + * + * @var array + */ + public $uses = [ + 'Rooms.RoomDeleteRelatedTable', + ]; + +/** + * DeleteRoomTablesを操作するライブラリ + * + * @var RoomsLibDeleteRoomTables + */ + private $__RoomsLibDeleteRoomTables; + +/** + * 一度の処理する件数 + * + * @var int + */ + const PROCESS_COUNT = 100; + +/** + * タスク実行 + * + * @return void + */ + public function execute() { + $this->__RoomsLibDeleteRoomTables = + new RoomsLibDeleteRoomTables($this->RoomDeleteRelatedTable, $this); + + $tableName = $this->RoomDeleteRelatedTable->tablePrefix . + $this->RoomDeleteRelatedTable->table; + $aliasName = $this->RoomDeleteRelatedTable->alias; + + $result = $this->RoomDeleteRelatedTable->query( + "SELECT COUNT(*) count_num FROM {$tableName} AS {$aliasName}" . + " WHERE {$aliasName}.end_time IS NULL" . + //" AND {$aliasName}.room_id = 23" + //" AND {$aliasName}.id = 1420" + " FOR UPDATE" + ); + if (empty($result)) { + return $this->_stop(); + } + + $totalCount = $result[0][0]['count_num']; + $maxLoop = ceil($totalCount / self::PROCESS_COUNT); + $procCount = 0; + + for ($i = 0; $i < $maxLoop; $i++) { + //ログ出力 + RoomsLibLog::processStartLog( + $this, + sprintf('Delete Related Tables[%s]', ($i * self::PROCESS_COUNT + 1) . '/' . $totalCount) + ); + + $records = $this->RoomDeleteRelatedTable->query( + "SELECT {$aliasName}.* FROM {$tableName} AS {$aliasName}" . + " WHERE {$aliasName}.end_time IS NULL" . + //" AND {$aliasName}.room_id = 23" + //" AND {$aliasName}.id = 1420" . + " LIMIT " . self::PROCESS_COUNT + ); + + //トランザクションBegin + $this->RoomDeleteRelatedTable->begin(); + + try { + foreach ($records as $record) { + $recordId = $record['RoomDeleteRelatedTable']['id']; + $this->RoomDeleteRelatedTable->updateStartTime($recordId); + + $this->__RoomsLibDeleteRoomTables->deleteRelatedTables( + $record['RoomDeleteRelatedTable']['delete_table_name'], + $record['RoomDeleteRelatedTable']['field_name'], + $record['RoomDeleteRelatedTable']['value'], + $record['RoomDeleteRelatedTable']['foreign_field_conditions'] + ); + + $this->RoomDeleteRelatedTable->updateEndTime($recordId); + + $procCount++; + } + + //トランザクションCommit + $this->RoomDeleteRelatedTable->commit(); + //$this->RoomDeleteRelatedTable->rollback(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->RoomDeleteRelatedTable->rollback($ex); + } + + //ログ出力 + RoomsLibLog::processEndLog( + $this, + sprintf('Delete Related Tables[%s]', $procCount . '/' . $totalCount) + ); + } + } + +/** + * 引数の使い方の取得 + * + * @return ConsoleOptionParser + */ + public function getOptionParser() { + $parser = parent::getOptionParser(); + + return $parser->description(__d('rooms', 'The Delete room associations Shell')); + } + +} diff --git a/Lib/RoomsLibCache.php b/Lib/RoomsLibCache.php index e6dabaf..d92ceea 100644 --- a/Lib/RoomsLibCache.php +++ b/Lib/RoomsLibCache.php @@ -36,12 +36,14 @@ public function __construct(Model $Model) { $cacheName = 'delete_rooms_' . $Model->useDbConfig; $isTest = ($Model->useDbConfig === 'test'); $this->__NetCommonsCache = new NetCommonsCache($cacheName, $isTest, 'netcommons_model'); + $this->__NetCommonsCache->clear(); } /** * キャッシュに登録 * * @param string $key キャッシュキー + * @param string $subKey キャッシュサブキー * @param array $value キャッシュに保存する値 * @return array */ @@ -53,7 +55,7 @@ public function saveCache($key, $subKey, $value) { * カラム名に対するテーブルリストを取得する * * @param string $key キャッシュキー - * @param string $subKey キャッシュサブキー + * @param string|null $subKey キャッシュサブキー * @return array */ public function readCache($key, $subKey = null) { diff --git a/Lib/RoomsLibCommandExec.php b/Lib/RoomsLibCommandExec.php new file mode 100644 index 0000000..ad6bc9a --- /dev/null +++ b/Lib/RoomsLibCommandExec.php @@ -0,0 +1,59 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * コマンド実行 ライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + * @see MailSend よりコピー + */ +class RoomsLibCommandExec { + +/** + * 関連データの削除処理のシェルを実行 + * + * @return void + */ + public static function deleteRelatedRooms() { + // バックグラウンドで実行 + // コマンド例) Console/cake rooms.delete_related_rooms + self::__execInBackground(APP . 'Console' . DS . 'cake rooms.delete_related_rooms -q'); + } + +/** + * バックグラウンド実行 + * + * @param string $cmd コマンド + * @return void + */ + private static function __execInBackground($cmd) { + if (self::__isWindows()) { + // Windowsの場合 + pclose(popen('cd ' . APP . ' && start /B ' . $cmd, 'r')); + } else { + // Linuxの場合 + // logrotate問題対応 http://dqn.sakusakutto.jp/2012/08/php_exec_nohup_background.html + exec('nohup ' . $cmd . ' > /dev/null &'); + } + } + +/** + * 動作しているOS がWindows かどうかを返す。 + * + * @return bool + */ + private static function __isWindows() { + if (DIRECTORY_SEPARATOR == '\\') { + return true; + } + return false; + } +} diff --git a/Lib/RoomsLibDataSourceExecute.php b/Lib/RoomsLibDataSourceExecute.php index ed07fc0..a3c2177 100644 --- a/Lib/RoomsLibDataSourceExecute.php +++ b/Lib/RoomsLibDataSourceExecute.php @@ -9,6 +9,8 @@ * @copyright Copyright 2014, NetCommons Project */ +App::uses('RoomsLibLog', 'Rooms.Lib'); + /** * ルーム削除時の関連テーブル削除処理に関するライブラリ * @@ -31,14 +33,23 @@ class RoomsLibDataSourceExecute { */ private $__Model; +/** + * 実行シェル + * + * @var Shell + */ + private $__Shell; + /** * コンストラクタ * * @param Model $Model モデル(当モデルは、MySQLのModelであれば何でも良い) + * @param Shell|null $Shell 実行シェル * @return void */ - public function __construct(Model $Model) { + public function __construct(Model $Model, $Shell = null) { $this->__Model = $Model; + $this->__Shell = $Shell; $this->__DataSource = $Model->getDataSource(); $this->__RoomsLibCache = new RoomsLibCache($Model); } @@ -71,7 +82,7 @@ public function showTables() { ! in_array($tableName, $schemaTables)) { continue; } - $retTables[$tableName] = $this->__showDbTableColumns($realTableName); + $retTables[$tableName] = $this->showTableColumns($realTableName); } //キャッシュに登録 @@ -108,7 +119,10 @@ private function __findAllSchemeFileTables() { */ private function __getSchemeFileTablesByPlugin($plugin) { $class = $plugin . 'Schema'; - $filePath = App::pluginPath($plugin) . 'Config' . DS . 'Schema' . DS . 'schema.php'; + if (! CakePlugin::loaded($plugin)) { + return false; + } + $filePath = CakePlugin::path($plugin) . 'Config' . DS . 'Schema' . DS . 'schema.php'; if (! file_exists($filePath)) { return false; } @@ -150,11 +164,10 @@ public function showTableColumns($realTableName) { * * @param string $tableName テーブル名 * @param array $selectFieldNames SELECTのカラム名リスト - * @param string $whereFieldName WHEREのカラム名 - * @param array $values 取得する値 + * @param array $wheres WHERE条件リスト * @return array */ - public function selectQuery($tableName, $selectFieldNames, $whereFieldName, $values) { + public function selectQuery($tableName, $selectFieldNames, $wheres) { $tablePrefix = $this->__Model->tablePrefix; $realTableName = $tablePrefix . $tableName; $tableAlias = Inflector::classify($tableName); @@ -168,7 +181,7 @@ public function selectQuery($tableName, $selectFieldNames, $whereFieldName, $val implode(', ', $fields), $realTableName, $tableAlias, - $this->__makeWhereSql($tableAlias, $whereFieldName, $values) + $this->__makeWhereSql($tableAlias, $wheres) ); $queryResults = $this->__Model->query($sql); @@ -179,11 +192,10 @@ public function selectQuery($tableName, $selectFieldNames, $whereFieldName, $val * SELECT COUNT(*)のSQLを実行する * * @param string $tableName テーブル名 - * @param string $whereFieldName WHEREのカラム名 - * @param array $values 取得する値 + * @param array $wheres WHERE条件リスト * @return array */ - public function countQuery($tableName, $whereFieldName, $values) { + public function countQuery($tableName, $wheres) { $tablePrefix = $this->__Model->tablePrefix; $realTableName = $tablePrefix . $tableName; $tableAlias = Inflector::classify($tableName); @@ -192,7 +204,7 @@ public function countQuery($tableName, $whereFieldName, $values) { 'SELECT COUNT(*) AS count_num FROM `%s` AS `%s` WHERE %s', $realTableName, $tableAlias, - $this->__makeWhereSql($tableAlias, $whereFieldName, $values) + $this->__makeWhereSql($tableAlias, $wheres) ); $queryResults = $this->__Model->query($sql); @@ -209,55 +221,65 @@ public function countQuery($tableName, $whereFieldName, $values) { * DELETEのSQLを実行する * * @param string $tableName テーブル名 - * @param string $whereFieldName WHEREのカラム名 - * @param array $values 取得する値 + * @param array $wheres WHERE条件リスト * @return array */ - public function deleteQuery($tableName, $whereFieldName, $values) { + public function deleteQuery($tableName, $wheres) { $tablePrefix = $this->__Model->tablePrefix; $realTableName = $tablePrefix . $tableName; - $tableAlias = Inflector::classify($tableName); $sql = sprintf( 'DELETE FROM `%s` WHERE %s', $realTableName, - $this->__makeWhereSql($realTableName, $whereFieldName, $values) + $this->__makeWhereSql($realTableName, $wheres) ); -\CakeLog::debug(__METHOD__ . '(' . __LINE__ . ') ' . var_export($sql, true)); + RoomsLibLog::infoLog($this->__Shell, $sql, 2); $queryResults = $this->__Model->query($sql); + + RoomsLibLog::successLog( + $this->__Shell, + '--> AffectedRows = ' . $this->__Model->getAffectedRows(), + 2 + ); + return $queryResults; } /** * 外部フィードキーに対して、削除対象データを取得する * - * @param string $tableName テーブル名 - * @param string $forienConditions 外部フィールドの条件(変換後) + * @param string $tableAlias テーブルのAlias名 + * @param array $wheres WHERE条件リスト * @return array */ - private function __makeWhereSql($tableAlias, $fieldName, $values) { - $whereField = $this->__Model->escapeField($fieldName, $tableAlias); - - if (is_array($values)) { - $escapeValuesArr = array_map(function ($value) { - return $this->__DataSource->value($value, 'string'); - }, $values); - $escapeValues = implode(', ', $escapeValuesArr); - $whereCondition = $whereField . ' IN (' . $escapeValues . ')'; - } else { - $escapeValues = $this->__DataSource->value($values, 'string'); - $whereCondition = $whereField . '=' . $escapeValues; + private function __makeWhereSql($tableAlias, $wheres) { + $whereConditions = []; + + foreach ($wheres as $fieldName => $values) { + $whereField = $this->__Model->escapeField($fieldName, $tableAlias); + + if (is_array($values)) { + $escapeValuesArr = array_map(function ($value) { + return $this->__DataSource->value($value, 'string'); + }, $values); + $escapeValues = implode(', ', $escapeValuesArr); + $whereConditions[] = $whereField . ' IN (' . $escapeValues . ')'; + } else { + $escapeValues = $this->__DataSource->value($values, 'string'); + $whereConditions[] = $whereField . '=' . $escapeValues; + } } - return $whereCondition; + return implode(' AND ', $whereConditions); } /** - * 外部フィードキーに対して、削除対象データを取得する + * クエリの結果をフラットの配列(一次配列、「.」で連結)にする * * @param string $tableName テーブル名 - * @param string $forienConditions 外部フィールドの条件(変換後) + * @param string $tableAlias テーブルのAlias名 + * @param array $queryResults クエリの結果 * @return array */ private function __flattenForDeleteTargetValues($tableName, $tableAlias, $queryResults) { @@ -266,7 +288,7 @@ private function __flattenForDeleteTargetValues($tableName, $tableAlias, $queryR return $retResults; } - foreach ($queryResults as $result){ + foreach ($queryResults as $result) { foreach ($result[$tableAlias] as $field => $value) { if (! isset($retResults[$tableName . '.' . $field])) { $retResults[$tableName . '.' . $field] = []; diff --git a/Lib/RoomsLibDeleteRoomTables.php b/Lib/RoomsLibDeleteRoomTables.php index 01bcfba..bf5bf66 100644 --- a/Lib/RoomsLibDeleteRoomTables.php +++ b/Lib/RoomsLibDeleteRoomTables.php @@ -11,6 +11,7 @@ App::uses('RoomsLibCache', 'Rooms.Lib'); App::uses('RoomsLibDataSourceExecute', 'Rooms.Lib'); +App::uses('RoomsLibLog', 'Rooms.Lib'); /** * ルーム削除時の関連テーブル削除処理に関するライブラリ @@ -34,6 +35,20 @@ class RoomsLibDeleteRoomTables { */ private $__Model; +/** + * 実行シェル + * + * @var Shell + */ + private $__Shell = null; + +/** + * UploadFileモデル + * + * @var UploadFile + */ + private $__UploadFile; + /** * キャッシュオブジェクト * @@ -63,22 +78,38 @@ class RoomsLibDeleteRoomTables { * @var array */ private $__defIgnoreTables = [ - 'rooms', 'pages', 'blocks', 'frames', 'room_delete_related_tables', 'roles_rooms' + 'rooms', 'pages', 'blocks', 'frames', 'room_delete_related_tables', + 'roles_rooms' + ]; + +/** + * 除外する外部キー + * + * ※定数扱いだが、php7からconstに配列が使用できるが、php5はconstに配列が使えないためprivateのメンバー変数とする + * + * @var array + */ + private $__defIgnoreForeigns = [ + 'cabinet_file_trees' ]; /** * コンストラクタ * * @param Model $Model モデル(当モデルは、MySQLのModelであれば何でも良い) + * @param Shell|null $Shell 実行シェル * @return void */ - public function __construct(Model $Model) { + public function __construct(Model $Model, $Shell = null) { $this->__Model = $Model; + $this->__Shell = $Shell; $this->__DataSource = $Model->getDataSource(); $this->__RoomsLibCache = new RoomsLibCache($Model); - $this->__RoomsLibDataSourceExecute = new RoomsLibDataSourceExecute($Model); + $this->__RoomsLibDataSourceExecute = new RoomsLibDataSourceExecute($Model, $Shell); $this->__tables = $this->__RoomsLibDataSourceExecute->showTables(); + + $this->__UploadFile = ClassRegistry::init('Files.UploadFile'); } /** @@ -128,10 +159,9 @@ public function findDeleteTargetRelatedTables($tableName, $fieldName, $foreignKe //戻り値の関連テーブルリストを取得する $retRelatedTables = []; - $ignoreTables = []; if (isset($this->__tables[$tableName][$fieldName])) { $this->__setRecursiveReletedTables( - $tableName, $fieldName, $foreignKey, $retRelatedTables, $ignoreTables + $tableName, $fieldName, $foreignKey, $retRelatedTables ); } @@ -152,15 +182,13 @@ public function findDeleteTargetRelatedTables($tableName, $fieldName, $foreignKe * @param string $fieldName カラム名 * @param string $foreignKey 外部キーフィールド名 * @param array &$retRelatedTables 戻り値の関連テーブルリスト - * @param array &$ignoreTables 除外するテーブルリスト(一度設定したものを除外するため) * @return void */ private function __setRecursiveReletedTables( - $tableName, $fieldName, $foreignKey, &$retRelatedTables, &$ignoreTables) { + $tableName, $fieldName, $foreignKey, &$retRelatedTables) { $relatedTableNames = array_keys($this->__tables); foreach ($relatedTableNames as $relatedTableName) { - if (in_array($relatedTableName, $ignoreTables, true) || - in_array($relatedTableName, $this->__defIgnoreTables, true)) { + if (in_array($relatedTableName, $this->__defIgnoreTables, true)) { continue; } @@ -174,20 +202,23 @@ private function __setRecursiveReletedTables( $retRelatedTables[$tableName][$fieldName] = []; } $retRelatedTables[$tableName][$fieldName][] = $relatedTableName . '.' . $foreignKey; - $ignoreTables[] = $relatedTableName; + + if (in_array($relatedTableName, $this->__defIgnoreForeigns, true)) { + continue; + } //idカラムがある場合、再帰的に取得する if (isset($columns['id'])) { $relatedForeignKey = $this->__makeForeignKey($relatedTableName, 'id'); $this->__setRecursiveReletedTables( - $relatedTableName, 'id', $relatedForeignKey, $retRelatedTables, $ignoreTables + $relatedTableName, 'id', $relatedForeignKey, $retRelatedTables ); } //keyカラムがある場合、再帰的に取得する if (isset($columns['key'])) { $relatedForeignKey = $this->__makeForeignKey($relatedTableName, 'key'); $this->__setRecursiveReletedTables( - $relatedTableName, 'key', $relatedForeignKey, $retRelatedTables, $ignoreTables + $relatedTableName, 'key', $relatedForeignKey, $retRelatedTables ); } } @@ -195,30 +226,6 @@ private function __setRecursiveReletedTables( return $retRelatedTables; } -/** - * 外部キーのテーブル名、カラム名を取得する - * - * @param string $fieldName カラム名 - * @return array $ret = [テーブル名, カラム名] - */ - private function __getTableAndFieldByForeignKey($fieldName) { - if (substr($fieldName, -3) === '_id') { - if (substr($fieldName, 0, -3) === 'bbs') { - return ['bbses', 'id']; - } else { - return [Inflector::pluralize(substr($fieldName, 0, -3)), 'id']; - } - } elseif (substr($fieldName, -4) === '_key') { - if (substr($fieldName, 0, -4) === 'bbs') { - return ['bbses', 'key']; - } else { - return [Inflector::pluralize(substr($fieldName, 0, -4)), 'key']; - } - } else { - return [null, null]; - } - } - /** * 外部キーのカラム名を生成する * @@ -239,13 +246,14 @@ private function __makeForeignKey($tableName, $fieldName) { /** * 外部フィールドキーの条件からテーブルリストに展開する * + * @param string $cacheKey キャッシュキー * @param string $tableName テーブル名 * @param string $forienConditions 外部フィールドの条件(変換後) * @return array */ - public function expandToTablesFromForienConditions($tableName, $forienConditions) { + public function expandToTablesFromForienConditions($cacheKey, $tableName, $forienConditions) { //キャッシュから取得 - $cacheTables = $this->__RoomsLibCache->readCache('expand_to_tables', $tableName); + $cacheTables = $this->__RoomsLibCache->readCache('expand_to_tables', $cacheKey); if ($cacheTables) { return $cacheTables; } @@ -270,7 +278,7 @@ public function expandToTablesFromForienConditions($tableName, $forienConditions } //キャッシュに登録 - $this->__RoomsLibCache->saveCache('expand_to_tables', $tableName, $retTables); + $this->__RoomsLibCache->saveCache('expand_to_tables', $cacheKey, $retTables); return $retTables; } @@ -281,13 +289,12 @@ public function expandToTablesFromForienConditions($tableName, $forienConditions * @param string $tableName テーブル名 * @param string $fieldName カラム名 * @param string $value 値 - * @param string $forienConditions 外部フィールドの条件 + * @param string $foreignConditions 外部フィールドの条件 * @return void */ public function deleteRelatedTables($tableName, $fieldName, $value, $foreignConditions) { - $retRelatedValues = []; - $targetTableList = $this->expandToTablesFromForienConditions( + $tableName . '.' . $fieldName, $tableName, RoomsLibForeignConditionsParser::invertDbValue($foreignConditions) ); @@ -295,53 +302,119 @@ public function deleteRelatedTables($tableName, $fieldName, $value, $foreignCond $this->__runDeleteRecursiveRelatedTables( $tableName, $fieldName, [$value], $targetTableList ); + + if ($tableName === 'users') { + $this->deleteAvatar($tableName, 'avatar', $value); + } } /** * 再帰的に削除処理を実行する * - * @param string $tableFieldName テーブル名とカラム名を連結したもの + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 * @param array $values 値 * @param array $targetTableList 対象テーブルリスト * @return array */ private function __runDeleteRecursiveRelatedTables( $tableName, $fieldName, $values, $targetTableList) { - //テーブルリストに対象のテーブルがあれば、 + //テーブルリストに対象のテーブルがあれば、処理する if (! isset($targetTableList[$tableName][$fieldName])) { return; } foreach ($targetTableList[$tableName][$fieldName] as $relatedTableField) { list($relatedTableName, $relatedFieldName) = explode('.', $relatedTableField); + if ($relatedTableName === 'upload_files') { + //アップロードファイル関連でデータ削除 + $this->__runDeleteUploadTables($relatedTableName, $relatedFieldName, $values); + } else { + if (isset($targetTableList[$relatedTableName])) { + //再帰する場合 + $results = $this->__RoomsLibDataSourceExecute->selectQuery( + $relatedTableName, + array_keys($targetTableList[$relatedTableName]), + [$relatedFieldName => $values] + ); - if (isset($targetTableList[$relatedTableName])) { - //再帰する場合 - $results = $this->__RoomsLibDataSourceExecute->selectQuery( - $relatedTableName, - array_keys($targetTableList[$relatedTableName]), - $relatedFieldName, - $values - ); - - if ($results) { - foreach ($results as $recursiveTableField => $recursiveValues) { - list($recursiveTableName, $recursiveFieldName) = explode('.', $recursiveTableField); - $this->__runDeleteRecursiveRelatedTables( - $recursiveTableName, - $recursiveFieldName, - $recursiveValues, - $targetTableList - ); + if ($results) { + foreach ($results as $recursiveTableField => $recursiveValues) { + list($recursiveTableName, $recursiveFieldName) = explode('.', $recursiveTableField); + $this->__runDeleteRecursiveRelatedTables( + $recursiveTableName, + $recursiveFieldName, + $recursiveValues, + $targetTableList + ); + } } - $this->__RoomsLibDataSourceExecute->deleteQuery($relatedTableName, $relatedFieldName, $values); } - } else { - //再帰しない場合 - if ($this->__RoomsLibDataSourceExecute->countQuery($relatedTableName, $relatedFieldName, $values)) { - $this->__RoomsLibDataSourceExecute->deleteQuery($relatedTableName, $relatedFieldName, $values); + + $count = $this->__RoomsLibDataSourceExecute->countQuery( + $relatedTableName, [$relatedFieldName => $values] + ); + if ($count) { + $this->__RoomsLibDataSourceExecute->deleteQuery( + $relatedTableName, [$relatedFieldName => $values] + ); } } + } + } + +/** + * アップロードファイル削除処理を実行する + * + * アップロードは、物理ファイルも消さないといけないので別処理とする。 + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param array $values 値 + * @return array + */ + private function __runDeleteUploadTables($tableName, $fieldName, $values) { + $results = $this->__RoomsLibDataSourceExecute->selectQuery( + $tableName, ['id'], [$fieldName => $values] + ); + if (! empty($results[$tableName . '.id'])) { + $this->deleteUploadTables($results[$tableName . '.id']); + } + } + +/** + * アバターファイル削除処理を実行する + * + * アップロードは、物理ファイルも消さないといけないので別処理とする。 + * + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param int|string $userId 会員ID + * @return array + */ + public function deleteAvatar($tableName, $fieldName, $userId) { + $results = $this->__RoomsLibDataSourceExecute->selectQuery( + 'upload_files', + ['id'], + ['plugin_key' => $tableName, 'field_name' => $fieldName, 'content_key' => $userId] + ); + + if (! empty($results[$tableName . '.id'])) { + $this->deleteUploadTables($results[$tableName . '.id']); + } + } + +/** + * アップロードファイル削除処理を実行する + * + * @param array $fileIds ファイルIDリスト + * @return array + */ + public function deleteUploadTables($fileIds) { + foreach ($fileIds as $fileId) { + RoomsLibLog::infoLog($this->__Shell, 'Delete Upload = ' . $fileId, 2); + $this->__UploadFile->deleteUploadFile($fileId); + RoomsLibLog::successLog($this->__Shell, '--> Success', 2); } } diff --git a/Lib/RoomsLibLog.php b/Lib/RoomsLibLog.php new file mode 100644 index 0000000..8537716 --- /dev/null +++ b/Lib/RoomsLibLog.php @@ -0,0 +1,219 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('Shell', 'Console/Command'); + +/** + * ルーム削除時の関連テーブル削除処理に関するライブラリ + * + * @author Shohei Nakajima + * @package NetCommons\Rooms\Lib + */ +class RoomsLibLog { + +/** + * シェル開始時間 + * + * @var float + */ + private static $__shellStartTime; + +/** + * 処理開始時間 + * + * @var float + */ + private static $__procStartTime; + +/** + * debugとしてログ出力 + * + * @param Shell|null $Shell 実行シェル + * @param string $message 出力するメッセージ + * @param int $indentLevel インデントレベル + * @return void + */ + public static function debugLog($Shell, $message, $indentLevel = 1) { + if (! empty($Shell)) { + $Shell->out( + "" . str_repeat(' ', $indentLevel) . "{$message}", + 1, + Shell::VERBOSE + ); + } + } + +/** + * infoとしてログ出力 + * + * @param Shell|null $Shell 実行シェル + * @param string $message 出力するメッセージ + * @param int $indentLevel インデントレベル + * @return void + */ + public static function infoLog($Shell, $message, $indentLevel = 1) { + if (! empty($Shell)) { + $Shell->out( + "" . str_repeat(' ', $indentLevel) . "{$message}", + 1, + Shell::VERBOSE + ); + } + } + +/** + * successとしてログ出力 + * + * @param Shell|null $Shell 実行シェル + * @param string $message 出力するメッセージ + * @param int $indentLevel インデントレベル + * @return void + */ + public static function successLog($Shell, $message, $indentLevel = 1) { + if (! empty($Shell)) { + $Shell->out( + "" . str_repeat(' ', $indentLevel) . "{$message}", + 1, + Shell::VERBOSE + ); + } + } + +/** + * シェル開始のログ出力 + * + * @param Shell|null $Shell 実行シェル + * @return void + */ + public static function shellStartLog($Shell) { + self::$__shellStartTime = microtime(true); + if (! empty($Shell)) { + $Shell->out(sprintf( + "[SHELL START %s] Memory=%s", + date('Y-m-d H:i:s'), + self::getMemoryUsage() + )); + } + } + +/** + * シェル終了のログ出力 + * + * @param Shell|null $Shell 実行シェル + * @return void + */ + public static function shellEndLog($Shell) { + $endTime = microtime(true); + if (! empty($Shell)) { + $Shell->out(sprintf( + "[SHELL E N D %s] Time=%.4f, Memory=%s", + date('Y-m-d H:i:s'), + ($endTime - self::$__shellStartTime), + self::getMemoryUsage() + )); + } + } + +/** + * 処理開始のログ出力 + * + * @param Shell|null $Shell 実行シェル + * @param string $message 出力するメッセージ + * @param int $indentLevel インデントレベル + * @return void + */ + public static function processStartLog($Shell, $message = '', $indentLevel = 1) { + self::$__procStartTime = microtime(true); + if (! empty($Shell)) { + $Shell->out(sprintf( + str_repeat(' ', $indentLevel) . "[PROCESS START %s] %s Memory=%s", + date('Y-m-d H:i:s'), + $message, + self::getMemoryUsage() + )); + } + } + +/** + * 処理終了のログ出力 + * + * @param Shell|null $Shell 実行シェル + * @param string $message 出力するメッセージ + * @param int $indentLevel インデントレベル + * @return void + */ + public static function processEndLog($Shell, $message = '', $indentLevel = 1) { + $endTime = microtime(true); + if (! empty($Shell)) { + $Shell->out(sprintf( + str_repeat(' ', $indentLevel) . "[PROCESS E N D %s] %s Time=%.4f, Memory=%s", + date('Y-m-d H:i:s'), + $message, + ($endTime - self::$__procStartTime), + self::getMemoryUsage() + )); + } + } + +/** + * メモリー使用量取得 単位付きで取得 + * + * @return string + * @see GetMemoryUsageComponent::execute() からコードをコピペ + */ + public static function getMemoryUsage() { + $size = memory_get_usage(); + return self::__formatMemory($size); + } + +/** + * getPeakMemoryUsage + * + * @return string + */ + public static function getPeakMemoryUsage() { + $size = memory_get_peak_usage(); + return self::__formatMemory($size); + } + +/** + * メモリ使用量のフォーマット + * + * @param int $size memory使用量 + * @return string + */ + private static function __formatMemory($size) { + $byte = 1024; // バイト + $mb = pow($byte, 2); // メガバイト + //$gb = pow($byte, 3); // ギガバイト + + switch(true){ + //case $size >= $gb: + // $target = $gb; + // $unit = 'GB'; + // break; + case $size >= $mb: + $target = $mb; + $unit = 'MB'; + break; + default: + $target = $byte; + $unit = 'KB'; + break; + } + + $newSize = round($size / $target, 3); + $fileSize = number_format($newSize, 3, '.', ',') . $unit; + + return $fileSize; + } + +} diff --git a/Locale/jpn/LC_MESSAGES/rooms.po b/Locale/jpn/LC_MESSAGES/rooms.po index beaa33e..7967a25 100644 --- a/Locale/jpn/LC_MESSAGES/rooms.po +++ b/Locale/jpn/LC_MESSAGES/rooms.po @@ -248,3 +248,6 @@ msgstr "処理するルームID" msgid "All records" msgstr "全レコード" + +msgid "Deleted." +msgstr "削除しました。" diff --git a/Model/Room.php b/Model/Room.php index 32ecc64..8f87369 100644 --- a/Model/Room.php +++ b/Model/Room.php @@ -13,6 +13,7 @@ App::uses('Role', 'Roles.Model'); App::uses('Space', 'Rooms.Model'); App::uses('BlockSettingBehavior', 'Blocks.Model/Behavior'); +App::uses('RoomsLibCommandExec', 'Rooms.Lib'); /** * Room Model @@ -470,6 +471,9 @@ public function afterDelete() { if (! $this->deleteAll(array($this->alias . '.id' => $this->_childRoomIds), false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + + //コマンドライン実行 + RoomsLibCommandExec::deleteRelatedRooms(); } /** diff --git a/Model/RoomDeleteRelatedTable.php b/Model/RoomDeleteRelatedTable.php index 0063e30..8c94a2b 100644 --- a/Model/RoomDeleteRelatedTable.php +++ b/Model/RoomDeleteRelatedTable.php @@ -34,6 +34,10 @@ public function insertByRoomId($roomId) { 'Block' => 'Blocks.Block', ]); + if ($this->__existTableValue($this->Room->table, 'id', $roomId)) { + return; + } + $targetTables = [ //$this->Room->table, $this->Page->table, @@ -80,6 +84,9 @@ public function insertUser($userId, $roomId) { $this->loadModels([ 'User' => 'Users.User', ]); + if ($this->__existTableValue($this->User->table, 'id', $userId)) { + return; + } //トランザクションBegin $this->begin(); @@ -100,6 +107,27 @@ public function insertUser($userId, $roomId) { } } +/** + * 対象テーブルの値が存在するか否か + * + * @param string $tableName 対象テーブル名 + * @param string $fieldName 対象カラム名 + * @param string $value 対象の値 + * + * @return bool + */ + private function __existTableValue($tableName, $fieldName, $value) { + $findTableName = $this->tablePrefix . $this->table; + $result = $this->query( + "SELECT COUNT(*) count_num FROM {$findTableName} AS {$this->alias}" . + " WHERE {$this->alias}.delete_table_name = :tableName" . + " AND {$this->alias}.field_name = :fieldName" . + " AND {$this->alias}.value = :value", + ['tableName' => $tableName, 'fieldName' => $fieldName, 'value' => $value] + ); + return $result[0][0]['count_num'] > 0; + } + /** * ルーム削除に関する情報を追加する * @@ -143,4 +171,53 @@ private function __execInsertQuery( return $this->query($sql); } +/** + * 開始時間の更新 + * + * @param int|string $id ID + * @return bool + */ + public function updateStartTime($id) { + $this->__updateField($id, 'start_time', gmdate('Y-m-d H:i:s')); + } + +/** + * 終了日時の更新 + * + * @param int|string $id ID + * @return bool + */ + public function updateEndTime($id) { + $this->__updateField($id, 'end_time', gmdate('Y-m-d H:i:s')); + } + +/** + * 更新処理 + * + * @param int|string $id ID + * @param string $name カラム名 + * @param string $value 値 + * @return bool|array See Model::save() False on failure or an array of model data on success. + * @see Model::save() + * @link https://book.cakephp.org/2.0/en/models/saving-your-data.html#model-savefield-string-fieldname-string-fieldvalue-validate-false + */ + private function __updateField($id, $name, $value) { + //トランザクションBegin + $this->begin(); + + try { + $this->create(false); + + $options = ['validate' => false, 'fieldList' => [$name]]; + $this->save([$this->alias => [$this->primaryKey => $id, $name => $value]], $options); + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + } + } From ab1a90ecfdcc142a9f60167f13cb691b75df746e Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 15 Oct 2019 17:17:30 +0900 Subject: [PATCH 04/28] =?UTF-8?q?fix:=20Upload=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E9=96=A2=E9=80=A3=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=82=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=81=93=E3=81=A8=E3=81=AB=E3=82=88=E3=82=8B=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0=20https://github.com/researchmap/RmNetCommons3/issues?= =?UTF-8?q?/1409=20https://github.com/researchmap/RmNetCommons3/issues/126?= =?UTF-8?q?9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/RoomsLibDeleteRoomTables.php | 41 ++++++++++++++++++++++---------- Model/RoomDeleteRelatedTable.php | 34 +++++++++++++++++++++----- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/Lib/RoomsLibDeleteRoomTables.php b/Lib/RoomsLibDeleteRoomTables.php index bf5bf66..ed885d4 100644 --- a/Lib/RoomsLibDeleteRoomTables.php +++ b/Lib/RoomsLibDeleteRoomTables.php @@ -79,7 +79,7 @@ class RoomsLibDeleteRoomTables { */ private $__defIgnoreTables = [ 'rooms', 'pages', 'blocks', 'frames', 'room_delete_related_tables', - 'roles_rooms' + 'roles_rooms', 'users' ]; /** @@ -100,7 +100,10 @@ class RoomsLibDeleteRoomTables { * @param Shell|null $Shell 実行シェル * @return void */ - public function __construct(Model $Model, $Shell = null) { + public function __construct($Model = null, $Shell = null) { + if (! $Model) { + $Model = ClassRegistry::init('Rooms.RoomDeleteRelatedTable'); + } $this->__Model = $Model; $this->__Shell = $Shell; $this->__DataSource = $Model->getDataSource(); @@ -304,7 +307,7 @@ public function deleteRelatedTables($tableName, $fieldName, $value, $foreignCond ); if ($tableName === 'users') { - $this->deleteAvatar($tableName, 'avatar', $value); + $this->deleteAttachment($tableName, 'avatar', $value); } } @@ -383,24 +386,24 @@ private function __runDeleteUploadTables($tableName, $fieldName, $values) { } /** - * アバターファイル削除処理を実行する + * アップロードファイル削除処理を実行する * * アップロードは、物理ファイルも消さないといけないので別処理とする。 * * @param string $tableName テーブル名 * @param string $fieldName カラム名 - * @param int|string $userId 会員ID + * @param int|string $contentKey コンテンツキー * @return array */ - public function deleteAvatar($tableName, $fieldName, $userId) { + public function deleteAttachment($tableName, $fieldName, $contentKey) { $results = $this->__RoomsLibDataSourceExecute->selectQuery( 'upload_files', ['id'], - ['plugin_key' => $tableName, 'field_name' => $fieldName, 'content_key' => $userId] + ['plugin_key' => $tableName, 'field_name' => $fieldName, 'content_key' => $contentKey] ); - if (! empty($results[$tableName . '.id'])) { - $this->deleteUploadTables($results[$tableName . '.id']); + if (! empty($results['upload_files.id'])) { + $this->deleteUploadTables($results['upload_files.id']); } } @@ -411,10 +414,22 @@ public function deleteAvatar($tableName, $fieldName, $userId) { * @return array */ public function deleteUploadTables($fileIds) { - foreach ($fileIds as $fileId) { - RoomsLibLog::infoLog($this->__Shell, 'Delete Upload = ' . $fileId, 2); - $this->__UploadFile->deleteUploadFile($fileId); - RoomsLibLog::successLog($this->__Shell, '--> Success', 2); + try { + //トランザクションBegin + $this->__UploadFile->begin(); + + foreach ($fileIds as $fileId) { + RoomsLibLog::infoLog($this->__Shell, 'Delete Upload = ' . $fileId, 2); + $this->__UploadFile->deleteUploadFile($fileId); + RoomsLibLog::successLog($this->__Shell, '--> Success', 2); + } + + //トランザクションCommit + $this->__UploadFile->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->__UploadFile->rollback($ex); } } diff --git a/Model/RoomDeleteRelatedTable.php b/Model/RoomDeleteRelatedTable.php index 8c94a2b..3601abe 100644 --- a/Model/RoomDeleteRelatedTable.php +++ b/Model/RoomDeleteRelatedTable.php @@ -84,7 +84,29 @@ public function insertUser($userId, $roomId) { $this->loadModels([ 'User' => 'Users.User', ]); - if ($this->__existTableValue($this->User->table, 'id', $userId)) { + + $table = $this->User->table; + $this->insert( + $roomId, $table, 'id', $userId, + RoomsLibForeignConditionsParser::getForeignCondition($table) + ); + } + +/** + * ルーム削除関連データを追加 + * + * insertByRoomId()やinsertUser()に含まれないものを追加する時に使用する + * + * @param int|string $roomId ルームID + * @param string $tableName テーブル名 + * @param string $fieldName カラム名 + * @param string|int $value 値 + * @param array $foreignConditions 外部キーリスト + * @return void + */ + public function insert($roomId, $tableName, $fieldName, $value, $foreignConditions) { + //既に登録されているかチェック + if ($this->__existTableValue($tableName, $fieldName, $value)) { return; } @@ -92,10 +114,8 @@ public function insertUser($userId, $roomId) { $this->begin(); try { - $table = $this->User->table; $this->__execInsertQuery( - $roomId, 'id', $userId, $table, 'id', - RoomsLibForeignConditionsParser::getForeignCondition($table) + $roomId, $fieldName, $value, $tableName, $fieldName, $foreignConditions ); //トランザクションCommit @@ -154,7 +174,8 @@ private function __execInsertQuery( 'delete_table_name' => $db->value($targetTableName, 'string'), 'field_name' => $db->value($targetFieldName, 'string'), 'value' => $this->escapeField($targetFieldName, $targetAlias), - 'foreign_field_conditions' => $db->value(json_encode($foreignConditions), 'string'), + 'foreign_field_conditions' => + $db->value(RoomsLibForeignConditionsParser::convertDbValue($foreignConditions), 'string'), 'created' => $db->value(date('Y-m-d H:i:s'), 'string'), 'created_user' => $db->value($loginUserId, 'string'), 'modified' => $db->value(date('Y-m-d H:i:s'), 'string'), @@ -165,7 +186,8 @@ private function __execInsertQuery( ' (' . implode(', ', array_keys($values)) . ')' . ' SELECT ' . implode(', ', $values) . ' FROM ' . $fullTargetTableName . ' AS ' . $targetAlias . - ' WHERE ' . $this->escapeField($findField, $targetAlias) . ' = ' . $findValue; + ' WHERE ' . $this->escapeField($findField, $targetAlias) . + ' = ' . $db->value($findValue, 'string'); //登録処理 return $this->query($sql); From 9fbcb5ecef6c2a27421b42821969aa7eb1c1fb4e Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 13 Nov 2019 14:17:23 +0900 Subject: [PATCH 05/28] =?UTF-8?q?change:=20=E3=83=9D=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=82=AA=E3=83=BC=E3=83=90=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=98=E3=83=AB=E3=83=97=E3=81=AE=E3=82=A2=E3=82=A4?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=81=AF=E3=80=81info=E3=81=A8=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=20https:?= =?UTF-8?q?//github.com/researchmap/RmNetCommons3/issues/1011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- View/Helper/RoomsHelper.php | 2 +- View/Helper/RoomsRolesFormHelper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/View/Helper/RoomsHelper.php b/View/Helper/RoomsHelper.php index 2d91ec6..05f5ab6 100644 --- a/View/Helper/RoomsHelper.php +++ b/View/Helper/RoomsHelper.php @@ -322,7 +322,7 @@ public function roomRoleName($roomRoleKey, $options = []) { ' data-content="' . $roleDesc . '"' . //' data-trigger="focus">'; ' data-trigger="focus">'; - $html .= ''; + $html .= ''; $html .= ''; $html .= ''; diff --git a/View/Helper/RoomsRolesFormHelper.php b/View/Helper/RoomsRolesFormHelper.php index 4126234..2a086f4 100644 --- a/View/Helper/RoomsRolesFormHelper.php +++ b/View/Helper/RoomsRolesFormHelper.php @@ -196,7 +196,7 @@ public function roomRolesDescription($options = []) { ' data-content="' . h($description) . '"' . ' data-trigger="focus">'; - $html .= ''; + $html .= ''; $html .= ''; $html .= ''; From 292a44c5ebfb4be0909c8742acc2bfde5ebf3b76 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 19 Nov 2019 00:21:02 +0000 Subject: [PATCH 06/28] fix: https://github.com/NetCommons3/NetCommons3/issues/1531 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deleteAllでルームに所属するページを全削除していたため、Callbackが走らず、並び順などのデータに狂いが生じる。 ルームのTOPページの1つだけをdeleteするようにして、あとの子ページ群はCallback処理に任せる。 このCallbackを走らせることで通常のページ削除と同様になることを期待する。 --- Model/Behavior/DeleteRoomAssociationsBehavior.php | 15 ++++++++++----- .../DeletePagesByRoomTest.php | 3 +-- Test/Fixture/Page4deleteFixture.php | 15 +++++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Model/Behavior/DeleteRoomAssociationsBehavior.php b/Model/Behavior/DeleteRoomAssociationsBehavior.php index 6ee84a8..043fdb9 100644 --- a/Model/Behavior/DeleteRoomAssociationsBehavior.php +++ b/Model/Behavior/DeleteRoomAssociationsBehavior.php @@ -64,18 +64,23 @@ public function deletePagesByRoom(Model $model, $roomId) { ]); //外部キーがpage_idのデータを削除 - $pageIds = $model->Page->find('list', array( + $page = $model->Page->find('first', array( 'recursive' => -1, //'fields' => array('id', 'key'), 'conditions' => array( $model->Page->alias . '.room_id' => $roomId, + 'root_id = parent_id' ), )); - $pageIds = array_keys($pageIds); + if (! $page) { + return true; // すでに対象のページがないということなので + } + + $pageId = $page['Page']['id']; - //Tree構成の関係で、ページの削除はdeleteAllでやる - if (!$model->Page->deleteAll(array($model->Page->alias . '.id' => $pageIds), false)) { - CakeLog::error('[room deleting] Page->deleteAll ' . implode(', ', $pageIds)); + //Tree構成の関係で、ページの削除はdeleteで親だけを消して、あとはCallbackに任せる + if (!$model->Page->delete(array($model->Page->alias . '.id' => $pageId), false)) { + CakeLog::error('[room deleting] Page->delete ' . $pageId); throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } diff --git a/Test/Case/Model/Behavior/DeleteRoomAssociationsBehavior/DeletePagesByRoomTest.php b/Test/Case/Model/Behavior/DeleteRoomAssociationsBehavior/DeletePagesByRoomTest.php index 60ea29f..004d751 100644 --- a/Test/Case/Model/Behavior/DeleteRoomAssociationsBehavior/DeletePagesByRoomTest.php +++ b/Test/Case/Model/Behavior/DeleteRoomAssociationsBehavior/DeletePagesByRoomTest.php @@ -93,7 +93,7 @@ public function testDeletePagesByRoom($roomId) { * @return void */ public function testDeletePagesByRoomOnExceptionError($roomId) { - $this->_mockForReturnFalse('TestModel', 'Pages.Page', 'deleteAll'); + $this->_mockForReturnFalse('TestModel', 'Pages.Page', 'delete'); //事前チェック $this->__assertTable('Page', 3); @@ -102,7 +102,6 @@ public function testDeletePagesByRoomOnExceptionError($roomId) { $this->setExpectedException('InternalErrorException'); $this->TestModel->deletePagesByRoom($roomId); } - /** * テーブルのチェック * diff --git a/Test/Fixture/Page4deleteFixture.php b/Test/Fixture/Page4deleteFixture.php index 544a114..0dd3c7c 100644 --- a/Test/Fixture/Page4deleteFixture.php +++ b/Test/Fixture/Page4deleteFixture.php @@ -43,7 +43,8 @@ class Page4deleteFixture extends PageFixture { array( 'id' => '1', 'room_id' => '2', - 'parent_id' => null, + 'parent_id' => 1, + 'root_id' => 1, //'lft' => '1', //'rght' => '2', 'weight' => '1', @@ -57,12 +58,13 @@ class Page4deleteFixture extends PageFixture { array( 'id' => '2', 'room_id' => '5', - 'parent_id' => null, + 'parent_id' => 1, + 'root_id' => 1, //'lft' => '3', //'rght' => '4', 'weight' => '2', 'sort_key' => '~00000002', - 'child_count' => '0', + 'child_count' => '1', 'permalink' => 'delete_page_1', 'slug' => 'delete_page_1', 'is_container_fluid' => true, @@ -70,11 +72,12 @@ class Page4deleteFixture extends PageFixture { array( 'id' => '3', 'room_id' => '5', - 'parent_id' => null, + 'parent_id' => 2, + 'root_id' => 1, //'lft' => '5', //'rght' => '6', - 'weight' => '3', - 'sort_key' => '~00000003', + 'weight' => '1', + 'sort_key' => '~00000002-00000001', 'child_count' => '0', 'permalink' => 'delete_page_2', 'slug' => 'delete_page_2', From 78011e6f59f182808bb44e29aff1bb9291f40e05 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 13 Mar 2020 23:47:31 +0900 Subject: [PATCH 07/28] =?UTF-8?q?change:=20test:=20travis.yml=E3=81=8B?= =?UTF-8?q?=E3=82=89php5.4,5.5=E3=82=92=E5=89=8A=E9=99=A4=E3=80=82php7.3,7?= =?UTF-8?q?.4=E3=82=92=E8=BF=BD=E5=8A=A0=20https://github.com/NetCommons3/?= =?UTF-8?q?NetCommons3/issues/1560?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e231d1c..10db2ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 sudo: false dist: trusty From 72d56077393dab6412c729ee8e25e9ff0a4391fc Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 14 Mar 2020 14:51:50 +0900 Subject: [PATCH 08/28] =?UTF-8?q?change:=20test:=20php7.4=E3=81=A7Notice?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20=E2=80=BBPHP7.4=E3=81=8B=E3=82=89=E3=82=B9?= =?UTF-8?q?=E3=82=AB=E3=83=A9=E3=83=BC=E5=9E=8B=E5=A4=89=E6=95=B0=E3=81=AB?= =?UTF-8?q?=E9=85=8D=E5=88=97=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=A8E=5FNOTICE=E3=81=8C=E5=87=BA=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AA=E3=81=A3=E3=81=9F=E3=80=82=20https:?= =?UTF-8?q?//github.com/NetCommons3/NetCommons3/issues/1560?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SaveRoomAssociationsBehavior/SaveDefaultPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Case/Model/Behavior/SaveRoomAssociationsBehavior/SaveDefaultPageTest.php b/Test/Case/Model/Behavior/SaveRoomAssociationsBehavior/SaveDefaultPageTest.php index e2ccdad..1deac3d 100644 --- a/Test/Case/Model/Behavior/SaveRoomAssociationsBehavior/SaveDefaultPageTest.php +++ b/Test/Case/Model/Behavior/SaveRoomAssociationsBehavior/SaveDefaultPageTest.php @@ -113,7 +113,7 @@ public function testPageOnExceptionError($data) { * @return void */ public function testRoomOnExceptionError($data) { - $this->_mockForReturnTrue('TestModel', 'Pages.Page', 'savePage'); + $this->_mockForReturn('TestModel', 'Pages.Page', 'savePage', ['Page' => ['id' => '5']]); $this->_mockForReturnFalse('TestModel', 'Rooms.Room', 'updateAll'); //テスト実施 From 032903e1f817aa3705b0c4560b7508dc3452c3e8 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 1 Aug 2020 06:14:46 +0900 Subject: [PATCH 09/28] =?UTF-8?q?change:=20test:=20Travis=E3=81=8B?= =?UTF-8?q?=E3=82=89PHP5.6=E3=82=92=E5=89=8A=E9=99=A4,php72=E4=BB=A5?= =?UTF-8?q?=E9=99=8D=E3=81=A7UnitTest=E3=81=A7Warning=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E3=82=8B=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3=20https://github.?= =?UTF-8?q?com/NetCommons3/NetCommons3/issues/1588?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 1 - phpunit.xml.dist | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 10db2ef..c7bc7d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.6 - 7.0 - 7.1 - 7.2 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 31a3436..7c9bdb6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,11 @@ + + + + + + app/Plugin/Rooms From 672ade2c5067948bae2fec5fe3b00cdc16a1b863 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 26 Aug 2020 20:21:46 +0900 Subject: [PATCH 10/28] change: Version number to 3.3.2 --- VERSION.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION.txt diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..4772543 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +3.3.2 From bbce10636b4de1ca6fc55a81e18e72ce2350524c Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sun, 13 Dec 2020 18:38:21 +0900 Subject: [PATCH 11/28] =?UTF-8?q?fix:=20test:=20TravisCI=E3=81=AEphp7.3?= =?UTF-8?q?=E3=81=A7=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C=E5=87=BA=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3=20https://github.com/NetCo?= =?UTF-8?q?mmons3/NetCommons3/issues/1618?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c7bc7d1..53262a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ php: - 7.0 - 7.1 - 7.2 - - 7.3 + - 7.3.24 - 7.4 sudo: false From 591af855371062560c778961710ec3674cd57a7a Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 23 Jan 2021 14:04:28 +0900 Subject: [PATCH 12/28] =?UTF-8?q?add:=20release=E3=82=BF=E3=82=B0=E4=BB=98?= =?UTF-8?q?=E3=81=91=E3=81=AEgithub=20action=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/NetCommons3/NetCommons3/issues/1619 --- .github/workflows/release.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a3225bc --- /dev/null +++ b/.github/workflows/release.yml @@ -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 From f39525c0db0ae35faf585c35f0111449e7299622 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 23 Jan 2021 14:04:39 +0900 Subject: [PATCH 13/28] change: Version number to 3.3.3 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 4772543..619b537 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.2 +3.3.3 From fee9d09f72e5c772e29efedc333bdf4ee6b9f8de Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 31 Jul 2021 15:24:29 +0900 Subject: [PATCH 14/28] =?UTF-8?q?change:=20test:=20TravisCI=E3=81=8B?= =?UTF-8?q?=E3=82=89GithubAction=E3=81=AB=E5=A4=89=E6=9B=B4=20https://gith?= =?UTF-8?q?ub.com/NetCommons3/NetCommons3/issues/1650?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 137 ++++++++++++++++++++++++++++++++++++ .travis.yml | 42 ----------- README.md | 11 +-- phpunit.xml.dist | 4 +- 4 files changed, 141 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d6bd01e --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,137 @@ +on: + push: + branches: + - main + - master + - availability + pull_request: + branches: + - main + - master + - availability + +name: tests + +jobs: + tests: + name: tests + runs-on: ubuntu-18.04 + strategy: + matrix: + php: [ '7.1', '7.2', '7.3', '7.4' ] + + env: + NC3_BUILD_DIR: "/opt/nc3" + NC3_DOCKER_DIR: "/opt/docker" + NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" + NC3_GIT_BRANCH: "master" + PLUGIN_BUILD_DIR: ${{ github.workspace }} + PHP_VERSION: ${{ matrix.php }} + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: cakephp_test + + steps: + - uses: actions/checkout@v2 + + - name: environment + run: | + echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" + echo "PLUGIN_BUILD_DIR=${PLUGIN_BUILD_DIR}" + echo "PHP_VERSION=${PHP_VERSION}" + ls -al ${PLUGIN_BUILD_DIR} + + - name: docker-compose install + run: | + curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + docker-compose --version + + - name: git clone nc3 + run: git clone -b ${NC3_GIT_BRANCH} ${NC3_GIT_URL} ${NC3_BUILD_DIR} + + - name: git clone nc3_docker + run: git clone https://github.com/NetCommons3/nc3app-docker.git ${NC3_DOCKER_DIR} + + - name: docker-compose start + run: | + cd ${NC3_DOCKER_DIR} + docker-compose up -d + docker-compose start + + - run: docker ps + + - name: check libraries + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/start-on-docker.sh + + - name: nc3 build + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/app-build.sh + + - name: phpcs (PHP CodeSniffer) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcs.sh + + - name: phpmd (PHP Mess Detector) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpmd.sh + + - name: phpcpd (PHP Copy/Paste Detector) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcpd.sh + + - name: gjslint (JavaScript Style Check) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/gjslint.sh + + - name: phpdoc (PHP Documentor) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpdoc.sh + + - name: phpunit (PHP UnitTest) + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpunit.sh + sudo -s chmod a+w -R ${NC3_BUILD_DIR}/build + + - name: push coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_FLAG_NAME: ${{ matrix.php }} + run: | + cd ${NC3_BUILD_DIR} + ls -la ${NC3_BUILD_DIR} + vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v + + - name: docker-compose remove + run: | + cd ${NC3_DOCKER_DIR} + docker-compose rm -f + + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Success + if: success() + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_CHANNEL: notify-netcommons3 + SLACK_TITLE: "${{ github.repository }}(${{ matrix.php }})" + SLACK_COLOR: good + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_CHANNEL: notify-netcommons3 + SLACK_TITLE: "${{ github.repository }}(${{ matrix.php }})" + SLACK_COLOR: danger diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 53262a9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3.24 - - 7.4 - -sudo: false -dist: trusty - -env: - matrix: - - NETCOMMONS_VERSION=master DB=mysql - global: - - secure: "UvZqrQzrJFGPz3z6Pbi8h5S8vEFcQT92eLLmOaapL9R+jkycRMKT2sUUKp/nM7C/TcNC/OeUULcrv/cnLH/0sb/ns6nJyoTGzOqlmViAAn92wxKVocy1kbCRYi0RWSrm8DiC492RqLk7oXhz4x8yTMHfowgw4S55M034VZVxtQg=" - - GIT_COMMITTER_NAME=s-nakajima - - GIT_COMMITTER_EMAIL=nakajimashouhei@gmail.com - - GIT_AUTHOR_NAME=s-nakajima - - GIT_AUTHOR_EMAIL=nakajimashouhei@gmail.com - -before_script: - - export NETCOMMONS_BUILD_DIR=`dirname $TRAVIS_BUILD_DIR`/NetCommons3 - - git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR - - cd $NETCOMMONS_BUILD_DIR - - git checkout $NETCOMMONS_VERSION - - travis_wait . tools/build/plugins/cakephp/travis/pre.sh - - . tools/build/plugins/cakephp/travis/environment.sh - -script: - - . tools/build/plugins/cakephp/travis/main.sh - -after_script: - - . tools/build/plugins/cakephp/travis/post.sh - -notifications: - email: - recipients: - - netcommons3@googlegroups.com - on_success: never # default: change - on_failure: always # default: always diff --git a/README.md b/README.md index 57e329c..dccdb4b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@ Rooms ===== -Rooms for NetComomns3 - -[![Build Status](https://api.travis-ci.org/NetCommons3/Rooms.png?branch=master)](https://travis-ci.org/NetCommons3/Rooms) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/Rooms/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/Rooms?branch=master) - -| dependencies | status | -| ------------ | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/53f823dde09da395fc0004e2/badge.png)](https://www.versioneye.com/user/projects/53f823dde09da395fc0004e2) | \ No newline at end of file +[![Tests Status](https://github.com/NetCommons3/Rooms/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Rooms/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Rooms/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Rooms?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/rooms.svg?label=stable)](https://packagist.org/packages/netcommons/rooms) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7c9bdb6..b6cfc6d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,9 +3,6 @@ - - - app/Plugin/Rooms @@ -20,5 +17,6 @@ + From 7f69cc9f8f371b8f263e2bcec19d3a3760a7c827 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 10 Aug 2021 17:34:17 +0900 Subject: [PATCH 15/28] =?UTF-8?q?fix:=20MySQL8=E3=81=A0=E3=81=A8SHOW=20TAB?= =?UTF-8?q?LES=E3=81=AE=E6=88=BB=E3=82=8A=E5=80=A4=E3=81=8CMySQL5=E3=81=A8?= =?UTF-8?q?=E7=95=B0=E3=81=AA=E3=82=8A=E3=80=81=E5=86=85=E9=83=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=80=82=20https://github.com/NetCommons3/NetCommons3/issues/1?= =?UTF-8?q?655?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/RoomsLibDataSourceExecute.php | 9 +++++++-- Model/Behavior/DeleteRoomAssociationsBehavior.php | 9 +++++++-- .../Case/Model/RolesRoomsUser/GetRolesRoomsUsersTest.php | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/RoomsLibDataSourceExecute.php b/Lib/RoomsLibDataSourceExecute.php index a3c2177..42e2f3a 100644 --- a/Lib/RoomsLibDataSourceExecute.php +++ b/Lib/RoomsLibDataSourceExecute.php @@ -74,7 +74,12 @@ public function showTables() { $retTables = []; foreach ($tables as $table) { - $realTableName = array_shift($table['TABLE_NAMES']); + $realTableName = null; + if (array_key_exists('TABLE_NAMES', $table)) { + $realTableName = array_shift($table['TABLE_NAMES']); + } elseif (array_key_exists('TABLES', $table)) { + $realTableName = array_shift($table['TABLES']); + } $realPrefix = substr($realTableName, 0, strlen($tablePrefix)); $tableName = substr($realTableName, strlen($tablePrefix)); @@ -149,7 +154,7 @@ private function __getSchemeFileTablesByPlugin($plugin) { * @return array */ public function showTableColumns($realTableName) { - $columns = $this->__Model->query('SHOW COLUMNS FROM ' . $realTableName); + $columns = $this->__Model->query('SHOW COLUMNS FROM `' . $realTableName . '`'); $retColumns = []; foreach ($columns as $column) { diff --git a/Model/Behavior/DeleteRoomAssociationsBehavior.php b/Model/Behavior/DeleteRoomAssociationsBehavior.php index 043fdb9..8018fd2 100644 --- a/Model/Behavior/DeleteRoomAssociationsBehavior.php +++ b/Model/Behavior/DeleteRoomAssociationsBehavior.php @@ -174,8 +174,13 @@ public function queryDeleteAll(Model $model, $field, $value) { $tables = $model->query("SHOW TABLES LIKE '{$prefix}%'"); foreach ($tables as $table) { - $tableName = array_shift($table['TABLE_NAMES']); - $columns = $model->query('SHOW COLUMNS FROM ' . $tableName); + $tableName = null; + if (array_key_exists('TABLE_NAMES', $table)) { + $tableName = array_shift($table['TABLE_NAMES']); + } elseif (array_key_exists('TABLES', $table)) { + $tableName = array_shift($table['TABLES']); + } + $columns = $model->query('SHOW COLUMNS FROM `' . $tableName . '`'); if (! Hash::check($columns, '{n}.COLUMNS[Field=' . $field . ']')) { continue; } diff --git a/Test/Case/Model/RolesRoomsUser/GetRolesRoomsUsersTest.php b/Test/Case/Model/RolesRoomsUser/GetRolesRoomsUsersTest.php index a8b60be..bc60f63 100644 --- a/Test/Case/Model/RolesRoomsUser/GetRolesRoomsUsersTest.php +++ b/Test/Case/Model/RolesRoomsUser/GetRolesRoomsUsersTest.php @@ -73,7 +73,7 @@ public function testGetRolesRoomsUsers() { ); //テスト実施 - $result = $this->$model->$methodName($conditions); + $result = $this->$model->$methodName($conditions, ['order' => ['Room.id' => 'asc']]); //チェック $this->assertCount(3, $result); From 020d6e30be2cfc901c1f159cbcc3a04001c7c889 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 11 Aug 2021 14:11:59 +0900 Subject: [PATCH 16/28] =?UTF-8?q?change:=20test:=20Slack=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3,=20mysql8.0=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=20https://github.com/NetCommons3/NetCommons3?= =?UTF-8?q?/issues/1650?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 35 ++++++++++++++++++++++++-- .github/workflows/tests.yml | 47 +++++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a3225bc..592d72f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,16 +4,25 @@ on: tags: - '3*' -name: Create Release +name: create_release jobs: build: - name: Create Release + name: create_release runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + SLACK_MESSAGE: "Start Job" + - name: Create Release id: create_release uses: actions/create-release@v1 @@ -26,3 +35,25 @@ jobs: NetCommons ${{ github.ref }} released. draft: false prerelease: false + + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Finish + uses: rtCamp/action-slack-notify@v2.2.0 + if: success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good + SLACK_MESSAGE: "Job Success" + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: danger + SLACK_MESSAGE: "Job Failure" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d6bd01e..1477ea2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,12 +13,26 @@ on: name: tests jobs: + setup: + name: setup + runs-on: ubuntu-18.04 + steps: + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + tests: name: tests + needs: setup runs-on: ubuntu-18.04 strategy: matrix: php: [ '7.1', '7.2', '7.3', '7.4' ] + mysql: [ '5.7', '8.0' ] env: NC3_BUILD_DIR: "/opt/nc3" @@ -27,6 +41,7 @@ jobs: NC3_GIT_BRANCH: "master" PLUGIN_BUILD_DIR: ${{ github.workspace }} PHP_VERSION: ${{ matrix.php }} + MYSQL_VERSION: ${{ matrix.mysql }} MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: cakephp_test @@ -38,6 +53,7 @@ jobs: echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" echo "PLUGIN_BUILD_DIR=${PLUGIN_BUILD_DIR}" echo "PHP_VERSION=${PHP_VERSION}" + echo "MYSQL_VERSION=${MYSQL_VERSION}" ls -al ${PLUGIN_BUILD_DIR} - name: docker-compose install @@ -116,22 +132,27 @@ jobs: cd ${NC3_DOCKER_DIR} docker-compose rm -f - # テスト成功時はこちらのステップが実行される - - name: Slack Notification on Success - if: success() - uses: rtCamp/action-slack-notify@v2.2.0 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: notify-netcommons3 - SLACK_TITLE: "${{ github.repository }}(${{ matrix.php }})" - SLACK_COLOR: good - # テスト失敗時はこちらのステップが実行される - name: Slack Notification on Failure uses: rtCamp/action-slack-notify@v2.2.0 if: failure() env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: notify-netcommons3 - SLACK_TITLE: "${{ github.repository }}(${{ matrix.php }})" + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}(php${{ matrix.php }}, mysql${{ matrix.mysql }})" SLACK_COLOR: danger + + teardown: + name: teardown + runs-on: ubuntu-18.04 + needs: tests + steps: + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Success + if: success() + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good From 122164586e22a111f09638ec0e78199355998540 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 13 Aug 2021 18:19:07 +0900 Subject: [PATCH 17/28] change: Version number to 3.3.4 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 619b537..a0891f5 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.3 +3.3.4 From 2276893be8cf32906ba8217b944e8cb5b4069d87 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 8 Oct 2021 10:16:31 +0900 Subject: [PATCH 18/28] =?UTF-8?q?change:=20=E3=82=BF=E3=82=A4=E3=83=9F?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=E3=81=AF?= =?UTF-8?q?Deadlock=E3=81=8C=E8=B5=B7=E3=81=93=E3=82=8B=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=80=A7=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=81=A7=E3=80=81?= =?UTF-8?q?=E3=83=88=E3=83=A9=E3=83=B3=E3=82=B6=E3=82=AF=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=81=AE=E3=82=BF=E3=82=A4=E3=83=9F=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Console/Command/Task/DeleteRelatedRoomsTask.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Console/Command/Task/DeleteRelatedRoomsTask.php b/Console/Command/Task/DeleteRelatedRoomsTask.php index a3348ba..eac0e0d 100644 --- a/Console/Command/Task/DeleteRelatedRoomsTask.php +++ b/Console/Command/Task/DeleteRelatedRoomsTask.php @@ -90,11 +90,11 @@ public function execute() { " LIMIT " . self::PROCESS_COUNT ); - //トランザクションBegin - $this->RoomDeleteRelatedTable->begin(); - try { foreach ($records as $record) { + //トランザクションBegin + $this->RoomDeleteRelatedTable->begin(); + $recordId = $record['RoomDeleteRelatedTable']['id']; $this->RoomDeleteRelatedTable->updateStartTime($recordId); @@ -108,11 +108,11 @@ public function execute() { $this->RoomDeleteRelatedTable->updateEndTime($recordId); $procCount++; - } - //トランザクションCommit - $this->RoomDeleteRelatedTable->commit(); - //$this->RoomDeleteRelatedTable->rollback(); + //トランザクションCommit + $this->RoomDeleteRelatedTable->commit(); + //$this->RoomDeleteRelatedTable->rollback(); + } } catch (Exception $ex) { //トランザクションRollback From 2f390ff3f881b44788f0128a831f8e95a62c13af Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 3 Jan 2022 14:41:23 +0900 Subject: [PATCH 19/28] =?UTF-8?q?change:=20=E4=BC=9A=E5=93=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=81=A7=E4=B8=80=E6=8B=AC=E5=89=8A=E9=99=A4=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0=20https://github.com/NetCo?= =?UTF-8?q?mmons3/NetCommons3/issues/1676?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Room.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Model/Room.php b/Model/Room.php index 8f87369..7f56ee2 100644 --- a/Model/Room.php +++ b/Model/Room.php @@ -471,9 +471,6 @@ public function afterDelete() { if (! $this->deleteAll(array($this->alias . '.id' => $this->_childRoomIds), false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - - //コマンドライン実行 - RoomsLibCommandExec::deleteRelatedRooms(); } /** @@ -628,10 +625,12 @@ public function saveMove($room, $moveMethod, $moveStep = 1) { * ルームの削除処理 * * @param array $data received post data + * @param bool $execDelCommand 削除コマンドを実行するかどうか * @return bool True on success, false on validation errors * @throws InternalErrorException + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function deleteRoom($data) { + public function deleteRoom($data, $execDelCommand = true) { $this->loadModels([ 'RoomsLanguage' => 'Rooms.RoomsLanguage', ]); @@ -645,6 +644,12 @@ public function deleteRoom($data) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + //コマンドライン実行 + if ($execDelCommand) { + //会員の一括削除の場合、毎回実行しないようにするため。 + RoomsLibCommandExec::deleteRelatedRooms(); + } + //トランザクションCommit $this->commit(); From 5ae7f30ae35f0d17e35cc9cb017cdcacad917110 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 3 Jan 2022 16:23:07 +0900 Subject: [PATCH 20/28] =?UTF-8?q?change:=20=E4=BC=9A=E5=93=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=81=A7=E4=B8=80=E6=8B=AC=E5=89=8A=E9=99=A4=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0=20https://github.com/NetCo?= =?UTF-8?q?mmons3/NetCommons3/issues/1676?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Room.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Room.php b/Model/Room.php index 7f56ee2..f856be4 100644 --- a/Model/Room.php +++ b/Model/Room.php @@ -644,15 +644,15 @@ public function deleteRoom($data, $execDelCommand = true) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + //トランザクションCommit + $this->commit(); + //コマンドライン実行 if ($execDelCommand) { //会員の一括削除の場合、毎回実行しないようにするため。 RoomsLibCommandExec::deleteRelatedRooms(); } - //トランザクションCommit - $this->commit(); - } catch (Exception $ex) { //トランザクションRollback $this->rollback($ex); From c64c3a3138713705d29c9986c8d40edf020fd057 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 11 Feb 2022 21:57:43 +0900 Subject: [PATCH 21/28] change: Version number to 3.3.5 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index a0891f5..fa7adc7 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.4 +3.3.5 From 032ea7fa12e7e45414c1303a6d523350d1ed7fb1 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 23 Apr 2022 13:00:14 +0900 Subject: [PATCH 22/28] =?UTF-8?q?test:=20github=20actions=E3=81=AE?= =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1477ea2..9501566 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -48,6 +48,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Fix up git URLs + run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig + - name: environment run: | echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" @@ -58,7 +61,7 @@ jobs: - name: docker-compose install run: | - curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose chmod +x ~/docker-compose sudo mv ~/docker-compose /usr/local/bin/docker-compose docker-compose --version From 26fe373a30b9e21fee14dd94eaea09af06d65f52 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Tue, 20 Dec 2022 16:03:49 +0900 Subject: [PATCH 23/28] =?UTF-8?q?fix:=20=E3=83=AB=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=81=AE=E5=8F=82=E5=8A=A0=E8=80=85=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E7=94=BB=E9=9D=A2=E3=81=A7=E3=80=8C=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=A0=E5=86=85=E3=81=AE=E5=BD=B9=E5=89=B2=E3=80=8D=E3=81=A7?= =?UTF-8?q?=E3=82=BD=E3=83=BC=E3=83=88=E3=81=99=E3=82=8B=E3=81=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3=EF=BC=88NC3=E3=81=AE?= =?UTF-8?q?=E3=81=BF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/Component/RoomsRolesFormComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Component/RoomsRolesFormComponent.php b/Controller/Component/RoomsRolesFormComponent.php index 9e52827..38b5a23 100644 --- a/Controller/Component/RoomsRolesFormComponent.php +++ b/Controller/Component/RoomsRolesFormComponent.php @@ -208,7 +208,7 @@ public function actionRoomsRolesUser(Controller $controller) { 'displayFields' => self::$displaFields, 'extra' => array( 'selectedUsers' => $controller->Session->read('RoomsRolesUsers'), - 'plugin' => $seached ? $controller->params['plugin'] : '', + 'plugin' => $controller->params['plugin'] ?? '', 'search' => $seached ) )); From af746dc2e3e51645bc4ef7357f687180fce4e30e Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 13 Feb 2023 22:20:43 +0900 Subject: [PATCH 24/28] =?UTF-8?q?fix:=20=E3=83=AB=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E6=88=90=E6=99=82=E3=81=AB=E3=80=81=E5=8F=82?= =?UTF-8?q?=E5=8A=A0=E8=80=85=E3=81=AE=E9=81=B8=E6=8A=9E=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=81=A7=E5=BD=B9=E5=89=B2=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=BE=8C=E3=81=A7=E5=9F=BA=E6=9C=AC=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=AB=E6=88=BB=E3=81=A3=E3=81=A6=E3=80=81=E3=80=8C=E3=81=99?= =?UTF-8?q?=E3=81=B9=E3=81=A6=E3=81=AE=E4=BC=9A=E5=93=A1=E3=82=92=E3=83=87?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=A7=E5=8F=82=E5=8A=A0?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=82=8B=E3=80=8D=E3=81=AB=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=92=E5=85=A5=E3=82=8C=E3=81=A6=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=99=E3=82=8B=E3=81=A8=E3=80=81=E5=BD=B9=E5=89=B2?= =?UTF-8?q?=E3=81=AE=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C=E4=BA=8C=E9=87=8D?= =?UTF-8?q?=E3=81=A7=E7=99=BB=E9=8C=B2=E3=81=95=E3=82=8C=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/RoomAddController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Controller/RoomAddController.php b/Controller/RoomAddController.php index 5237e93..750e1d6 100644 --- a/Controller/RoomAddController.php +++ b/Controller/RoomAddController.php @@ -165,6 +165,11 @@ public function basic() { //他言語が入力されていない場合、Currentの言語データをセット $this->SwitchLanguage->setM17nRequestValue(); + $defaultParticipation = $this->request->data['Room']['default_participation'] ?? null; + if ($this->Session->read('RoomAdd.Room.default_participation') !== $defaultParticipation) { + $this->Session->delete('RoomsRolesUsers'); + } + //登録処理 $this->request->data['Room']['in_draft'] = true; $room = $this->Room->saveRoom($this->request->data); From 2909b70fd8a6ee13f6d711f320ab9759b8d08de5 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 24 Feb 2023 16:59:18 +0900 Subject: [PATCH 25/28] =?UTF-8?q?test:=20Github=20Action=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9501566..7cfa881 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,6 +44,7 @@ jobs: MYSQL_VERSION: ${{ matrix.mysql }} MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: cakephp_test + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 From 8f612cb4f41735e8269f9823a09309e379be0f1b Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sun, 26 Feb 2023 05:19:08 +0900 Subject: [PATCH 26/28] change: Version number to 3.3.6 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index fa7adc7..9c25013 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.5 +3.3.6 From d20cb13e67e415ad6870477d41b8adee96c6613a Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 5 Oct 2023 22:44:38 +0900 Subject: [PATCH 27/28] =?UTF-8?q?test:=20github=20action=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7cfa881..6da4321 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,22 +3,21 @@ on: branches: - main - master - - availability pull_request: branches: - main - master - - availability name: tests jobs: setup: name: setup - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Slack Notification on Start uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' env: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} SLACK_CHANNEL: notify-nc3-tests @@ -28,7 +27,7 @@ jobs: tests: name: tests needs: setup - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: matrix: php: [ '7.1', '7.2', '7.3', '7.4' ] @@ -92,46 +91,53 @@ jobs: docker-compose exec -T nc3app bash /opt/scripts/app-build.sh - name: phpcs (PHP CodeSniffer) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpcs.sh - name: phpmd (PHP Mess Detector) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpmd.sh - name: phpcpd (PHP Copy/Paste Detector) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpcpd.sh - name: gjslint (JavaScript Style Check) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/gjslint.sh - name: phpdoc (PHP Documentor) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpdoc.sh - name: phpunit (PHP UnitTest) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpunit.sh sudo -s chmod a+w -R ${NC3_BUILD_DIR}/build - - name: push coveralls - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS_FLAG_NAME: ${{ matrix.php }} - run: | - cd ${NC3_BUILD_DIR} - ls -la ${NC3_BUILD_DIR} - vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v +# - name: push coveralls +# env: +# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# COVERALLS_FLAG_NAME: ${{ matrix.php }} +# run: | +# cd ${NC3_BUILD_DIR} +# ls -la ${NC3_BUILD_DIR} +# vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v - name: docker-compose remove + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose rm -f @@ -139,7 +145,7 @@ jobs: # テスト失敗時はこちらのステップが実行される - name: Slack Notification on Failure uses: rtCamp/action-slack-notify@v2.2.0 - if: failure() + if: env.SLACK_WEBHOOK != '' && failure() env: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} SLACK_CHANNEL: notify-nc3-tests @@ -148,13 +154,13 @@ jobs: teardown: name: teardown - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest needs: tests steps: # テスト成功時はこちらのステップが実行される - name: Slack Notification on Success - if: success() uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && success() env: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} SLACK_CHANNEL: notify-nc3-tests From b1c4948df31534719aaa30a22d94157d3d25b6e4 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 9 Oct 2023 22:36:30 +0900 Subject: [PATCH 28/28] change: Version number to 3.3.7 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 9c25013..86fb650 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.6 +3.3.7