Skip to content

Commit

Permalink
NBNP-448 Further structure changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSanford committed Jun 8, 2024
1 parent 681ecb8 commit 7b872d9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ public function getParentTitle() {
return $this->get('parent_title')->entity;
}

/**
* {@inheritdoc}
*/
public function getParentTitleId() {
return $this->get('parent_title')->entity->id();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -641,9 +648,10 @@ public function createStoragePath() {
* {@inheritDoc}
*/
public function getStorageUri() {
$title_id = $this->getParentTitleId();
$default_file_scheme = \Drupal::config('system.file')->get('default_scheme');
$issue_id = $this->id();
return "$default_file_scheme://serials/pages/$issue_id";
return "$default_file_scheme://serials/pages/$title_id/$issue_id";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@ public function getParentIssue() {
return $this->get('parent_issue')->entity;
}

/**
* {@inheritdoc}
*/
public function getParentIssueId() {
return $this->get('parent_issue')->entity->id();
}

/**
* {@inheritdoc}
*/
public function getParentTitle() {
$issue = $this->getParentIssue();
return $issue->get('parent_title')->entity;
}

/**
* {@inheritdoc}
*/
public function getParentTitleId() {
$issue = $this->getParentIssue();
return $issue->get('parent_title')->entity->id();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -518,13 +541,13 @@ public function deletePdfFile() {
* {@inheritDoc}
*/
public function getPdfUri() {
$issue = $this->getParentIssue();
$issue_id = $issue->id();
$issue_id = $this->getParentIssueId();
$title_id = $this->getParentTitleId();
$file = $this->getPageImage();
$pdf_filename = str_replace('.jpg', '.pdf', $file->getFilename());
$pdf_uri_schemas = [
"base://serials/pages/$issue_id/$pdf_filename",
"base://serials/pages/pdf/$issue_id/$pdf_filename"
"base://serials/pages/$title_id/$issue_id/$pdf_filename",
"base://serials/pages/pdf/$issue_id/$pdf_filename",
];

foreach ($pdf_uri_schemas as $pdf_uri_schema) {
Expand All @@ -540,13 +563,13 @@ public function getPdfUri() {
* {@inheritDoc}
*/
public function getPdfPath() {
$issue = $this->getParentIssue();
$issue_id = $issue->id();
$issue_id = $this->getParentIssueId();
$title_id = $this->getParentTitleId();
$file = $this->getPageImage();
$pdf_filename = str_replace('.jpg', '.pdf', $file->getFilename());
$pdf_file_schemas = [
"/app/html/sites/default/files/serials/pages/$title_id/$issue_id/$pdf_filename",
"/app/html/sites/default/files/serials/pages/pdf/$issue_id/$pdf_filename",
"/app/html/sites/default/files/serials/pages/$issue_id/$pdf_filename"
];

foreach ($pdf_file_schemas as $pdf_file_schema) {
Expand All @@ -561,13 +584,13 @@ public function getPdfPath() {
* {@inheritDoc}
*/
public function getDziUri() {
$issue = $this->getParentIssue();
$issue_id = $issue->id();
$issue_id = $this->getParentIssueId();
$title_id = $this->getParentTitleId();
$file = $this->getPageImage();
$dzi_filename = str_replace('.jpg', '.dzi', $file->getFilename());
$dzi_uri_schemas = [
"base://serials/pages/$issue_id/$dzi_filename",
"base://serials/pages/$dzi_filename"
"base://serials/pages/$title_id/$issue_id/$dzi_filename",
"base://serials/pages/$dzi_filename",
];

foreach ($dzi_uri_schemas as $dzi_uri_schema) {
Expand All @@ -583,13 +606,13 @@ public function getDziUri() {
* {@inheritDoc}
*/
public function getDziPath() {
$issue = $this->getParentIssue();
$issue_id = $issue->id();
$issue_id = $this->getParentIssueId();
$title_id = $this->getParentTitleId();
$file = $this->getPageImage();
$dzi_filename = str_replace('.jpg', '.dzi', $file->getFilename());
$dzi_file_schemas = [
"/app/html/sites/default/files/serials/pages/$issue_id/$dzi_filename",
"/app/html/sites/default/files/serials/pages/$dzi_filename"
"/app/html/sites/default/files/serials/pages/$title_id/$issue_id/$dzi_filename",
"/app/html/sites/default/files/serials/pages/$dzi_filename",
];

foreach ($dzi_file_schemas as $dzi_file_schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public static function bulkCreateNewStoragePaths() {
$count = count($issue_ids);
$progress = 0;
foreach ($issue_ids as $issue_id) {
$issue = \Drupal::entityTypeManager()
->getStorage('digital_serial_issue')
->load($issue_id);
$title_id = $issue->getParentTitleId();
$progress += 1;
echo "Creating issue $progress/$count...\n";
$issue_absolute_path = "/app/html/sites/default/files/serials/pages/$issue_id";
$issue_absolute_path = "/app/html/sites/default/files/serials/pages/$title_id/$issue_id";
if (!file_exists($issue_absolute_path)) {
mkdir($issue_absolute_path, 0755, TRUE);
}
Expand Down Expand Up @@ -90,11 +94,12 @@ public static function moveIssuePages($issue) {
public static function moveDziTileLocation($page, $issue) {
$file = $page->getPageImage();
$issue_id = $issue->id();
$title_id = $issue->getParentTitleId();
$image_file_name = $file->getFilename();
$file_name = str_replace('.jpg', '.dzi', $image_file_name);

$old_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$file_name";
$new_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$issue_id/$file_name";
$new_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$title_id/$issue_id/$file_name";
$old_dzi_file = str_replace('.jpg', '.dzi', $old_page_absolute_file_location);
$old_dzi_asset_path = str_replace('.jpg', '_files', $old_page_absolute_file_location);
$new_dzi_file = str_replace('.jpg', '.dzi', $new_page_absolute_file_location);
Expand All @@ -120,9 +125,10 @@ public static function moveDziTileLocation($page, $issue) {
public static function movePdfFileLocation($page, $issue) {
$file = $page->getPageImage();
$issue_id = $issue->id();
$title_id = $issue->getParentTitleId();
$file_name = $file->getFilename();
$old_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$file_name";
$new_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$issue_id/$file_name";
$new_page_absolute_file_location = "/app/html/sites/default/files/serials/pages/$title_id/$issue_id/$file_name";

$old_pdf_file_path = str_replace(
'/pages/',
Expand Down

0 comments on commit 7b872d9

Please sign in to comment.