Changeset 3314285
- Timestamp:
- 06/19/2025 05:15:48 AM (9 months ago)
- Location:
- post-migration/trunk
- Files:
-
- 1 added
- 9 edited
-
assets/js/post-mi-script.js (modified) (1 diff)
-
composer.lock (modified) (2 diffs)
-
post-migration.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
vendor/composer/installed.json (modified) (3 diffs)
-
vendor/composer/installed.php (modified) (3 diffs)
-
vendor/itmar/wpsetting-class-package/README.md (modified) (3 diffs)
-
vendor/itmar/wpsetting-class-package/src/ItmarDbAction.php (modified) (5 diffs)
-
vendor/itmar/wpsetting-class-package/src/ItmarDbCache.php (added)
-
vendor/itmar/wpsetting-class-package/src/ItmarRedirectControl.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
post-migration/trunk/assets/js/post-mi-script.js
r3295494 r3314285 373 373 // Object.entries() を使って key-value をループ 374 374 for (const [key, value] of Object.entries(postData.acf_fields)) { 375 if (regex.test(value)) { 376 // 正規表現でマッチするかチェック 377 const file = await extractMediaFile(value); 378 // すでに同じファイル名が存在するかをチェック 379 const isDuplicate = mediaData.some( 380 (existingFile) => existingFile.name === file.name 381 ); 382 if (!isDuplicate) { 383 mediaData.push(file); 375 if (Array.isArray(value)) { 376 for (const media_path of value) { 377 if (regex.test(media_path)) { 378 // 正規表現でマッチするかチェック 379 const file = await extractMediaFile(media_path); 380 // すでに同じファイル名が存在するかをチェック 381 const isDuplicate = mediaData.some( 382 (existingFile) => existingFile.name === file.name 383 ); 384 if (!isDuplicate) { 385 mediaData.push(file); 386 } 387 } 388 } 389 } else { 390 if (regex.test(value)) { 391 // 正規表現でマッチするかチェック 392 const file = await extractMediaFile(value); 393 // すでに同じファイル名が存在するかをチェック 394 const isDuplicate = mediaData.some( 395 (existingFile) => existingFile.name === file.name 396 ); 397 if (!isDuplicate) { 398 mediaData.push(file); 399 } 384 400 } 385 401 } -
post-migration/trunk/composer.lock
r3306091 r3314285 86 86 { 87 87 "name": "itmar/wpsetting-class-package", 88 "version": "v1. 2.5",88 "version": "v1.3.1", 89 89 "source": { 90 90 "type": "git", 91 91 "url": "https://github.com/itmaroon/wpsetting-class-package.git", 92 "reference": " be1ab7d46a9ce60465d975a3a26236c635c58169"92 "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26" 93 93 }, 94 94 "dist": { 95 95 "type": "zip", 96 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/ be1ab7d46a9ce60465d975a3a26236c635c58169",97 "reference": " be1ab7d46a9ce60465d975a3a26236c635c58169",96 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/15b4b285066bd652de9c2f89edb71f9e15667c26", 97 "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26", 98 98 "shasum": "" 99 99 }, … … 120 120 "support": { 121 121 "issues": "https://github.com/itmaroon/wpsetting-class-package/issues", 122 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1. 2.5"122 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.3.1" 123 123 }, 124 "time": "2025-0 5-23T02:21:11+00:00"124 "time": "2025-06-19T05:02:18+00:00" 125 125 } 126 126 ], -
post-migration/trunk/post-migration.php
r3306091 r3314285 5 5 Requires at least: 6.4 6 6 Requires PHP: 8.2 7 Version: 1. 0.17 Version: 1.1.0 8 8 Author: Web Creator ITmaroon 9 9 Author URI: https://itmaroon.net … … 571 571 $media_urls[] = $media_url; 572 572 } 573 } elseif ($field_object['type'] === 'gallery') { 574 $gallery = get_field($key, $post->ID); 575 foreach ($gallery as $value) { 576 $media_url = is_numeric($value) ? wp_get_attachment_url($value) : (is_array($value) && isset($value['url']) ? $value['url'] : $value); 577 if ($media_url) { 578 $relative_path = 'exported_media/' . basename($media_url); 579 $post_data['acf_fields'][$key][] = $relative_path; 580 $media_urls[] = $media_url; 581 } 582 } 573 583 } elseif ($field_object['type'] === 'group') { 574 584 $post_data['acf_fields'][$key] = '_group'; -
post-migration/trunk/readme.txt
r3306091 r3314285 4 4 Requires at least: 6.4 5 5 Tested up to: 6.8 6 Stable tag: 1. 0.16 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 54 54 == Changelog == 55 55 56 = 1.1.0 = 57 Added functionality to ensure proper export and import when gallery is used as an ACF custom field type. 58 56 59 = 1.0.1 = 57 60 Update due to the version upgrade of the composer package of wpsetting-class-package 58 61 59 62 = 1.0.0 = 60 63 * Release -
post-migration/trunk/vendor/composer/installed.json
r3306091 r3314285 86 86 { 87 87 "name": "itmar/wpsetting-class-package", 88 "version": "v1. 2.5",89 "version_normalized": "1. 2.5.0",88 "version": "v1.3.1", 89 "version_normalized": "1.3.1.0", 90 90 "source": { 91 91 "type": "git", 92 92 "url": "https://github.com/itmaroon/wpsetting-class-package.git", 93 "reference": " be1ab7d46a9ce60465d975a3a26236c635c58169"93 "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26" 94 94 }, 95 95 "dist": { 96 96 "type": "zip", 97 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/ be1ab7d46a9ce60465d975a3a26236c635c58169",98 "reference": " be1ab7d46a9ce60465d975a3a26236c635c58169",97 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/15b4b285066bd652de9c2f89edb71f9e15667c26", 98 "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26", 99 99 "shasum": "" 100 100 }, … … 102 102 "itmar/loader-package": "^1.0" 103 103 }, 104 "time": "2025-0 5-23T02:21:11+00:00",104 "time": "2025-06-19T05:02:18+00:00", 105 105 "type": "library", 106 106 "installation-source": "dist", … … 123 123 "support": { 124 124 "issues": "https://github.com/itmaroon/wpsetting-class-package/issues", 125 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1. 2.5"125 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.3.1" 126 126 }, 127 127 "install-path": "../itmar/wpsetting-class-package" -
post-migration/trunk/vendor/composer/installed.php
r3306091 r3314285 4 4 'pretty_version' => 'dev-master', 5 5 'version' => 'dev-master', 6 'reference' => ' fed24b753d0df1eb8f6ced0a027ee03a23b60489',6 'reference' => '4da18f909e01e3e6514a50f3255c612ded28f9ce', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-master', 15 15 'version' => 'dev-master', 16 'reference' => ' fed24b753d0df1eb8f6ced0a027ee03a23b60489',16 'reference' => '4da18f909e01e3e6514a50f3255c612ded28f9ce', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../', … … 39 39 ), 40 40 'itmar/wpsetting-class-package' => array( 41 'pretty_version' => 'v1. 2.5',42 'version' => '1. 2.5.0',43 'reference' => ' be1ab7d46a9ce60465d975a3a26236c635c58169',41 'pretty_version' => 'v1.3.1', 42 'version' => '1.3.1.0', 43 'reference' => '15b4b285066bd652de9c2f89edb71f9e15667c26', 44 44 'type' => 'library', 45 45 'install_path' => __DIR__ . '/../itmar/wpsetting-class-package', -
post-migration/trunk/vendor/itmar/wpsetting-class-package/README.md
r3295494 r3314285 21 21 22 22 ## 変更履歴 23 24 = 1.3.1 = 25 ItmarDbActionクラスのset_mediaメソッドの$file_path引数に配列がセットされたときの処理を新たに加えた 26 27 = 1.3.0 = 28 ItmarDbCacheクラスを新たに加えた 23 29 24 30 = 1.2.0 = … … 142 148 set_media($media_array, $post_id, $file_path, $media_type) 143 149 $media_arrayで渡されたアップロードファイルの配列から、ファイル名が$file_pathと一致するものを選び出し、メディアライブラリに登録するとともに、$post_idのIDをもつ投稿に関連付ける。関連付けの方法は次の3とおり。 150 $file_pathが配列で複数のメディアのパスを渡した場合にも対応する。 144 151 - アイキャッチ画像 145 152 $media_typeがthumbnail … … 264 271 ``` 265 272 266 267 268 269 270 271 272 273 273 ### 名前空間・クラス 274 \Itmar\WpSettingClassPackage\ItmarDbCache 275 276 #### クラスの概要 277 `ItmarDbCache` は `$wpdb` を用いた WordPress の DB 操作にキャッシュ機構を付加するためのユーティリティクラスです。Plugin Check で警告されがちな直接DB呼び出しに対し、キャッシュ処理 (`wp_cache_get` / `wp_cache_set` / `wp_cache_delete`) を適切に加えることで、パフォーマンスとコード品質を両立させます。 278 279 --- 280 281 #### メソッドの説明 282 283 --- 284 285 ### `get_var_cached($sql, $cache_key, $expire = 3600)` 286 SQL文字列を実行し、結果をキャッシュ付きで1行1列取得する。 287 288 ##### 引数 289 - `string $sql` : 実行するSQL(`$wpdb->prepare()`済み推奨) 290 - `string $cache_key` : キャッシュキー 291 - `int $expire` : キャッシュの有効期間(秒) 292 293 ##### 戻り値 294 - `mixed` : 結果行の1カラム目の値 295 296 ##### 使用例 297 ```php 298 $sql = $wpdb->prepare("SHOW TABLES LIKE %s", $table_name); 299 $result = ItmarDbCache::get_var_cached($sql, 'table_exists_' . md5($table_name)); 300 ``` 301 302 --- 303 304 ### `get_row_cached($sql, $cache_key, $expire = 3600, $output = ARRAY_A)` 305 SQL文字列を実行し、1行のデータをキャッシュ付きで取得する。 306 307 ##### 引数 308 - `string $sql` : 実行するSQL 309 - `string $cache_key` : キャッシュキー 310 - `int $expire` : キャッシュの有効期間(秒) 311 - `string $output` : 返却形式。`OBJECT`, `ARRAY_A`, `ARRAY_N` のいずれか(デフォルト:`ARRAY_A`) 312 313 ##### 戻り値 314 - `mixed` : 1行の結果データ 315 316 ##### 使用例 317 ```php 318 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE token = %s", $token); 319 $row = ItmarDbCache::get_row_cached($sql, 'row_token_' . md5($token)); 320 ``` 321 322 --- 323 324 ### `update_and_clear_cache($table, $data, $where, ?array $data_format = null, ?array $where_format = null, array $cache_keys = [])` 325 レコードを更新し、指定したキャッシュキーのキャッシュを削除する。 326 327 ##### 引数 328 - `string $table` : 対象テーブル名 329 - `array $data` : 更新データ 330 - `array $where` : WHERE 条件 331 - `?array $data_format` : 更新データのフォーマット(`%s`など) 332 - `?array $where_format` : WHERE 条件のフォーマット 333 - `array $cache_keys` : 削除対象のキャッシュキー配列 334 335 ##### 戻り値 336 - `int|false` : 成功時は更新された行数、失敗時は false 337 338 ##### 使用例 339 ```php 340 $result = ItmarDbCache::update_and_clear_cache( 341 $wpdb->users, 342 ['user_pass' => $hashed_password], 343 ['ID' => $user_id], 344 ['%s'], 345 ['%d'], 346 ['user_cache_' . $user_id] 347 ); 348 ``` 349 350 --- 351 352 ### `delete_and_clear_cache($table, $where, ?array $where_format = null, array $cache_keys = [])` 353 レコードを削除し、指定したキャッシュキーのキャッシュを削除する。 354 355 ##### 引数 356 - `string $table` : 対象テーブル名 357 - `array $where` : WHERE 条件 358 - `?array $where_format` : WHERE 条件のフォーマット 359 - `array $cache_keys` : 削除対象のキャッシュキー配列 360 361 ##### 戻り値 362 - `int|false` : 削除された行数、または失敗時は false 363 364 ##### 使用例 365 ```php 366 $result = ItmarDbCache::delete_and_clear_cache( 367 $table, 368 ['id' => $row['id']], 369 ['%d'], 370 ['row_token_' . md5($row['token'])] 371 ); 372 ``` 373 374 --- 375 376 ### `set_cache_group($group)` 377 キャッシュのグループ名を変更する。 378 379 ##### 引数 380 - `string $group` : グループ名(デフォルトは `itmar_cache`) 381 382 ##### 戻り値 383 - なし 384 385 ##### 使用例 386 ```php 387 ItmarDbCache::set_cache_group('my_plugin_group'); 388 ``` 389 390 391 392 393 394 395 396 397 398 -
post-migration/trunk/vendor/itmar/wpsetting-class-package/src/ItmarDbAction.php
r3306091 r3314285 177 177 'value' => $value 178 178 ]; 179 } else if (is_array($value)) { 180 $image_arr = []; 181 foreach ($value as $elm) { 182 if (is_string($elm) && preg_match('/exported_media\/(.+?\.[a-zA-Z0-9]+)/u', $elm, $matches)) { //メディアフィールド 183 $image_arr[] = $elm; 184 } 185 } 186 $acf_mediaURLs[] = [ 187 'key' => $key, 188 'value' => $image_arr 189 ]; 179 190 } 180 191 } … … 233 244 if ($content_path) { 234 245 $media_result = $this->set_media($uploaded_medias, $new_post_id, $content_path, "content"); 235 $updated_content = str_replace($content_path, $media_result['attachment_url'] , $updated_content);246 $updated_content = str_replace($content_path, $media_result['attachment_url'][0], $updated_content); 236 247 $error_logs[] = $media_result['message']; 237 248 } … … 276 287 add_filter('wp_image_editors', [$this, 'force_gd_editor']); 277 288 289 //$file_pathが配列の時に備えてすべて配列で対応 290 $file_names = []; 278 291 //acf_fieldのときはオブジェクトが来るのでそれに対応 279 292 if ($media_type === 'acf_field') { 280 $file_name = basename($file_path['value']);281 293 $acf_field = $file_path['key']; 294 $acf_paths = $file_path['value']; 295 if (is_array($acf_paths)) { //$file_pathが配列の時(gallery対応) 296 foreach ($acf_paths as $acf_path) { 297 $file_names[] = basename($acf_path); 298 } 299 } else { 300 $file_names[] = basename($acf_paths); 301 } 282 302 } else { 283 $file_name = basename($file_path); 284 } 285 286 // `name` キーに `$file_name` が一致する要素を検索 287 $matched_files = array_filter($media_array, function ($file) use ($file_name) { 288 return $file['name'] === $file_name; 289 }); 290 // 1つだけ取得 291 $file = reset($matched_files) ?: null; 292 //取得できなければ終了 293 if (is_null($file)) { 294 return array( 295 "status" => 'error', 296 "message" => esc_html__("File not found (file name:", "wpsetting-class-package") . $file_name . ")", 297 ); 298 } 299 300 $upload_dir = wp_upload_dir(); 301 $dest_path = $upload_dir['path'] . '/' . basename($file['name']); 302 303 304 if (file_exists($dest_path)) { 305 //既に同じ名前のファイルが存在したらアップロードしない 306 $attachment_id = $this->get_attachment_id_by_file_path($dest_path); 307 if ($attachment_id) { 308 $result = 'success'; 309 $message = esc_html__("Processing stopped due to existing file found (media ID:", "wpsetting-class-package") . $attachment_id . ")"; 310 } 311 } else { 312 // wp_handle_upload の前準備 313 require_once(ABSPATH . 'wp-admin/includes/file.php'); 314 require_once(ABSPATH . 'wp-admin/includes/image.php'); 315 316 $upload_overrides = array('test_form' => false); 317 $movefile = wp_handle_upload($file, $upload_overrides); 318 319 if ($movefile && !isset($movefile['error'])) { 320 $dest_path = $movefile['file']; 321 $file_name = isset($file['name']) ? $file['name'] : basename($dest_path); 322 $filetype = wp_check_filetype(basename($dest_path), null); 323 324 $attachment = array( 325 'post_mime_type' => $filetype['type'], 326 'post_title' => sanitize_file_name($file_name), 327 'post_content' => '', 328 'post_status' => 'inherit' 303 $file_names[] = basename($file_path); 304 } 305 306 //$attachment_idをストックする配列 307 $attachment_ids = []; 308 foreach ($file_names as $file_name) { 309 // `name` キーに `$file_name` が一致する要素を検索 310 $matched_files = array_filter($media_array, function ($file) use ($file_name) { 311 return $file['name'] === $file_name; 312 }); 313 // 1つだけ取得 314 $file = reset($matched_files) ?: null; 315 //取得できなければ終了 316 if (is_null($file)) { 317 return array( 318 "status" => 'error', 319 "message" => esc_html__("File not found (file name:", "wpsetting-class-package") . $file_name . ")", 329 320 ); 330 331 $attachment_id = wp_insert_attachment($attachment, $dest_path); 332 $attach_data = wp_generate_attachment_metadata($attachment_id, $dest_path); 333 wp_update_attachment_metadata($attachment_id, $attach_data); 334 335 // 成功時のレスポンス 336 $result = 'success'; 337 $message = esc_html__("File uploaded", "wpsetting-class-package"); 338 } else { 339 $result = 'error'; 340 $message = esc_html__("Failed to upload file", "wpsetting-class-package"); 321 } 322 323 $upload_dir = wp_upload_dir(); 324 $dest_path = $upload_dir['path'] . '/' . basename($file['name']); 325 326 if (file_exists($dest_path)) { 327 //既に同じ名前のファイルが存在したらアップロードしない 328 $attachment_id = $this->get_attachment_id_by_file_path($dest_path); 329 if ($attachment_id) { 330 $result = 'success'; 331 $message = esc_html__("Processing stopped due to existing file found (media ID:", "wpsetting-class-package") . $attachment_id . ")"; 332 } 333 $attachment_ids[] = $attachment_id; 334 } else { 335 // wp_handle_upload の前準備 336 require_once(ABSPATH . 'wp-admin/includes/file.php'); 337 require_once(ABSPATH . 'wp-admin/includes/image.php'); 338 339 $upload_overrides = array('test_form' => false); 340 $movefile = wp_handle_upload($file, $upload_overrides); 341 342 if ($movefile && !isset($movefile['error'])) { 343 $dest_path = $movefile['file']; 344 $file_name = isset($file['name']) ? $file['name'] : basename($dest_path); 345 $filetype = wp_check_filetype(basename($dest_path), null); 346 347 $attachment = array( 348 'post_mime_type' => $filetype['type'], 349 'post_title' => sanitize_file_name($file_name), 350 'post_content' => '', 351 'post_status' => 'inherit' 352 ); 353 354 $attachment_id = wp_insert_attachment($attachment, $dest_path); 355 $attach_data = wp_generate_attachment_metadata($attachment_id, $dest_path); 356 wp_update_attachment_metadata($attachment_id, $attach_data); 357 $attachment_ids[] = $attachment_id; 358 // 成功時のレスポンス 359 $result = 'success'; 360 $message = esc_html__("File uploaded", "wpsetting-class-package"); 361 } else { 362 $result = 'error'; 363 $message = esc_html__("Failed to upload file", "wpsetting-class-package"); 364 } 341 365 } 342 366 } 343 367 344 368 // 投稿データにメディア情報を反映 345 $attachment_url = wp_get_attachment_url($attachment_id); 346 if ($attachment_id ) {369 370 if ($attachment_ids) { 347 371 if ($media_type === 'thumbnail') { 348 set_post_thumbnail($post_id, $attachment_id );372 set_post_thumbnail($post_id, $attachment_ids[0]); 349 373 $message = esc_html__('Upload thumbnail: ', "wpsetting-class-package") . $message; 350 374 } elseif ($media_type === 'content') { … … 352 376 } elseif ($media_type === 'acf_field') { 353 377 if (!empty($acf_field)) { 354 update_field($acf_field, $attachment_id, $post_id); 378 if (count($attachment_ids) > 1) { 379 update_field($acf_field, $attachment_ids, $post_id); 380 } else { 381 update_field($acf_field, $attachment_ids[0], $post_id); 382 } 383 355 384 $message = esc_html__('Uploading acf media: ', "wpsetting-class-package") . $message; 356 385 } … … 360 389 // フィルターを元に戻す 361 390 remove_filter('wp_image_editors', [$this, 'force_gd_editor']); 391 //呼び出しもとに返すためにURLを取得 392 $attachment_urls = []; 393 foreach ($attachment_ids as $attachment_id) { 394 $attachment_urls[] = wp_get_attachment_url($attachment_id); 395 } 362 396 363 397 return array( 364 398 "status" => $result, 365 399 "message" => $message, 366 "attachment_id" => $attachment_id ,367 "attachment_url" => $attachment_url ,400 "attachment_id" => $attachment_ids, 401 "attachment_url" => $attachment_urls, 368 402 ); 369 403 } -
post-migration/trunk/vendor/itmar/wpsetting-class-package/src/ItmarRedirectControl.php
r3306091 r3314285 79 79 // すでに index.php が存在する場合はエラー 80 80 if (file_exists($this->index_php_path)) { 81 $needle = "require __DIR__ . '/{$subdir}/wp-blog-header.php';";81 //$needle = "require __DIR__ . '/{$subdir}/wp-blog-header.php';"; 82 82 $contents = file_get_contents($this->index_php_path); 83 83 84 if (strpos($contents, $needle) !== false) { 84 $pattern = '/require\s+__DIR__\s*\.\s*[\'"]\/\s*' . preg_quote($subdir, '/') . '\s*\/wp-blog-header\.php[\'"];/'; 85 if (preg_match($pattern, $contents)) { 86 85 87 // ファイルが存在し、require 文も含まれている 86 88 return true;
Note: See TracChangeset
for help on using the changeset viewer.