Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hook update to fix exstsing file entities #3

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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\}\},'
Original file line number Diff line number Diff line change
@@ -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 = '<span class="file file--mime-application-pdf file--application-pdf">' . $pdfLink . '</span>';

// $output = '<ul class="related-links">';
//
// /** @var \Drupal\node\NodeInterface $node */
// foreach ($related_nodes as $node) {
// $output .= '<li>';
// $output .= $node->toLink()->toString();
// $output .= '</li>';
// }
// $output .= '</ul>';

return $output;
}

Original file line number Diff line number Diff line change
@@ -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 <a href=":url">' . $urlText . '</a>', [
$markup = Markup::create(t('Søg i <a href=":url">@text</a>', [
':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;
52 changes: 52 additions & 0 deletions os2web_meetings.install
Original file line number Diff line number Diff line change
@@ -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
));
}
1 change: 0 additions & 1 deletion src/Entity/BulletPointAttachment.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

namespace Drupal\os2web_meetings\Entity;

use Drupal\decreto_content_modify\Entity\DecretoBulletPoint;
use Drupal\node\Entity\Node;

/**
5 changes: 2 additions & 3 deletions src/EventSubscriber/MeetingContentRedirectSubscriber.php
Original file line number Diff line number Diff line change
@@ -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();
}
4 changes: 2 additions & 2 deletions src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 6 additions & 5 deletions src/MeetingsDirectoryInterface.php
Original file line number Diff line number Diff line change
@@ -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);

}
24 changes: 11 additions & 13 deletions src/Plugin/migrate/source/MeetingsDirectory.php
Original file line number Diff line number Diff line change
@@ -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();
1 change: 0 additions & 1 deletion src/Plugin/migrate_plus/data_parser/SimpleXmlArray.php
Original file line number Diff line number Diff line change
@@ -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;