1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-06-27 19:34:17 +02:00

Give up on MySQL timestamps & just use unix timestamps (int)

Also change the way update "success" is evaluated for setting details/words.
This commit is contained in:
Robbie Antenesse 2018-01-12 14:57:05 -07:00
parent 23263051f5
commit 39fe0cbe0a
2 changed files with 22 additions and 20 deletions

View file

@ -118,7 +118,7 @@ SET name=:name,
sort_by_definition=:sort_by_definition, sort_by_definition=:sort_by_definition,
is_complete=:is_complete, is_complete=:is_complete,
is_public=:is_public, is_public=:is_public,
last_updated=NOW() last_updated=:last_updated
WHERE user=$user AND id=$dictionary"; WHERE user=$user AND id=$dictionary";
$result1 = $this->db->query($query1, array( $result1 = $this->db->query($query1, array(
@ -130,6 +130,7 @@ WHERE user=$user AND id=$dictionary";
':sort_by_definition' => $dictionary_object['settings']['sortByDefinition'], ':sort_by_definition' => $dictionary_object['settings']['sortByDefinition'],
':is_complete' => $dictionary_object['settings']['isComplete'], ':is_complete' => $dictionary_object['settings']['isComplete'],
':is_public' => $dictionary_object['settings']['isPublic'], ':is_public' => $dictionary_object['settings']['isPublic'],
':last_updated' => $dictionary_object['lastUpdated'],
)); ));
if ($result1->rowCount() > 0) { if ($result1->rowCount() > 0) {
$linguistics = $dictionary_object['details']; $linguistics = $dictionary_object['details'];
@ -140,14 +141,14 @@ SET parts_of_speech=:parts_of_speech,
grammar_notes=:grammar_notes grammar_notes=:grammar_notes
WHERE dictionary=$dictionary"; WHERE dictionary=$dictionary";
$result2 = $this->db->query($query2, array( $result2 = $this->db->execute($query2, array(
':parts_of_speech' => json_encode($dictionary_object['partsOfSpeech']), ':parts_of_speech' => json_encode($dictionary_object['partsOfSpeech']),
':phonology' => json_encode($linguistics['phonology']), ':phonology' => json_encode($linguistics['phonology']),
':orthography_notes' => $linguistics['orthography']['notes'], ':orthography_notes' => $linguistics['orthography']['notes'],
':grammar_notes' => $linguistics['grammar']['notes'], ':grammar_notes' => $linguistics['grammar']['notes'],
)); ));
if ($result2->rowCount() > 0) { if ($result2) {
return true; return true;
} }
} }
@ -160,14 +161,14 @@ WHERE dictionary=$dictionary";
if ($results) { if ($results) {
return array_map(function ($row) { return array_map(function ($row) {
return array( return array(
'id' => $result['word_id'], 'id' => intval($row['word_id']),
'name' => $result['name'], 'name' => $row['name'],
'pronunciation' => $result['pronunciation'], 'pronunciation' => $row['pronunciation'],
'partOfSpeech' => $result['part_of_speech'], 'partOfSpeech' => $row['part_of_speech'],
'definition' => $result['definition'], 'definition' => $row['definition'],
'details' => $result['details'], 'details' => $row['details'],
'lastUpdated' => is_null($result['last_updated']) ? null : strtotime($result['last_updated']), 'lastUpdated' => is_null($row['last_updated']) ? null : strtotime($row['last_updated']),
'createdOn' => strtotime($result['created_on']), 'createdOn' => strtotime($row['created_on']),
); );
}, $results); }, $results);
} }
@ -175,10 +176,11 @@ WHERE dictionary=$dictionary";
} }
public function setWords ($dictionary, $words = array()) { public function setWords ($dictionary, $words = array()) {
$query = 'INSERT INTO words (word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES '; $query = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES ';
$params = array(); $params = array();
foreach($words as $word) { foreach($words as $word) {
$query .= "(?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?)), "; $query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?), ";
$params[] = $dictionary;
$params[] = $word['id']; $params[] = $word['id'];
$params[] = $word['name']; $params[] = $word['name'];
$params[] = $word['pronunciation']; $params[] = $word['pronunciation'];
@ -196,7 +198,7 @@ definition=VALUES(definition),
details=VALUES(details), details=VALUES(details),
last_updated=VALUES(last_updated)'; last_updated=VALUES(last_updated)';
$results = $this->db->query($query, $params); $results = $this->db->execute($query, $params);
return $results->rowCount(); return $results;
} }
} }

View file

@ -18,8 +18,8 @@ CREATE TABLE IF NOT EXISTS `dictionaries` (
`sort_by_definition` tinyint(1) NOT NULL DEFAULT '0', `sort_by_definition` tinyint(1) NOT NULL DEFAULT '0',
`is_complete` tinyint(1) NOT NULL DEFAULT '0', `is_complete` tinyint(1) NOT NULL DEFAULT '0',
`is_public` tinyint(1) NOT NULL DEFAULT '0', `is_public` tinyint(1) NOT NULL DEFAULT '0',
`last_updated` timestamp NULL DEFAULT NULL, `last_updated` int(11) DEFAULT NULL,
`created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_on` int(11) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=352 ; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=352 ;
DROP TRIGGER IF EXISTS `delete_dictionary_parts`; DROP TRIGGER IF EXISTS `delete_dictionary_parts`;
@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS `users` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`), UNIQUE KEY `email` (`email`),
UNIQUE KEY `username` (`username`) UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=151 ; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=152 ;
DROP TRIGGER IF EXISTS `Delete_User_Dictionaries`; DROP TRIGGER IF EXISTS `Delete_User_Dictionaries`;
DELIMITER // DELIMITER //
CREATE TRIGGER `Delete_User_Dictionaries` AFTER DELETE ON `users` CREATE TRIGGER `Delete_User_Dictionaries` AFTER DELETE ON `users`
@ -81,8 +81,8 @@ CREATE TABLE IF NOT EXISTS `words` (
`part_of_speech` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `part_of_speech` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`definition` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `definition` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`details` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown', `details` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown',
`last_updated` timestamp NULL DEFAULT NULL, `last_updated` int(11) DEFAULT NULL,
`created_on` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `created_on` int(11) NOT NULL,
UNIQUE KEY `unique_index` (`dictionary`,`word_id`) UNIQUE KEY `unique_index` (`dictionary`,`word_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;