If logged in on load, sync dictionaries
This commit is contained in:
parent
a25e4726e5
commit
0dc64b5f10
|
@ -27,7 +27,7 @@ class Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create ($user) {
|
public function create ($user) {
|
||||||
$insert_dictionary_query = "INSERT INTO dictionaries (user) VALUES ($user)";
|
$insert_dictionary_query = "INSERT INTO dictionaries (user, created_on) VALUES ($user, " . time() . ")";
|
||||||
$insert_dictionary = $this->db->execute($insert_dictionary_query);
|
$insert_dictionary = $this->db->execute($insert_dictionary_query);
|
||||||
|
|
||||||
if ($insert_dictionary === true) {
|
if ($insert_dictionary === true) {
|
||||||
|
@ -101,8 +101,8 @@ VALUES ($new_dictionary_id, ?, ?)";
|
||||||
'isComplete' => $result['is_complete'] === '1' ? true : false,
|
'isComplete' => $result['is_complete'] === '1' ? true : false,
|
||||||
'isPublic' => $result['is_public'] === '1' ? true : false,
|
'isPublic' => $result['is_public'] === '1' ? true : false,
|
||||||
),
|
),
|
||||||
'lastUpdated' => is_null($result['last_updated']) ? null : strtotime($result['last_updated']),
|
'lastUpdated' => is_null($result['last_updated']) ? null : $result['last_updated'],
|
||||||
'createdOn' => strtotime($result['created_on']),
|
'createdOn' => $result['created_on'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -118,10 +118,12 @@ 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=:last_updated
|
last_updated=:last_updated,
|
||||||
|
created_on=:created_on
|
||||||
WHERE user=$user AND id=$dictionary";
|
WHERE user=$user AND id=$dictionary";
|
||||||
|
|
||||||
$result1 = $this->db->query($query1, array(
|
// $result1 = $this->db->query($query1, array(
|
||||||
|
$result1 = $this->db->execute($query1, array(
|
||||||
':name' => $dictionary_object['name'],
|
':name' => $dictionary_object['name'],
|
||||||
':specification' => $dictionary_object['specification'],
|
':specification' => $dictionary_object['specification'],
|
||||||
':description' => $dictionary_object['description'],
|
':description' => $dictionary_object['description'],
|
||||||
|
@ -131,8 +133,10 @@ WHERE user=$user AND id=$dictionary";
|
||||||
':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'],
|
':last_updated' => $dictionary_object['lastUpdated'],
|
||||||
|
':created_on' => $dictionary_object['createdOn'],
|
||||||
));
|
));
|
||||||
if ($result1->rowCount() > 0) {
|
// if ($result1->rowCount() > 0) {
|
||||||
|
if ($result1 === true) {
|
||||||
$linguistics = $dictionary_object['details'];
|
$linguistics = $dictionary_object['details'];
|
||||||
$query2 = "UPDATE dictionary_linguistics
|
$query2 = "UPDATE dictionary_linguistics
|
||||||
SET parts_of_speech=:parts_of_speech,
|
SET parts_of_speech=:parts_of_speech,
|
||||||
|
@ -141,6 +145,7 @@ 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(
|
$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']),
|
||||||
|
@ -148,10 +153,13 @@ WHERE dictionary=$dictionary";
|
||||||
':grammar_notes' => $linguistics['grammar']['notes'],
|
':grammar_notes' => $linguistics['grammar']['notes'],
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($result2) {
|
// if ($result2->rowCount() > 0) {
|
||||||
|
if ($result2 === true) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// return $result2->errorInfo();
|
||||||
}
|
}
|
||||||
|
// return $result1->errorInfo();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +175,8 @@ WHERE dictionary=$dictionary";
|
||||||
'partOfSpeech' => $row['part_of_speech'],
|
'partOfSpeech' => $row['part_of_speech'],
|
||||||
'definition' => $row['definition'],
|
'definition' => $row['definition'],
|
||||||
'details' => $row['details'],
|
'details' => $row['details'],
|
||||||
'lastUpdated' => is_null($row['last_updated']) ? null : strtotime($row['last_updated']),
|
'lastUpdated' => is_null($row['last_updated']) ? null : $row['last_updated'],
|
||||||
'createdOn' => strtotime($row['created_on']),
|
'createdOn' => $row['created_on'],
|
||||||
);
|
);
|
||||||
}, $results);
|
}, $results);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,8 @@ switch ($action) {
|
||||||
$update_details_success = $user->updateCurrentDictionaryDetails($token, $request['details']);
|
$update_details_success = $user->updateCurrentDictionaryDetails($token, $request['details']);
|
||||||
if ($update_details_success !== false) {
|
if ($update_details_success !== false) {
|
||||||
return Response::json(array(
|
return Response::json(array(
|
||||||
'data' => 'Updated successfully',
|
// 'data' => 'Updated successfully',
|
||||||
|
'data' => $update_details_success,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
), 200);
|
), 200);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import './sass/main.scss';
|
||||||
|
|
||||||
import Inferno from 'inferno';
|
import Inferno from 'inferno';
|
||||||
import Component from 'inferno-component';
|
import Component from 'inferno-component';
|
||||||
|
import store from 'store';
|
||||||
|
|
||||||
import removeDiacritics from '../vendor/StackOverflow/removeDiacritics';
|
import removeDiacritics from '../vendor/StackOverflow/removeDiacritics';
|
||||||
import { addHelpfulPrototypes, getWordsStats } from './Helpers';
|
import { addHelpfulPrototypes, getWordsStats } from './Helpers';
|
||||||
|
@ -47,7 +48,9 @@ class App extends Component {
|
||||||
|
|
||||||
this.updater = new Updater(this, dictionary);
|
this.updater = new Updater(this, dictionary);
|
||||||
|
|
||||||
this.updateDisplayedWords();
|
this.updateDisplayedWords(() => {
|
||||||
|
if (store.get('LexicongaToken')) this.updater.sync();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get dictionaryInfo () {
|
get dictionaryInfo () {
|
||||||
|
|
|
@ -89,7 +89,7 @@ export class Updater {
|
||||||
return request('set-dictionary-details', {
|
return request('set-dictionary-details', {
|
||||||
token: store.get('LexicongaToken'),
|
token: store.get('LexicongaToken'),
|
||||||
details: dictionaryDetails,
|
details: dictionaryDetails,
|
||||||
}, response => console.log(response))
|
}, response => console.log(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
sendWords (words) {
|
sendWords (words) {
|
||||||
|
@ -114,15 +114,16 @@ export class Updater {
|
||||||
}
|
}
|
||||||
|
|
||||||
compareDetails (externalDetails) {
|
compareDetails (externalDetails) {
|
||||||
if (externalDetails.lastUpdated) {
|
console.log('external details', externalDetails);
|
||||||
if (externalDetails.lastUpdated > store.get('Lexiconga').lastUpdated) {
|
if (!externalDetails.lastUpdated
|
||||||
this.app.setState(externalDetails, () => {
|
|| externalDetails.lastUpdated < this.dictionary.storedData.lastUpdated) {
|
||||||
this.dictionary.storedData = externalDetails;
|
this.sendDictionaryDetails(this.dictionary.storedData);
|
||||||
console.log('updated local');
|
} else if (externalDetails.lastUpdated
|
||||||
});
|
&& externalDetails.lastUpdated > this.dictionary.storedData.lastUpdated) {
|
||||||
} else if (externalDetails.lastUpdated < store.get('Lexiconga').lastUpdated) {
|
this.app.setState(externalDetails, () => {
|
||||||
this.sendDictionaryDetails(this.app.state);
|
this.dictionary.storedData = externalDetails;
|
||||||
}
|
console.log('updated local');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue