mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Merge branch '3.8'
Conflicts: composer.json composer.lock lib/Alchemy/Phrasea/Controller/Prod/Edit.php lib/Alchemy/Phrasea/Controller/Report/Activity.php lib/classes/caption/field.php lib/classes/module/report/activity.php lib/classes/module/report/download.php lib/classes/task/period/apibridge.php
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
"require": {
|
||||
"php" : ">=5.4",
|
||||
"alchemy/oauth2php" : "1.0.0",
|
||||
"alchemy/phlickr" : "0.2.8",
|
||||
"alchemy/phlickr" : "0.2.9",
|
||||
"alchemy/task-manager" : "2.0.x-dev@dev",
|
||||
"alchemy/zippy" : "0.2.x-dev@dev",
|
||||
"cboden/ratchet" : "~0.3",
|
||||
|
10
composer.lock
generated
10
composer.lock
generated
@@ -282,16 +282,16 @@
|
||||
},
|
||||
{
|
||||
"name": "alchemy/phlickr",
|
||||
"version": "0.2.8",
|
||||
"version": "0.2.9",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alchemy-fr/Phlickr.git",
|
||||
"reference": "26b7764fd45c15062cb1b21c9389aff919e8c2bd"
|
||||
"reference": "f9af93e27e9235db43e61ce2f9588d8ce9859b68"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/alchemy-fr/Phlickr/zipball/26b7764fd45c15062cb1b21c9389aff919e8c2bd",
|
||||
"reference": "26b7764fd45c15062cb1b21c9389aff919e8c2bd",
|
||||
"url": "https://api.github.com/repos/alchemy-fr/Phlickr/zipball/f9af93e27e9235db43e61ce2f9588d8ce9859b68",
|
||||
"reference": "f9af93e27e9235db43e61ce2f9588d8ce9859b68",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
@@ -301,7 +301,7 @@
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"time": "2014-07-07 16:25:07"
|
||||
"time": "2014-12-15 14:27:57"
|
||||
},
|
||||
{
|
||||
"name": "alchemy/task-manager",
|
||||
|
@@ -295,6 +295,7 @@ class Edit implements ControllerProviderInterface
|
||||
|
||||
$media = $app['mediavorus']->guess($value->get_pathfile());
|
||||
$app['subdef.substituer']->substitute($reg_record, $name, $media);
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($reg_record));
|
||||
$app['phraseanet.logger']($reg_record->get_databox())->log(
|
||||
$reg_record,
|
||||
\Session_Logger::EVENT_SUBSTITUTE,
|
||||
@@ -311,8 +312,6 @@ class Edit implements ControllerProviderInterface
|
||||
return $app->json(['message' => '', 'error' => false]);
|
||||
}
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($records));
|
||||
|
||||
$databoxes = $records->databoxes();
|
||||
$databox = array_pop($databoxes);
|
||||
|
||||
@@ -342,6 +341,7 @@ class Edit implements ControllerProviderInterface
|
||||
|
||||
if (isset($rec['metadatas']) && is_array($rec['metadatas'])) {
|
||||
$record->set_metadatas($rec['metadatas']);
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($record));
|
||||
}
|
||||
|
||||
$newstat = $record->get_status();
|
||||
|
@@ -133,9 +133,7 @@ class Activity implements ControllerProviderInterface
|
||||
$conf = [
|
||||
'user' => [$app->trans('report:: utilisateur'), 0, 1, 0, 0],
|
||||
'nbdoc' => [$app->trans('report:: nombre de documents'), 0, 0, 0, 0],
|
||||
'poiddoc' => [$app->trans('report:: poids des documents'), 0, 0, 0, 0],
|
||||
'nbprev' => [$app->trans('report:: nombre de preview'), 0, 0, 0, 0],
|
||||
'poidprev' => [$app->trans('report:: poids des previews'), 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
$activity = new \module_report_activity(
|
||||
|
50
lib/Alchemy/Phrasea/Notification/Attachment.php
Normal file
50
lib/Alchemy/Phrasea/Notification/Attachment.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Notification;
|
||||
|
||||
/**
|
||||
* Class Attachment attach file to a mail
|
||||
* @package Alchemy\Phrasea\Notification
|
||||
*/
|
||||
class Attachment
|
||||
{
|
||||
private $path;
|
||||
private $filename;
|
||||
private $contentType;
|
||||
|
||||
/**
|
||||
* @param string $path path to an existing file to be added as attachment
|
||||
* @param string $filename change the name of attachment, (default to '' to use filename from path)
|
||||
* @param string $contentType change mime, (default to '' to get from path)
|
||||
*/
|
||||
public function __construct($path, $filename='', $contentType='')
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->filename = $filename;
|
||||
$this->contentType = $contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Swift_Mime_Attachment the attachment as a swift attachment
|
||||
*/
|
||||
public function As_Swift_Attachment()
|
||||
{
|
||||
$swa = \Swift_Attachment::fromPath($this->path);
|
||||
if($this->filename !== '') {
|
||||
$swa->setFilename($this->filename);
|
||||
}
|
||||
if($this->contentType !== '') {
|
||||
$swa->setContentType($this->contentType);
|
||||
}
|
||||
return $swa;
|
||||
}
|
||||
}
|
@@ -47,7 +47,7 @@ class Deliverer
|
||||
* @throws LogicException In case no Receiver provided
|
||||
* @throws LogicException In case a read-receipt is asked but no Emitter provided
|
||||
*/
|
||||
public function deliver(MailInterface $mail, $readReceipt = false)
|
||||
public function deliver(MailInterface $mail, $readReceipt = false, array $attachments = null)
|
||||
{
|
||||
if (!$mail->getReceiver()) {
|
||||
throw new LogicException('You must provide a receiver for a mail notification');
|
||||
@@ -63,6 +63,12 @@ class Deliverer
|
||||
$message->setReplyTo($mail->getEmitter()->getEmail(), $mail->getEmitter()->getName());
|
||||
}
|
||||
|
||||
if(is_array($attachments)) {
|
||||
foreach($attachments as $attachment) {
|
||||
$message->attach($attachment->As_Swift_Attachment());
|
||||
}
|
||||
}
|
||||
|
||||
if ($readReceipt) {
|
||||
if (!$mail->getEmitter()) {
|
||||
throw new LogicException('You must provide an emitter for a ReadReceipt');
|
||||
|
@@ -282,7 +282,7 @@ class caption_field implements cache_cacheableInterface
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function rename_all_metadatas(databox_field $databox_field)
|
||||
public static function rename_all_metadatas(Application $app, databox_field $databox_field)
|
||||
{
|
||||
$sql = 'SELECT count(id) as count_id FROM metadatas
|
||||
WHERE meta_struct_id = :meta_struct_id';
|
||||
@@ -317,10 +317,6 @@ class caption_field implements cache_cacheableInterface
|
||||
try {
|
||||
$record = $databox_field->get_databox()->get_record($row['record_id']);
|
||||
$record->set_metadatas([]);
|
||||
|
||||
/**
|
||||
* TODO NEUTRON add App
|
||||
*/
|
||||
$app['phraseanet.SE']->updateRecord($record);
|
||||
unset($record);
|
||||
} catch (\Exception $e) {
|
||||
|
@@ -422,7 +422,7 @@ class databox_field implements cache_cacheableInterface
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($this->renamed) {
|
||||
caption_field::rename_all_metadatas($this);
|
||||
caption_field::rename_all_metadatas($this->app, $this);
|
||||
$this->renamed = false;
|
||||
}
|
||||
|
||||
|
@@ -343,13 +343,11 @@ class module_report_activity extends module_report
|
||||
SELECT DISTINCT(log.id), log_docs.date AS the_date, log_docs.final, log_docs.record_id
|
||||
FROM (log_docs)
|
||||
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)
|
||||
WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
|
||||
AND (log_docs.action = 'download' OR log_docs.action = 'mail')
|
||||
AND (log_docs.final = 'preview' OR log_docs.final = 'document')
|
||||
) AS tt
|
||||
LEFT JOIN record ON (record.record_id = tt.record_id)
|
||||
LEFT JOIN subdef AS s ON (s.record_id = tt.record_id)
|
||||
WHERE s.name = tt.final
|
||||
GROUP BY tt.final, ddate
|
||||
ORDER BY tt.the_date DESC";
|
||||
|
||||
@@ -525,19 +523,14 @@ class module_report_activity extends module_report
|
||||
$params = array_merge([], $filter['params']);
|
||||
|
||||
$sql = "
|
||||
SELECT tt.usrid, TRIM(" . $on . ") AS " . $on . ", tt.final, sum(1) AS nb, sum(size) AS poid
|
||||
FROM (
|
||||
SELECT DISTINCT(log.id), TRIM(" . $on . ") AS " . $on . ", log_docs.record_id, log_docs.final, log.usrid
|
||||
SELECT TRIM(" . $on . ") AS " . $on . ", SUM(1) AS nb, log_docs.final, log.usrid
|
||||
FROM log_docs
|
||||
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (record.record_id = log_docs.record_id)
|
||||
WHERE (" . $filter['sql'] . ") AND !ISNULL(usrid)
|
||||
AND (log_docs.action = 'download' OR log_docs.action = 'mail')
|
||||
) AS tt
|
||||
LEFT JOIN record ON (record.record_id = tt.record_id)
|
||||
LEFT JOIN subdef FORCE INDEX (unicite) ON (tt.record_id = subdef.record_id)
|
||||
WHERE subdef.name = tt.final
|
||||
GROUP BY " . $on . ", usrid
|
||||
ORDER BY nb DESC;";
|
||||
AND (log_docs.final = 'preview' OR log_docs.final = 'document')
|
||||
GROUP BY usrid";
|
||||
|
||||
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $sql), FILE_APPEND);
|
||||
|
||||
@@ -550,9 +543,7 @@ class module_report_activity extends module_report
|
||||
$i = -1;
|
||||
$total = [
|
||||
'nbdoc' => 0,
|
||||
'poiddoc' => 0,
|
||||
'nbprev' => 0,
|
||||
'poidprev' => 0
|
||||
];
|
||||
|
||||
$this->setChamp($rs);
|
||||
@@ -563,47 +554,36 @@ class module_report_activity extends module_report
|
||||
$user = $row[$on];
|
||||
if (($save_user != $user) && ! is_null($user) && ! empty($user)) {
|
||||
if ($i >= 0) {
|
||||
if (($this->result[$i]['nbprev'] + $this->result[$i]['nbdoc']) == 0 || ($this->result[$i]['poiddoc'] + $this->result[$i]['poidprev']) == 0) {
|
||||
if (($this->result[$i]['nbprev'] + $this->result[$i]['nbdoc']) == 0) {
|
||||
unset($this->result[$i]);
|
||||
}
|
||||
|
||||
if (isset($this->result[$i]['poiddoc']) && isset($this->result[$i]['poidprev'])) {
|
||||
$this->result[$i]['poiddoc'] = p4string::format_octets($this->result[$i]['poiddoc']);
|
||||
$this->result[$i]['poidprev'] = p4string::format_octets($this->result[$i]['poidprev']);
|
||||
}
|
||||
}
|
||||
|
||||
$i ++;
|
||||
|
||||
$this->result[$i]['nbprev'] = 0;
|
||||
$this->result[$i]['poidprev'] = 0;
|
||||
$this->result[$i]['nbdoc'] = 0;
|
||||
$this->result[$i]['poiddoc'] = 0;
|
||||
}
|
||||
|
||||
//doc info
|
||||
if ($row['final'] == 'document' &&
|
||||
! is_null($user) && ! is_null($row['usrid'])) {
|
||||
$this->result[$i]['nbdoc'] = ( ! is_null($row['nb']) ? $row['nb'] : 0);
|
||||
$this->result[$i]['poiddoc'] = ( ! is_null($row['poid']) ? $row['poid'] : 0);
|
||||
$this->result[$i]['user'] = empty($row[$on]) ?
|
||||
"<i>" . $this->app->trans('report:: non-renseigne') . "</i>" : $row[$on];
|
||||
$total['nbdoc'] += $this->result[$i]['nbdoc'];
|
||||
$total['poiddoc'] += ( ! is_null($row['poid']) ? $row['poid'] : 0);
|
||||
$this->result[$i]['usrid'] = $row['usrid'];
|
||||
}
|
||||
//preview info
|
||||
if (($row['final'] == 'preview' || $row['final'] == 'thumbnail') &&
|
||||
if (($row['final'] == 'preview') &&
|
||||
! is_null($user) &&
|
||||
! is_null($row['usrid'])) {
|
||||
|
||||
$this->result[$i]['nbprev'] += ( ! is_null($row['nb']) ? $row['nb'] : 0);
|
||||
$this->result[$i]['poidprev'] += ( ! is_null($row['poid']) ? $row['poid'] : 0);
|
||||
|
||||
$this->result[$i]['user'] = empty($row[$on]) ?
|
||||
"<i>" . $this->app->trans('report:: non-renseigne') . "</i>" : $row[$on];
|
||||
$total['nbprev'] += ( ! is_null($row['nb']) ? $row['nb'] : 0);
|
||||
$total['poidprev'] += ( ! is_null($row['poid']) ? $row['poid'] : 0);
|
||||
$this->result[$i]['usrid'] = $row['usrid'];
|
||||
}
|
||||
|
||||
@@ -617,11 +597,7 @@ class module_report_activity extends module_report
|
||||
if ($this->total > 0) {
|
||||
$this->result[$nb_row]['user'] = '<b>TOTAL</b>';
|
||||
$this->result[$nb_row]['nbdoc'] = '<b>' . $total['nbdoc'] . '</b>';
|
||||
$this->result[$nb_row]['poiddoc'] =
|
||||
'<b>' . p4string::format_octets($total['poiddoc']) . '</b>';
|
||||
$this->result[$nb_row]['nbprev'] = '<b>' . $total['nbprev'] . '</b>';
|
||||
$this->result[$nb_row]['poidprev'] =
|
||||
'<b>' . p4string::format_octets($total['poidprev']) . '</b>';
|
||||
}
|
||||
|
||||
foreach($this->result as $k=>$row) {
|
||||
|
@@ -26,10 +26,7 @@ class module_report_download extends module_report
|
||||
'log_id' => 'log_docs.log_id',
|
||||
'record_id' => 'log_docs.record_id',
|
||||
'final' => 'log_docs.final',
|
||||
'comment' => 'log_docs.comment',
|
||||
'size' => 'subdef.size',
|
||||
'mime' => 'subdef.mime',
|
||||
'file' => 'subdef.file'
|
||||
'comment' => 'log_docs.comment'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@@ -48,7 +48,6 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
FROM log_docs
|
||||
INNER JOIN log FORCE INDEX (date_site) ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (record.record_id=log_docs.record_id)
|
||||
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)
|
||||
WHERE (" .$filter['sql'] . ")
|
||||
AND !ISNULL(usrid)
|
||||
AND (log_docs.action = 'download' OR log_docs.action = 'mail')
|
||||
@@ -61,21 +60,16 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
|
||||
if ($name == 'record_id' && $this->on == 'DOC') {
|
||||
$this->sql = '
|
||||
SELECT ' . $name . ', SUM(1) AS telechargement, tt.comment, tt.size, tt.file, tt.mime, tt.final
|
||||
SELECT ' . $name . ', SUM(1) AS telechargement, tt.comment, tt.final
|
||||
FROM (
|
||||
SELECT log.id, TRIM( ' . $field . ' ) AS ' . $name . ', log_docs.comment, subdef.size, subdef.file, subdef.mime, log_docs.final
|
||||
SELECT log.id, TRIM( ' . $field . ' ) AS ' . $name . ', log_docs.comment, log_docs.final
|
||||
FROM log FORCE INDEX (date_site)
|
||||
INNER JOIN log_docs ON (log.id = log_docs.log_id)
|
||||
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)
|
||||
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)';
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)';
|
||||
|
||||
$customFieldMap = [
|
||||
$field => $name,
|
||||
'log_docs.comment' => 'tt.comment',
|
||||
'subdef.size' => 'tt.size',
|
||||
'subdef.file' => 'tt.file',
|
||||
'subdef.mime' => 'tt.mime',
|
||||
'log_docs.final' => 'tt.final',
|
||||
];
|
||||
|
||||
@@ -86,8 +80,7 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
SELECT DISTINCT(log.id), TRIM(' . $field . ') AS ' . $name . '
|
||||
FROM log FORCE INDEX (date_site)
|
||||
INNER JOIN log_docs ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)
|
||||
LEFT JOIN subdef ON ( log_docs.record_id = subdef.record_id)';
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)';
|
||||
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
|
||||
} else {
|
||||
$this->sql = '
|
||||
@@ -96,14 +89,14 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
SELECT DISTINCT(log.id), TRIM( ' . $this->getTransQuery($this->groupby) . ') AS ' . $name . '
|
||||
FROM log FORCE INDEX (date_site)
|
||||
INNER JOIN log_docs ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)
|
||||
LEFT JOIN subdef ON (record.record_id = subdef.record_id)';
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)';
|
||||
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
|
||||
}
|
||||
|
||||
$this->sql .= ' WHERE ' . $filter['sql'] . ' ';
|
||||
$this->sql .= ' AND !ISNULL(usrid)';
|
||||
$this->sql .= ' AND (log_docs.action = \'download\' OR log_docs.action = \'mail\') ';
|
||||
$this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : '';
|
||||
$this->sql .= $this->on == 'DOC' ? ' AND (log_docs.final = "document") ' : ' AND (log_docs.final = "preview" OR log_docs.final = "document")';
|
||||
$this->sql .= ') as tt';
|
||||
$this->sql .= ' GROUP BY ' . $name . ' ' . ($name == 'record_id' && $this->on == 'DOC' ? ', final' : '');
|
||||
// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n%s\n\n", __FILE__, __LINE__, $this->sql), FILE_APPEND);
|
||||
@@ -142,10 +135,10 @@ class module_report_sqldownload extends module_report_sql implements module_repo
|
||||
FROM log FORCE INDEX (date_site)
|
||||
INNER JOIN log_docs ON (log.id = log_docs.log_id)
|
||||
LEFT JOIN record ON (log_docs.record_id = record.record_id)
|
||||
LEFT JOIN subdef ON (log_docs.record_id = subdef.record_id)
|
||||
WHERE (' . $filter['sql'] . ')
|
||||
AND !ISNULL(log.usrid)
|
||||
AND (log_docs.action = "download" OR log_docs.action = "mail")' .
|
||||
($this->on == 'DOC' ? ' AND subdef.name = "document"' : '') .
|
||||
($this->on == 'DOC' ? ' AND (log_docs.final = "document") ' : ' AND (log_docs.final = "preview" OR log_docs.final = "document")') .
|
||||
') AS tt';
|
||||
|
||||
$this->sql .= $this->filter->getOrderFilter() ? : '';
|
||||
|
40
tests/Alchemy/Tests/Phrasea/Notification/AttachmentTest.php
Normal file
40
tests/Alchemy/Tests/Phrasea/Notification/AttachmentTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Notification;
|
||||
|
||||
use Alchemy\Phrasea\Notification\Attachment;
|
||||
|
||||
class AttachmentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Attachment
|
||||
*/
|
||||
protected $object;
|
||||
protected $tempFile;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->tempFile = tempnam(null, 'attachment');
|
||||
$this->object = new Attachment($this->tempFile, 'test.txt', 'text/plain');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Alchemy\Phrasea\Notification\Attachment::As_Swift_Attachment
|
||||
*/
|
||||
public function testAsSwiftAttachment()
|
||||
{
|
||||
/** @var $a \Swift_Mime_Attachment */
|
||||
$swa = $this->object->As_Swift_Attachment();
|
||||
|
||||
$this->assertInstanceOf('Swift_Attachment', $swa);
|
||||
$this->assertEquals($swa->getContentType(), 'text/plain');
|
||||
$this->assertEquals($swa->getFilename(), 'test.txt');
|
||||
|
||||
unset($swa);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unlink($this->tempFile);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user