diff --git a/.travis.yml b/.travis.yml index 36a007c..1c550a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: php sudo: false php: - - 7.2 + - 7.4 services: - mysql @@ -18,8 +18,7 @@ before_install: - echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini install: - - composer global require hirak/prestissimo - - composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs + - composer global require drupal/coder mglaman/drupal-check friendsoftwig/twigcs - export PATH="$HOME/.config/composer/vendor/bin:$PATH" - phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer - phpenv rehash @@ -28,6 +27,7 @@ install: - npm install --global yarn - cd ../ && composer create-project drupal-composer/drupal-project:8.x-dev drupal --no-interaction - cd drupal + - composer require drush/drush:9.x-dev -W - DRUPAL_ROOT=$(pwd)/web - export REPOSITORIES='"repositories":\ \[' - export REPOSITORIES_REPLACE='"repositories":\[\{"type":"path","url":"..\/os2web_meetings","options":\{"symlink":false\}\},' diff --git a/modules/os2web_meetings_print/src/Plugin/Block/MeetingDocumentDownload.php b/modules/os2web_meetings_print/src/Plugin/Block/MeetingDocumentDownload.php index 40c1582..557fea0 100644 --- a/modules/os2web_meetings_print/src/Plugin/Block/MeetingDocumentDownload.php +++ b/modules/os2web_meetings_print/src/Plugin/Block/MeetingDocumentDownload.php @@ -4,10 +4,7 @@ use Drupal\Core\Block\BlockBase; use Drupal\Core\Link; -use Drupal\Core\Url; -use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; -use Drupal\os2web_pagebuilder\Form\SettingsForm; /** * Provides a 'OS2Web Meetings Document Download' block. @@ -40,7 +37,7 @@ public function build() { /** * Make block links markup. * - * @param NodeInterface $meeting + * @param \Drupal\node\Entity\NodeInterface $meeting * Meeting node. * * @return string @@ -57,17 +54,6 @@ private function getMarkup(NodeInterface $meeting) { $pdfLink = Link::fromTextAndUrl(t('Download samlet dokument'), $pdfUrl)->toString(); $output = '' . $pdfLink . ''; - -// $output = ''; - return $output; } diff --git a/modules/os2web_meetings_search/src/Plugin/Block/RelatedSearchPageLink.php b/modules/os2web_meetings_search/src/Plugin/Block/RelatedSearchPageLink.php index 2ea2d02..e0307ba 100644 --- a/modules/os2web_meetings_search/src/Plugin/Block/RelatedSearchPageLink.php +++ b/modules/os2web_meetings_search/src/Plugin/Block/RelatedSearchPageLink.php @@ -9,6 +9,7 @@ /** * Provides OS2Web Meeting Search Related search page link. + * * @Block( * id = "os2web_meetings_search_rel_search_page_link", * admin_label = @Translation("OS2Web Meeting Search Related search page link"), @@ -43,8 +44,9 @@ public function build() { if ($url) { $link = $url->toString(); - $markup = Markup::create(t('Søg i ' . $urlText . '', [ + $markup = Markup::create(t('Søg i @text', [ ':url' => $link, + '@text' => $urlText, ])); return [ @@ -61,7 +63,8 @@ public function build() { * {@inheritdoc} */ public function getCacheContexts() { - $context = parent::getCacheContexts(); // TODO: Change the autogenerated stub + // @todo Change the autogenerated stub. + $context = parent::getCacheContexts(); $context[] = 'url.path'; $context[] = 'url.query_args'; return $context; diff --git a/os2web_meetings.install b/os2web_meetings.install index 1c44254..f4d5420 100644 --- a/os2web_meetings.install +++ b/os2web_meetings.install @@ -165,3 +165,55 @@ function os2web_meetings_update_8008() { // Updating view. $active_storage->write('views.view.os2web_meetings_search', Yaml::parse(file_get_contents($path . '/config/optional/views.view.os2web_meetings_search.yml'))); } + +/** + * Make sure that imported pdf files did get .pdf extension. + */ +function os2web_meetings_update_8009() { + $field_name = 'field_os2web_m_doc'; + $bundle = 'os2web_meetings_meeting'; + $connection = \Drupal::database(); + $result_m = $connection->select('node__' . $field_name, 'f') + ->fields('f', array($field_name . '_target_id')) + ->distinct(TRUE) + ->condition('bundle', $bundle) + ->execute()->fetchCol(); + + $field_name = 'field_os2web_m_bp_enclosures'; + $bundle = 'os2web_meetings_bp'; + $connection = \Drupal::database(); + $result_bp = $connection->select('node__' . $field_name, 'f') + ->fields('f', array($field_name . '_target_id')) + ->distinct(TRUE) + ->condition('bundle', $bundle) + ->execute()->fetchCol(); + + $field_name = 'field_os2web_m_bpa_file'; + $bundle = 'os2web_meetings_bpa'; + $connection = \Drupal::database(); + $result_bpa = $connection->select('node__' . $field_name, 'f') + ->fields('f', array($field_name . '_target_id')) + ->distinct(TRUE) + ->condition('bundle', $bundle) + ->execute()->fetchCol(); + $result = array_merge($result_m, $result_bp, $result_bpa); + + $messenger = \Drupal::messenger(); + $counter = 0; + foreach ($result as $id) { + $file = \Drupal\file\Entity\File::load($id); + $filename = $file->getFilename(); + $ext = pathinfo($filename, PATHINFO_EXTENSION); + + if ($ext != 'pdf' && $file->getMimeType() == 'application/pdf') { + $new_filename = $filename .'.pdf'; + $file->setFilename($new_filename); + $file->save(); + $counter++; + } + } + $messenger->addStatus(sprintf( + '%s files has been updated with correct extension', + $counter + )); +} diff --git a/src/Entity/BulletPointAttachment.php b/src/Entity/BulletPointAttachment.php index 83d07cd..00de9fc 100644 --- a/src/Entity/BulletPointAttachment.php +++ b/src/Entity/BulletPointAttachment.php @@ -2,7 +2,6 @@ namespace Drupal\os2web_meetings\Entity; -use Drupal\decreto_content_modify\Entity\DecretoBulletPoint; use Drupal\node\Entity\Node; /** diff --git a/src/EventSubscriber/MeetingContentRedirectSubscriber.php b/src/EventSubscriber/MeetingContentRedirectSubscriber.php index 0c38ee4..5b6983b 100644 --- a/src/EventSubscriber/MeetingContentRedirectSubscriber.php +++ b/src/EventSubscriber/MeetingContentRedirectSubscriber.php @@ -2,7 +2,6 @@ namespace Drupal\os2web_meetings\EventSubscriber; -use Drupal\node\NodeInterface; use Drupal\os2web_meetings\Entity\BulletPoint; use Drupal\os2web_meetings\Entity\BulletPointAttachment; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -25,7 +24,7 @@ class MeetingContentRedirectSubscriber implements EventSubscriberInterface { * @throws \Drupal\Core\Entity\Exception\UnsupportedEntityTypeDefinitionException */ public function nodeRedirect(GetResponseEvent $event) { - /** @var NodeInterface $node */ + /** @var \Drupal\node\NodeInterface $node */ $node = NULL; $routeMatch = \Drupal::routeMatch(); if ($routeMatch->getRouteName() == 'entity.node.canonical' && $node = $routeMatch->getParameter('node')) { @@ -35,7 +34,7 @@ public function nodeRedirect(GetResponseEvent $event) { $bulletPoint = new BulletPoint($node); $meetingNode = $bulletPoint->getMeeting(); } - elseif ($node->getType() == 'os2web_meetings_bpa'){ + elseif ($node->getType() == 'os2web_meetings_bpa') { $bpa = new BulletPointAttachment($node); $meetingNode = $bpa->getMeeting(); } diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index 8cee613..742911c 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -88,7 +88,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => t('Create copy of attachments files during import'), '#description' => t('This decides if file copy should be created when enclosures imported'), '#default_value' => ($this->config(SettingsForm::$configName) - ->get('create_files_copy') !== null) ? $this->config(SettingsForm::$configName) + ->get('create_files_copy') !== NULL) ? $this->config(SettingsForm::$configName) ->get('create_files_copy') : TRUE, ]; @@ -188,7 +188,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => t('Show closed agendas separately'), '#default_value' => $this->config(SettingsForm::$configName) - ->get('show_closed_agendas_separately'), + ->get('show_closed_agendas_separately'), ]; return parent::buildForm($form, $form_state); diff --git a/src/MeetingsDirectoryInterface.php b/src/MeetingsDirectoryInterface.php index cfd4844..4e900df 100644 --- a/src/MeetingsDirectoryInterface.php +++ b/src/MeetingsDirectoryInterface.php @@ -22,7 +22,7 @@ interface MeetingsDirectoryInterface extends ImportAwareInterface { * @var string */ const AGENDA_TYPE_REFERAT = 'Referat'; - + /** * Agenda type Kladde. * @@ -200,6 +200,8 @@ public function convertBulletPointsToCanonical(array $source); * * @param array $source * Raw array values from ESDH provider. + * @param bool $access + * Access boolean argument. * * @return mixed * Array of attachments in canonical format: @@ -236,7 +238,7 @@ public function convertAttachmentsToCanonical(array $source, $access = TRUE); * ] */ public function convertEnclosuresToCanonical(array $source); - + /** * Convert the agenda participants to canonical format. * @@ -249,7 +251,7 @@ public function convertEnclosuresToCanonical(array $source); * Agenda type as string. */ public function convertParticipantToCanonical(array $source); - + /** * Convert the agenda id to canonical format. * @@ -261,7 +263,6 @@ public function convertParticipantToCanonical(array $source); * @return string * Agenda type as string. */ - public function convertAgendaIdToCanonical(array $source); - + } diff --git a/src/Plugin/migrate/source/MeetingsDirectory.php b/src/Plugin/migrate/source/MeetingsDirectory.php index 54b0771..77fe63f 100644 --- a/src/Plugin/migrate/source/MeetingsDirectory.php +++ b/src/Plugin/migrate/source/MeetingsDirectory.php @@ -111,7 +111,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition // very few modifications. // Always get UNIX paths, skipping . and .., key as filename, and follow // links. - $flags = \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::KEY_AS_FILENAME | @@ -194,13 +193,12 @@ public function prepareRow(Row $row) { if (!$result) { return $result; } - // TODO: meeting skipping, meeting updating (agenda->referat etc) + // @todo Meeting skipping, meeting updating (agenda->referat etc) // Check if the current meeting needs creating updating. if (!$row->getIdMap() || $row->needsUpdate() || $this->aboveHighwater($row) || $this->rowChanged($row)) { print_r(PHP_EOL . 'Importing meeting: ' . $agendaId . PHP_EOL); // Setting meeting source ID. - $row->setDestinationProperty('field_os2web_m_source', $this->getPluginId()); $meetingDirectoryPath = $row->getSourceProperty('directory_path'); @@ -258,12 +256,12 @@ public function prepareRow(Row $row) { $bulletPointTargets = $this->processBulletPoints($bulletPointsCanonical, $meetingDirectoryPath, $meeting); $row->setSourceProperty('bullet_points_targets', $bulletPointTargets); - // Process participants + // Process participants. $participantsCanonical = $this->convertParticipantToCanonical($source); - if (!empty($participantsCanonical['participants'])){ + if (!empty($participantsCanonical['participants'])) { $row->setSourceProperty('participants', implode(',', $participantsCanonical['participants'])); } - if (!empty($participantsCanonical['participants_canceled'])){ + if (!empty($participantsCanonical['participants_canceled'])) { $row->setSourceProperty('cancel_participants', implode(',', $participantsCanonical['participants_canceled'])); } } @@ -554,7 +552,7 @@ protected function processBulletPoints(array $bulletPoints, $directoryPath, $mee } } - // TODO think about deleting the BPs. + // @todo Think about deleting the BPs. return $bulletPointsTargets; } @@ -613,7 +611,7 @@ protected function processEnclosures(array $enclosures, $directoryPath, $bulletP } } - // TODO think about deleting the enclosures. + // @todo Think about deleting the enclosures. return $enclosureTargets; } @@ -694,7 +692,7 @@ protected function processAttachments(array $attachments, $directoryPath, Bullet } } - // TODO think about deleting the BPAs. + // @todo Think about deleting the BPAs. return $bpaTargets; } @@ -740,7 +738,7 @@ protected function createFileCopyAsManaged($uri, $title = NULL) { $name = $basename; $ext = ''; } - $original_name = $name; + $original_name = $name . $ext; // If the desired title is provided, use it. Otherwise take the original // title and concat '_0'. if ($title) { @@ -760,10 +758,10 @@ protected function createFileCopyAsManaged($uri, $title = NULL) { $createFilesCopy = $settingFormConfig->get('create_files_copy'); try { if ($createFilesCopy) { - $unmanagedFilePath = $file_system->copy($uri, $copyUri, FileSystemInterface::EXISTS_REPLACE); + $unmanagedFilePath = $file_system->copy($uri, $copyUri, FileSystemInterface::EXISTS_REPLACE); - $data = file_get_contents($unmanagedFilePath); - $managedFile = file_save_data($data, $unmanagedFilePath, FileSystemInterface::EXISTS_REPLACE); + $data = file_get_contents($unmanagedFilePath); + $managedFile = file_save_data($data, $unmanagedFilePath, FileSystemInterface::EXISTS_REPLACE); } else { $current_user = \Drupal::currentUser(); diff --git a/src/Plugin/migrate_plus/data_parser/SimpleXmlArray.php b/src/Plugin/migrate_plus/data_parser/SimpleXmlArray.php index d5c2105..5d408dc 100644 --- a/src/Plugin/migrate_plus/data_parser/SimpleXmlArray.php +++ b/src/Plugin/migrate_plus/data_parser/SimpleXmlArray.php @@ -2,7 +2,6 @@ namespace Drupal\os2web_meetings\Plugin\migrate_plus\data_parser; -use Drupal\migrate\MigrateException; use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\SimpleXml; use Drupal\os2web_meetings\Form\SettingsForm;