diff --git a/CHANGELOG.md b/CHANGELOG.md index e2611bb..f1b9275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ IMPORTANT NOTE: This version only works on CACTI 1.x++! --- develop --- +* issue#277: Allow map duplication when the debug column is absent while preserving its default when present * issue#151: Keep standalone editor controls visible and use theme-aware dialog contrast * issue#275: Load permitted editor picker results in bounded pages, search interface descriptions, and encode graph search terms * issue#274: Fit hover popups to their graph content and close them immediately when leaving map links, preserving graph proportions and meaningful captions diff --git a/tests/Support/MapDuplicatePayload.php b/tests/Support/MapDuplicatePayload.php new file mode 100644 index 0000000..ad558dd --- /dev/null +++ b/tests/Support/MapDuplicatePayload.php @@ -0,0 +1,96 @@ + 2, 'active' => 1, 'configfile' => 'Original.conf', 'titlecache' => 'Original Map', + 'thumb_height' => 150, 'thumb_width' => 200, 'schedule' => '* * * * *', 'archiving' => 0]; +} + +/** + * Return the existing maximum map sort order. + * + * @param string $sql Query. + * + * @return int Maximum sort order. + */ +function db_fetch_cell($sql) { + return 9; +} + +/** + * Count a fixture array. + * + * @param array $value Array to count. + * + * @return int Array size. + */ +function cacti_sizeof($value) { + return count($value); +} + +/** + * Supply a destination filename without touching the filesystem. + * + * @param string $file Source filename. + * + * @return string Destination filename. + */ +function map_get_next_name($file) { + return 'Original_copy.conf'; +} + +/** + * Report the selected schema shape. + * + * @param string $table Table name. + * @param string $column Column name. + * + * @return bool Whether the debug column exists. + */ +function db_column_exists($table, $column) { + if ($table !== 'weathermap_maps' || $column !== 'debug') { + throw new RuntimeException('Unexpected column lookup.'); + } + + return $GLOBALS['argv'][1] === 'present'; +} + +/** + * Capture the actual save payload and stop before file copying/polling. + * + * @param array $payload Map fields to save. + * @param string $table Destination table. + * + * @return int Zero prevents further side effects in the fixture. + */ +function sql_save($payload, $table) { + $GLOBALS['duplicate_save'] = ['table' => $table, 'payload' => $payload]; + + return 0; +} + +map_duplicate(5, ' Copy'); +print json_encode($GLOBALS['duplicate_save'], JSON_THROW_ON_ERROR); diff --git a/tests/Unit/MapDuplicateSchemaTest.php b/tests/Unit/MapDuplicateSchemaTest.php new file mode 100644 index 0000000..50ca414 --- /dev/null +++ b/tests/Unit/MapDuplicateSchemaTest.php @@ -0,0 +1,31 @@ +toBe(0); + $saved = json_decode(implode("\n", $lines), true, 512, JSON_THROW_ON_ERROR); + expect($saved['table'])->toBe('weathermap_maps'); + $payload = $saved['payload']; + expect(array_key_exists('debug', $payload))->toBe($has_debug); + + if ($has_debug) { + expect($payload['debug'])->toBe('off'); + } + expect($payload['id'])->toBe(0) + ->and($payload['sortorder'])->toBe(10) + ->and($payload['titlecache'])->toBe('Original Map Copy') + ->and($payload['configfile'])->toBe('Original_copy.conf') + ->and($payload['group_id'])->toBe(2) + ->and($payload['active'])->toBe(1) + ->and($payload['imagefile'])->toBe('') + ->and($payload['htmlfile'])->toBe('') + ->and($payload['warncount'])->toBe(0); +})->with([false, true]); diff --git a/weathermap-cacti-plugin-mgmt.php b/weathermap-cacti-plugin-mgmt.php index 896bc90..87e7baf 100644 --- a/weathermap-cacti-plugin-mgmt.php +++ b/weathermap-cacti-plugin-mgmt.php @@ -1936,7 +1936,9 @@ function map_duplicate($id, $titlecache, $configfile = null) { $save['htmlfile'] = ''; $save['filehash'] = ''; $save['warncount'] = 0; - $save['debug'] = 'off'; + if (db_column_exists('weathermap_maps', 'debug')) { + $save['debug'] = 'off'; + } $save['config'] = ''; $save['thumb_height'] = $map['thumb_height']; $save['thumb_width'] = $map['thumb_width'];