Skip to content

Commit 4b565f5

Browse files
committed
Unzipped demo db.
1 parent 4854b99 commit 4b565f5

6 files changed

Lines changed: 522 additions & 46 deletions

File tree

‎docs/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ from 1.8.0 to 1.10.2. This brings some bug fixes.
5757
* Moved Google API files:
5858
* Moved ``googleTimeToken.php`` from root folder to ``inc/``.
5959
* Moved ``googleTranslateClass.php`` from root folder to ``inc/classes/GoogleTranslate.php``.
60+
* ``install_demo_db_sql.gz`` uncompressed to ``install_demo_db.sql``. Functions adapted.
6061

6162
### Fixed
6263

‎docs/info.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,8 @@ <h4>Changed</h4>
19341934
<li>Moved <code>googleTranslateClass.php</code> from root folder to <code>inc/classes/GoogleTranslate.php</code>.</li>
19351935
</ul>
19361936
</li>
1937+
<li>
1938+
<code>install_demo_db_sql.gz</code> uncompressed to <code>install_demo_db.sql</code>. Functions adapted.</li>
19371939
</ul>
19381940
<h4>Fixed</h4>
19391941
<ul>

‎inc/session_utility.php‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,7 @@ function insertExpressions($textlc, $lid, $wid, $len, $mode): string|null
42024202
*
42034203
* @since 2.0.3-fork Function was broken
42044204
* @since 2.5.3-fork Function repaired
4205+
* @since 2.7.0-fork $handle should be for an *uncompressed* file.
42054206
*/
42064207
function restore_file($handle, $title): string
42074208
{
@@ -4216,15 +4217,9 @@ function restore_file($handle, $title): string
42164217
$inserts = 0;
42174218
$creates = 0;
42184219
$start = 1;
4219-
while (!gzeof($handle)) {
4220+
while (!feof($handle)) {
42204221
$sql_line = trim(
4221-
str_replace(
4222-
"\r", "",
4223-
str_replace(
4224-
"\n", "",
4225-
gzgets($handle, 99999)
4226-
)
4227-
)
4222+
str_replace("\r", "", str_replace("\n", "", fgets($handle, 99999)))
42284223
);
42294224
if ($sql_line != "") {
42304225
if ($start) {
@@ -4241,8 +4236,7 @@ function restore_file($handle, $title): string
42414236
}
42424237
if (substr($sql_line, 0, 3) !== '-- ' ) {
42434238
$res = mysqli_query(
4244-
$GLOBALS['DBCONNECTION'],
4245-
insert_prefix_in_sql($sql_line)
4239+
$GLOBALS['DBCONNECTION'], insert_prefix_in_sql($sql_line)
42464240
);
42474241
$lines++;
42484242
if ($res == false) {
@@ -4260,7 +4254,7 @@ function restore_file($handle, $title): string
42604254
}
42614255
}
42624256
} // while (! feof($handle))
4263-
gzclose($handle);
4257+
fclose($handle);
42644258
if ($errors == 0) {
42654259
runsql("DROP TABLE IF EXISTS {$tbpref}textitems", '');
42664260
check_update_db($debug, $tbpref, $dbname);

‎install_demo.php‎

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,76 @@
1111

1212
// RESTORE DEMO
1313

14-
if (isset($_REQUEST['install'])) {
15-
$file = getcwd() . '/install_demo_db.sql.gz';
14+
/**
15+
* Restore demo database from file.
16+
*
17+
* @return string Status message
18+
*/
19+
function restore_demo_db()
20+
{
21+
$file = getcwd() . '/install_demo_db.sql';
1622
if (file_exists($file) ) {
17-
$handle = gzopen($file, "r");
23+
$handle = fopen($file, "r");
1824
if ($handle === false) {
19-
$message = "Error: File ' . $file . ' could not be opened";
20-
} // $handle not OK
21-
else { // $handle OK
22-
$message = restore_file($handle, "Demo Database");
25+
return "Error: File ' . $file . ' could not be opened";
26+
// $handle not OK
27+
} else {
28+
// $handle OK
29+
return restore_file($handle, "Demo Database");
2330
} // $handle OK
24-
} // restore file specified
25-
else {
26-
$message = "Error: File ' . $file . ' does not exist";
31+
} else {
32+
// restore file specified
33+
return "Error: File ' . $file . ' does not exist";
2734
}
35+
}
36+
37+
if (isset($_REQUEST['install'])) {
38+
$message = restore_demo_db();
2839
}
2940

3041
pagestart('Install LWT Demo Database', true);
3142

3243
echo error_message_with_hide($message, 1);
3344

34-
$langcnt = get_first_value('select count(*) as value from ' . $tbpref . 'languages');
45+
$langcnt = get_first_value("SELECT COUNT(*) AS value FROM {$tbpref}languages");
3546

3647
if ($tbpref == '') {
3748
$prefinfo = "(Default Table Set)";
38-
}
39-
else {
49+
} else {
4050
$prefinfo = "(Table Set: <i>" . tohtml(substr($tbpref, 0, -1)) . "</i>)";
4151
}
4252

4353
?>
4454
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return confirm('Are you sure?');">
4555
<table class="tab3" cellspacing="0" cellpadding="5">
46-
<tr>
47-
<th class="th1 center">Install Demo</th>
48-
<td class="td1">
49-
<p class="smallgray2">
50-
The database <i><?php echo tohtml($dbname); ?></i> <?php echo $prefinfo; ?> will be <b>replaced</b> by the LWT demo database.
51-
52-
<?php
53-
if ($langcnt > 0 ) {
54-
?>
55-
<br />The existent database will be <b>overwritten!</b>
56-
<?php
57-
}
58-
?>
56+
<tr>
57+
<th class="th1 center">Install Demo</th>
58+
<td class="td1">
59+
<p class="smallgray2">
60+
The database <i><?php echo tohtml($dbname); ?></i>
61+
<?php echo $prefinfo; ?> will be <b>replaced</b> by the LWT
62+
demo database.
63+
<?php
64+
if ($langcnt > 0) {
65+
?>
66+
<br />The existent database will be <b>overwritten!</b>
67+
<?php
68+
}
69+
?>
5970

60-
</p>
61-
<p class="right">&nbsp;<br /><span class="red2">YOU MAY LOSE DATA - BE CAREFUL: &nbsp; &nbsp; &nbsp;</span>
62-
<input type="submit" name="install" value="Install LWT demo database" /></p>
63-
</td>
64-
</tr>
65-
<tr>
66-
<td class="td1 right" colspan="2">
67-
<input type="button" value="&lt;&lt; Back to LWT Main Menu" onclick="location.href='index.php';" /></td>
68-
</tr>
71+
</p>
72+
<p class="right">
73+
&nbsp;<br /><span class="red2">
74+
YOU MAY LOSE DATA - BE CAREFUL: &nbsp; &nbsp; &nbsp;
75+
</span>
76+
<input type="submit" name="install" value="Install LWT demo database" /></p>
77+
</td>
78+
</tr>
79+
<tr>
80+
<td class="td1 right" colspan="2">
81+
<input type="button" value="&lt;&lt; Back to LWT Main Menu" onclick="location.href='index.php';" />
82+
</td>
83+
</tr>
6984
</table>
7085
</form>
7186

0 commit comments

Comments
 (0)