Skip to content

Commit

Permalink
CS-5701 - Interference of changes provided from different editors at …
Browse files Browse the repository at this point in the history
…the same time
  • Loading branch information
takeit committed Mar 2, 2015
1 parent 3f56569 commit 46049bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public function getPlaylistsArticlesAction(Request $request, $id)
if ($user && $user->isAdmin()) {
$onlyPublished = false;
}
} catch (\Newscoop\NewscoopException $e) {}
} catch (\Newscoop\NewscoopException $e) {
}

$playlistArticles = $em->getRepository('Newscoop\Entity\Playlist')
->articles($playlist, null, true, null, null, $onlyPublished, true)->getResult();
Expand All @@ -155,7 +156,7 @@ public function getPlaylistsArticlesAction(Request $request, $id)
'title' => $playlist->getName(),
'notes' => $playlist->getNotes(),
'maxItems' => $playlist->getMaxItems(),
'articlesModificationTime' => $playlist->getArticlesModificationTime()
'articlesModificationTime' => $playlist->getArticlesModificationTime(),
), $articles);

return $allItems;
Expand Down Expand Up @@ -315,9 +316,9 @@ public function saveBatchActionsAction(Request $request, $id)
$actions = $request->request->get('actions', array());
$lastArtclesModificationTime = $request->request->get('articlesModificationTime');
if (!$lastArtclesModificationTime && $playlist->getArticlesModificationTime() != null) {
throw new InvalidParametersException('articlesModificationTime date is requred');
} else if ($lastArtclesModificationTime != $playlist->getArticlesModificationTime() && $playlist->getArticlesModificationTime() != null) {
throw new ResourcesConflictException("This playlist is already in different state than fetched by you.", 409);
throw new InvalidParametersException('articlesModificationTime parameter is required');
} elseif (new \DateTime($lastArtclesModificationTime) != $playlist->getArticlesModificationTime() && $playlist->getArticlesModificationTime() != null) {
throw new ResourcesConflictException("This list is already in a different state than the one in which it was loaded.", 409);
}

$playlist->setArticlesModificationTime(new \DateTime('now'));
Expand Down Expand Up @@ -477,7 +478,7 @@ public function updatePlaylistAction(Request $request, $id)
$oldMaxItems = $playlist->getMaxItems();

$form = $this->createForm(new PlaylistType(), $playlist, array(
'method' => $request->getMethod()
'method' => $request->getMethod(),
));
$form->handleRequest($request);
if ($form->isValid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ angular.module('playlistsApp').controller('PlaylistsController', [
return true;
}

Playlist.batchUpdate(logList)
Playlist.batchUpdate(logList, $scope.playlist.selected)
.then(function () {
flashMessage(Translator.trans('List saved'));
Playlist.clearLogList();
Expand Down Expand Up @@ -376,8 +376,16 @@ angular.module('playlistsApp').controller('PlaylistsController', [
flashMessage(Translator.trans('List saved'));
$scope.featuredArticles = Playlist.getArticlesByListId({id: Playlist.getListId()});
$scope.playlist.selected.id = Playlist.getListId();
}, function() {
flashMessage(Translator.trans('Could not save the list'), 'error');
}, function(response) {
if (response.errors[0].code === 409) {
flashMessage(Translator.trans(
'This list is already in a different state than the one in which it was loaded.'
), 'error');
// automatically refresh playlist
$scope.featuredArticles = Playlist.getArticlesByListId({id: Playlist.getListId()});
} else {
flashMessage(Translator.trans('Could not save the list'), 'error');
}
flash.fadeOut();
$scope.processing = false;
});
Expand Down Expand Up @@ -412,7 +420,7 @@ angular.module('playlistsApp').controller('PlaylistsController', [
list = deferred;
$scope.playlist.selected.title = listname;

if (!playlistExists && !update) {
if (!playlistExists && !update && $scope.playlist.selected.id === undefined) {
return Playlist.createPlaylist($scope.playlist.selected);
}

Expand All @@ -426,6 +434,6 @@ angular.module('playlistsApp').controller('PlaylistsController', [
return list;
}

return Playlist.batchUpdate(logList);
return Playlist.batchUpdate(logList, $scope.playlist.selected);
}
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,19 @@ angular.module('playlistsApp').factory('Playlist', [
* @return {Object} promise object that is resolved on successful server
* response and rejected on server error response
*/
Playlist.batchUpdate = function(logList) {
Playlist.batchUpdate = function(logList, playlist) {
var deferred = $q.defer(),
postParams,
now;
now,
playlistDateTime = undefined;

now = new Date();
postParams = parseAndBuildParams(logList);

if (playlist.articlesModificationTime !== undefined) {
playlistDateTime = new Date(playlist.articlesModificationTime);
}

$http({
url: Routing.generate(
'newscoop_gimme_articleslist_savebatchactions',
Expand All @@ -185,10 +190,16 @@ angular.module('playlistsApp').factory('Playlist', [
str.push("actions[]["+param.method+"]=" + encodeURIComponent(param.link));
});

// send also datetime to see if playlist is locked by diffrent user
if (playlistDateTime !== undefined) {
str.push("articlesModificationTime=" + playlistDateTime.toLocaleString());
} else {
str.push("articlesModificationTime=" + now.toLocaleString());
}

return str.join("&");
},
data: postParams,
params: {articlesModificationTime: now.toLocaleString()}
data: postParams
})
.success(function () {
deferred.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Comments: Comments
'Snippet': 'Snippet'
'Are you sure you want to change the limit ? If you change the limit, all articles below the limit will be removed from the list.': 'Are you sure you want to change the limit ? If you change the limit, all articles below the limit will be removed from the list.'
'List limit reached! Remove some articles from the list before adding new ones.': 'List limit reached! Remove some articles from the list before adding new ones.'
'This list is already in a different state than the one in which it was loaded.': 'This list is already in a different state than the one in which it was loaded.'
articles:
images:
edit:
Expand Down

0 comments on commit 46049bc

Please sign in to comment.