Skip to content

Commit

Permalink
Dev: Check for null arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 17, 2016
1 parent dc90b9f commit 47f36e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 12 additions & 4 deletions application/core/plugins/CintLink/CintLink.php
Expand Up @@ -425,12 +425,20 @@ public function beforeSurveyDeactivate()
'sid' => $surveyId,
'deleted' => 0
));
$orders = CintLinkOrder::updateOrders($orders);

if (CintLinkOrder::anyOrderHasStatus($orders, array('new', 'live')))
if (empty($orders))
{
$event->set('message', $this->gT('You cannot deactivate the survey while any Cint order is live.'));
$event->set('success', false);
// Do nothing
}
else
{
$orders = CintLinkOrder::updateOrders($orders);

if (CintLinkOrder::anyOrderHasStatus($orders, array('new', 'live')))
{
$event->set('message', $this->gT('You cannot deactivate the survey while any Cint order is live.'));
$event->set('success', false);
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion application/core/plugins/CintLink/model/CintLinkOrder.php
Expand Up @@ -424,7 +424,7 @@ public function updateFromCint()
/**
* Update a bunch of orders
* @param CintLinkOrder[]|int $orders Or survey id
* @return CintLinkOrder[]
* @return CintLinkOrder[]|null
*/
public static function updateOrders($orders)
{
Expand All @@ -434,6 +434,11 @@ public static function updateOrders($orders)
$orders = self::getOrders($orders);
}

if (empty($orders))
{
return null;
}

$newOrders = array();
$limesurveyOrgKey = Yii::app()->user->getState('limesurveyOrgKey');

Expand Down Expand Up @@ -520,6 +525,11 @@ public static function hasAnyOrders($surveyId)
*/
public static function anyOrderHasStatus($orders, $statuses)
{
if (empty($orders))
{
return false;
}

if (!is_array($orders))
{
$orders = array($orders);
Expand Down

0 comments on commit 47f36e4

Please sign in to comment.