Skip to content

Commit 4d5b097

Browse files
committed
Make ImageSource class & DB match
86ab215 set the types for the ImageSource class but some of the strings can be null. Reconcile the two. While we're here make the url and credit fields the max 255 varchar size (like the URLs are in other tables).
1 parent d70659c commit 4d5b097

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

SETUP/db_schema.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ CREATE TABLE `image_sources` (
9999
`full_name` varchar(100) NOT NULL default '',
100100
`info_page_visibility` tinyint(3) unsigned NOT NULL default '0',
101101
`is_active` tinyint(3) NOT NULL default '-1',
102-
`url` varchar(200) default NULL,
103-
`credit` varchar(200) default NULL,
102+
`url` varchar(255) NOT NULL default '',
103+
`credit` varchar(255) NOT NULL default '',
104104
`ok_keep_images` tinyint(4) NOT NULL default '-1',
105105
`ok_show_images` tinyint(4) NOT NULL default '-1',
106-
`public_comment` varchar(255) default NULL,
106+
`public_comment` varchar(255) NOT NULL default '',
107107
`internal_comment` text,
108-
UNIQUE KEY `code_name` (`code_name`),
108+
PRIMARY KEY (`code_name`),
109109
UNIQUE KEY `display_name` (`display_name`)
110110
);
111111

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
$relPath = '../../../pinc/';
3+
include_once($relPath.'base.inc');
4+
5+
header('Content-type: text/plain');
6+
7+
// ------------------------------------------------------------
8+
9+
echo "Updating image_sources...\n";
10+
$update_statements = [
11+
"UPDATE image_sources SET url = '' where url is NULL",
12+
"UPDATE image_sources SET credit = '' where credit is NULL",
13+
"UPDATE image_sources SET public_comment = '' where public_comment is NULL",
14+
];
15+
16+
foreach ($update_statements as $sql) {
17+
echo "\n $sql\n";
18+
mysqli_query(DPDatabase::get_connection(), $sql) or die(mysqli_error(DPDatabase::get_connection()));
19+
}
20+
21+
$sql = "
22+
ALTER TABLE image_sources
23+
MODIFY COLUMN `url` varchar(255) NOT NULL default '',
24+
MODIFY COLUMN `credit` varchar(255) NOT NULL default '',
25+
MODIFY COLUMN `public_comment` varchar(255) NOT NULL default '',
26+
DROP INDEX `code_name`,
27+
ADD PRIMARY KEY (code_name);
28+
";
29+
30+
mysqli_query(DPDatabase::get_connection(), $sql) or die(mysqli_error(DPDatabase::get_connection()));
31+
32+
// ------------------------------------------------------------
33+
34+
echo "\nDone!\n";

tools/project_manager/manage_image_sources.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ImageSource
152152
public int $ok_keep_images; // TODO: bool
153153
public int $ok_show_images; // TODO: bool
154154
public string $public_comment;
155-
public string $internal_comment;
155+
public ?string $internal_comment;
156156
public int $is_active;
157157

158158
public function __construct($code_name = null)
@@ -286,8 +286,8 @@ public function show_edit_form()
286286
}
287287
$this->_show_edit_row('display_name', _('Display Name'), false, 30, true);
288288
$this->_show_edit_row('full_name', _('Full Name'), false, 100, true);
289-
$this->_show_edit_row('url', _('Website'), false, 200);
290-
$this->_show_edit_row('credit', _('Credits Line (no URLs)'), true, 200);
289+
$this->_show_edit_row('url', _('Website'), false, 255);
290+
$this->_show_edit_row('credit', _('Credits Line (no URLs)'), true, 255);
291291
$this->_show_edit_permissions_row();
292292
$this->_show_edit_row('public_comment', _('Description (public comments)'), true, 255);
293293
$this->_show_edit_row('internal_comment', _('Notes (internal comments)'), true);
@@ -419,8 +419,8 @@ public function save_from_post()
419419
code_name = LEFT('%s', 10),
420420
display_name = LEFT('%s', 30),
421421
full_name = LEFT('%s', 100),
422-
url = LEFT('%s', 200),
423-
credit = LEFT('%s', 200),
422+
url = LEFT('%s', 255),
423+
credit = LEFT('%s', 255),
424424
ok_keep_images = %d,
425425
ok_show_images = %d,
426426
info_page_visibility = %d,

0 commit comments

Comments
 (0)