Skip to content

Commit 8c3c8c7

Browse files
committed
Tolerate team ids sent as scalar
1 parent 07ccf57 commit 8c3c8c7

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Module.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,10 +1980,8 @@ public function itemCreate(Event $event)
19801980
$operation = $request->getOperation();
19811981
$em = $this->getServiceLocator()->get('Omeka\EntityManager');
19821982

1983-
19841983
if ($operation == 'create') {
19851984
$response = $event->getParam('response');
1986-
19871985
$resource = $response->getContent();
19881986
$team_key = '';
19891987
if (array_key_exists('team', $request->getContent())){
@@ -1994,24 +1992,24 @@ public function itemCreate(Event $event)
19941992

19951993
if ($team_key) {
19961994
$teams = $request->getContent()[$team_key];
1997-
1995+
if (!is_array($teams)){
1996+
$teams = [$teams];
1997+
}
19981998
//add items to team
1999-
foreach ($teams as $team_id):
1999+
foreach ($teams as $team_id){
20002000
$team = $em->getRepository('Teams\Entity\Team')->findOneBy(['id'=>$team_id]);
2001-
$tr = new TeamResource($team, $resource);
2002-
$em->persist($tr);
2003-
2004-
//if there is media, add those to the team as well
2005-
2006-
$media = $resource->getMedia();
2007-
2008-
if (count($media) > 0) {
2009-
foreach ($media as $m):
2010-
$tr = new TeamResource($team, $m);
2001+
$tr = new TeamResource($team, $resource);
20112002
$em->persist($tr);
2012-
endforeach;
2003+
2004+
//if there is media, add those to the team as well
2005+
$media = $resource->getMedia();
2006+
if (count($media) > 0) {
2007+
foreach ($media as $m):
2008+
$tr = new TeamResource($team, $m);
2009+
$em->persist($tr);
2010+
endforeach;
2011+
}
20132012
}
2014-
endforeach;
20152013
$em->flush();
20162014
}
20172015
}

0 commit comments

Comments
 (0)