mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
Fix unit tests
This commit is contained in:
@@ -1463,10 +1463,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
|
||||
if (!$session->hasModuleId($app_id)) {
|
||||
$module = new \Entities\SessionModule();
|
||||
|
||||
$module->setModuleId($app_id);
|
||||
$module->setSession($session);
|
||||
$session->addSessionModule($module);
|
||||
|
||||
$app['EM']->persist($module);
|
||||
$app['EM']->persist($session);
|
||||
|
||||
$app['EM']->flush();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -110,6 +110,12 @@ class User_Query implements User_QueryInterface
|
||||
*/
|
||||
protected $only_templates = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $email_not_null = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
@@ -222,6 +228,10 @@ class User_Query implements User_QueryInterface
|
||||
$sql .= ' AND usr.invite=0 ';
|
||||
}
|
||||
|
||||
if ( ! $this->email_not_null) {
|
||||
$sql .= ' AND usr.usr_mail IS NOT NULL ';
|
||||
}
|
||||
|
||||
if ($this->only_templates === true) {
|
||||
$sql .= ' AND model_of = ' . $this->app['phraseanet.user']->get_id();
|
||||
} elseif ($this->include_templates === false) {
|
||||
@@ -439,6 +449,18 @@ class User_Query implements User_QueryInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return User_Query
|
||||
*/
|
||||
public function email_not_null($boolean)
|
||||
{
|
||||
$this->email_not_null = ! ! $boolean;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $rights
|
||||
|
@@ -197,17 +197,20 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
|
||||
$body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->get_email());
|
||||
$body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->get_company());
|
||||
|
||||
$receiver = Receiver::fromUser($to);
|
||||
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body);
|
||||
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$receiver = Receiver::fromUser($to);
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body);
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -82,19 +82,24 @@ class eventsmanager_notify_bridgeuploadfail extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['usr_id'])) {
|
||||
$user = User_Adapter::getInstance($params['usr_id'], $this->app);
|
||||
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$user = User_Adapter::getInstance($params['usr_id'], $this->app);
|
||||
$account = Bridge_Account::load_account($this->app, $params['account_id']);
|
||||
$readyToSend = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$receiver = Receiver::fromUser($user);
|
||||
/** ADD MAIL TEST */
|
||||
$mail = MailInfoBridgeUploadFailed::create($this->app, $receiver);
|
||||
$mail->setAdapter($account->get_api()->get_connector()->get_name());
|
||||
$mail->setReason($params['reason']);
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,10 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
|
||||
$Query = new \User_Query($this->app);
|
||||
|
||||
$Query->include_phantoms(true)->include_invite(false)->include_templates(false);
|
||||
$Query->include_phantoms(true)
|
||||
->include_invite(false)
|
||||
->include_templates(false)
|
||||
->email_not_null(true);
|
||||
|
||||
if ($entry->get_feed()->get_collection()) {
|
||||
$Query->on_base_ids(array($entry->get_feed()->get_collection()->get_base_id()));
|
||||
@@ -83,32 +86,38 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
|
||||
do {
|
||||
$results = $Query->limit($start, $perLoop)->execute()->get_results();
|
||||
|
||||
|
||||
foreach ($results as $user_to_notif) {
|
||||
/* @var $user_to_notif \User_Adapter */
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($user_to_notif->get_id())) {
|
||||
|
||||
$token = \random::getUrlToken(
|
||||
$this->app,
|
||||
\random::TYPE_FEED_ENTRY
|
||||
, $user_to_notif->get_id()
|
||||
, null
|
||||
, $entry->get_id()
|
||||
);
|
||||
|
||||
$url = $this->app['phraseanet.registry']->get('GV_ServerName') . 'lightbox/index.php?LOG=' . $token;
|
||||
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$token = \random::getUrlToken(
|
||||
$this->app,
|
||||
\random::TYPE_FEED_ENTRY
|
||||
, $user_to_notif->get_id()
|
||||
, null
|
||||
, $entry->get_id()
|
||||
);
|
||||
|
||||
$url = $this->app['phraseanet.registry']->get('GV_ServerName') . 'lightbox/index.php?LOG=' . $token;
|
||||
|
||||
$receiver = Receiver::fromUser($user_to_notif);
|
||||
$readyToSend = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoNewPublication::create($this->app, $receiver);
|
||||
$mail->setButtonUrl($url);
|
||||
$mail->setAuthor($entry->get_author_name());
|
||||
$mail->setTitle($entry->get_title());
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -111,15 +111,20 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($user->get_id())) {
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$receiver = Receiver::fromUser($user);
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoNewOrder::create($this->app, $receiver);
|
||||
$mail->setUser($orderInitiator);
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -96,30 +96,29 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['to'])) {
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$user_from = User_Adapter::getInstance($params['from'], $this->app);
|
||||
$user_to = User_Adapter::getInstance($params['to'], $this->app);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$repository = $this->app['EM']->getRepository('\Entities\Basket');
|
||||
|
||||
$basket = $repository->find($params['ssel_id']);
|
||||
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Emitter::fromUser($user_from);
|
||||
|
||||
$repository = $this->app['EM']->getRepository('\Entities\Basket');
|
||||
$basket = $repository->find($params['ssel_id']);
|
||||
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoOrderDelivered::create($this->app, $receiver, $emitter);
|
||||
$mail->setBasket($basket);
|
||||
$mail->setDeliverer($user_from);
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -76,17 +76,22 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['to'])) {
|
||||
|
||||
$readyToSend = false;
|
||||
|
||||
try {
|
||||
$user_from = User_Adapter::getInstance($params['from'], $this->app);
|
||||
$user_to = User_Adapter::getInstance($params['to'], $this->app);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Emitter::fromUser($user_from);
|
||||
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
|
||||
$mail->setQuantity($params['n']);
|
||||
$mail->setDeliverer($user_from);
|
||||
@@ -94,8 +99,6 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -83,6 +83,8 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['to'])) {
|
||||
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$repository = $this->app['EM']->getRepository('\Entities\Basket');
|
||||
$basket = $repository->find($params['ssel_id']);
|
||||
@@ -92,7 +94,12 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
|
||||
|
||||
$receiver = Receiver::fromUser($user_from);
|
||||
$emitter = Emitter::fromUser($user_to);
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message']);
|
||||
$mail->setBasket($basket);
|
||||
$mail->setPusher($user_from);
|
||||
@@ -100,8 +107,6 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
|
||||
$this->app['notification.deliverer']->deliver($mail, $params['accuse']);
|
||||
|
||||
$mailed = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -119,18 +119,22 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($usr_id)) {
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$admin_user = User_Adapter::getInstance($usr_id, $this->app);
|
||||
|
||||
$receiver = Receiver::fromUser($admin_user);
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoUserRegistered::create($this->app, $receiver);
|
||||
$mail->setRegisteredUser($registeredUser);
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
|
||||
$mailed = true;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -110,13 +110,18 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($user->get_id())) {
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$receiver = Receiver::fromUser($user);
|
||||
$readyToSend = true;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoRecordQuarantined::create($this->app, $receiver);
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,8 +10,9 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
use Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest;
|
||||
use Alchemy\Phrasea\Notification\Emitter;
|
||||
use Alchemy\Phrasea\Notification\Receiver;
|
||||
|
||||
class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
|
||||
{
|
||||
@@ -89,34 +90,32 @@ class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['to'])) {
|
||||
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$user_from = User_Adapter::getInstance($params['from'], $this->app);
|
||||
$user_to = User_Adapter::getInstance($params['to'], $this->app);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$basket = $this->app['EM']
|
||||
->getRepository('\Entities\Basket')
|
||||
->find($params['ssel_id']);
|
||||
$title = $basket->getName();
|
||||
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Emitter::fromUser($user_from);
|
||||
|
||||
$readyToSend = true;
|
||||
} catch (\Exception $e) {
|
||||
$title = '';
|
||||
|
||||
}
|
||||
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Receiver::fromUser($user_from);
|
||||
|
||||
try {
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']);
|
||||
$mail->setButtonUrl($params['url']);
|
||||
$mail->setTitle($title);
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail, $params['accuse']);
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,8 +10,9 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
use Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone;
|
||||
use Alchemy\Phrasea\Notification\Emitter;
|
||||
use Alchemy\Phrasea\Notification\Receiver;
|
||||
|
||||
class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
|
||||
{
|
||||
@@ -85,34 +86,31 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
|
||||
$mailed = false;
|
||||
|
||||
if ($this->shouldSendNotificationFor($params['to'])) {
|
||||
$readyToSend = false;
|
||||
try {
|
||||
$user_from = User_Adapter::getInstance($params['from'], $this->app);
|
||||
$user_to = User_Adapter::getInstance($params['to'], $this->app);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$basket = $this->app['EM']
|
||||
->getRepository('\Entities\Basket')
|
||||
->find($params['ssel_id']);
|
||||
$title = $basket->getName();
|
||||
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Emitter::fromUser($user_from);
|
||||
|
||||
$readyToSend = true;
|
||||
} catch (\Exception $e) {
|
||||
$title = '';
|
||||
|
||||
}
|
||||
|
||||
$receiver = Receiver::fromUser($user_to);
|
||||
$emitter = Receiver::fromUser($user_from);
|
||||
|
||||
try {
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoValidationDone::create($this->app, $receiver, $emitter);
|
||||
$mail->setButtonUrl($params['url']);
|
||||
$mail->setTitle($title);
|
||||
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
$mailed = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,8 +26,9 @@ abstract class eventsmanager_notifyAbstract extends eventsmanager_eventAbstract
|
||||
protected function get_prefs($class, $usr_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($usr_id, $this->app);
|
||||
$pref = $user->getPrefs('notification_' . $class);
|
||||
|
||||
return $user->getPrefs('notification_' . $class);
|
||||
return null !== $pref ? $pref : 1;
|
||||
}
|
||||
|
||||
protected function shouldSendNotificationFor($usr_id)
|
||||
|
@@ -471,7 +471,7 @@ class set_order extends set_abstract
|
||||
$stmt->closeCursor();
|
||||
$n ++;
|
||||
}
|
||||
|
||||
|
||||
if ($n > 0) {
|
||||
$params = array(
|
||||
'from' => $this->app['phraseanet.user']->get_id(),
|
||||
|
Reference in New Issue
Block a user