diff --git a/composer.json b/composer.json index 4731df0d40..58663b68a6 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 366666bde2..6eab1646da 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php index 6e6e5f18fc..0abdc3f525 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Edit.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Edit.php @@ -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(); diff --git a/lib/Alchemy/Phrasea/Controller/Report/Activity.php b/lib/Alchemy/Phrasea/Controller/Report/Activity.php index 2294d56ed9..961db4fd71 100644 --- a/lib/Alchemy/Phrasea/Controller/Report/Activity.php +++ b/lib/Alchemy/Phrasea/Controller/Report/Activity.php @@ -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( diff --git a/lib/Alchemy/Phrasea/Notification/Attachment.php b/lib/Alchemy/Phrasea/Notification/Attachment.php new file mode 100644 index 0000000000..237c7f3ed1 --- /dev/null +++ b/lib/Alchemy/Phrasea/Notification/Attachment.php @@ -0,0 +1,50 @@ +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; + } +} diff --git a/lib/Alchemy/Phrasea/Notification/Deliverer.php b/lib/Alchemy/Phrasea/Notification/Deliverer.php index 0a79e87138..c11527d9e0 100644 --- a/lib/Alchemy/Phrasea/Notification/Deliverer.php +++ b/lib/Alchemy/Phrasea/Notification/Deliverer.php @@ -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'); diff --git a/lib/classes/caption/field.php b/lib/classes/caption/field.php index e720ca73d2..07efb26010 100644 --- a/lib/classes/caption/field.php +++ b/lib/classes/caption/field.php @@ -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) { diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index 193ff36a4f..34f916f1f3 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -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; } diff --git a/lib/classes/module/report/activity.php b/lib/classes/module/report/activity.php index 30b7e76fd2..853d1c947b 100644 --- a/lib/classes/module/report/activity.php +++ b/lib/classes/module/report/activity.php @@ -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]) ? "" . $this->app->trans('report:: non-renseigne') . "" : $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]) ? "" . $this->app->trans('report:: non-renseigne') . "" : $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'] = 'TOTAL'; $this->result[$nb_row]['nbdoc'] = '' . $total['nbdoc'] . ''; - $this->result[$nb_row]['poiddoc'] = - '' . p4string::format_octets($total['poiddoc']) . ''; $this->result[$nb_row]['nbprev'] = '' . $total['nbprev'] . ''; - $this->result[$nb_row]['poidprev'] = - '' . p4string::format_octets($total['poidprev']) . ''; } foreach($this->result as $k=>$row) { diff --git a/lib/classes/module/report/download.php b/lib/classes/module/report/download.php index 60fc0fe363..3a36b0365b 100644 --- a/lib/classes/module/report/download.php +++ b/lib/classes/module/report/download.php @@ -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' ]; /** diff --git a/lib/classes/module/report/sqldownload.php b/lib/classes/module/report/sqldownload.php index 9130074a16..dd62cee444 100644 --- a/lib/classes/module/report/sqldownload.php +++ b/lib/classes/module/report/sqldownload.php @@ -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 ( log_docs.action = \'download\' OR log_docs.action = \'mail\') '; - $this->sql .= $this->on == 'DOC' ? 'AND subdef.name = \'document\' ' : ''; + $this->sql .= ' AND !ISNULL(usrid)'; + $this->sql .= ' AND (log_docs.action = \'download\' OR log_docs.action = \'mail\') '; + $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() ? : ''; diff --git a/tests/Alchemy/Tests/Phrasea/Notification/AttachmentTest.php b/tests/Alchemy/Tests/Phrasea/Notification/AttachmentTest.php new file mode 100644 index 0000000000..546eb2c011 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Notification/AttachmentTest.php @@ -0,0 +1,40 @@ +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); + } +}