diff --git a/src/constants.js b/src/constants.js index 50de91b..0526d44 100644 --- a/src/constants.js +++ b/src/constants.js @@ -49,7 +49,7 @@ export const DEFAULT_DICTIONARY = { isComplete: false, isPublic: false, }, - lastUpdated: null, + lastUpdated: getTimestampInSeconds(), createdOn: getTimestampInSeconds(), version: MIGRATE_VERSION, }; diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index c3cb002..0f73d63 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -91,7 +91,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; 'name' => $result['name'], 'specification' => $result['specification'], 'description' => $result['description'], - 'partsOfSpeech' => $partsOfSpeech, + 'partsOfSpeech' => explode(',', $partsOfSpeech), 'details' => array( 'phonology' => array( 'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(), @@ -118,7 +118,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; 'isComplete' => $result['is_complete'] === '1' ? true : false, 'isPublic' => $result['is_public'] === '1' ? true : false, ), - 'lastUpdated' => is_null($result['last_updated']) ? null : $result['last_updated'], + 'lastUpdated' => is_null($result['last_updated']) ? $results['created_on'] : $result['last_updated'], 'createdOn' => $result['created_on'], ); } diff --git a/src/php/api/User.php b/src/php/api/User.php index bc1b5b1..617c7dc 100644 --- a/src/php/api/User.php +++ b/src/php/api/User.php @@ -194,7 +194,13 @@ VALUES (?, ?, ?, ?, ?)'; if ($user_data !== false) { $user = $user_data->id; $dictionary = $user_data->dictionary; - return $this->dictionary->setDetails($user, $dictionary, $dictionary_details); + $details_updated = $this->dictionary->setDetails($user, $dictionary, $dictionary_details); + if ($details_updated === true) { + return true; + } + return array( + 'error' => $details_updated, + ); } return false; } diff --git a/src/php/api/index.php b/src/php/api/index.php index aff5717..e0ed336 100644 --- a/src/php/api/index.php +++ b/src/php/api/index.php @@ -222,13 +222,19 @@ switch ($action) { if ($token !== false && isset($request['details'])) { $user = new User(); $update_details_success = $user->updateCurrentDictionaryDetails($token, $request['details']); - if ($update_details_success !== false) { + if ($update_details_success === true) { return Response::json(array( // 'data' => 'Updated successfully', 'data' => $update_details_success, 'error' => false, ), 200); } + if (isset($update_details_success['error'])) { + return Response::json(array( + 'data' => $update_details_success['error'], + 'error' => true, + ), 500); + } return Response::json(array( 'data' => 'Could not set dictionary: invalid token', 'error' => true,