Skip to content

Commit

Permalink
Migrate from the general "default_to_private" setting to granular set…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
jimsafley committed Jun 14, 2024
1 parent e0a284a commit 410097a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
2 changes: 1 addition & 1 deletion application/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Module extends AbstractModule
/**
* This Omeka version.
*/
const VERSION = '4.2.0-alpha';
const VERSION = '4.2.0-alpha.1';

/**
* The vocabulary IRI used to define Omeka application data.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Omeka\Db\Migrations;

use Doctrine\DBAL\Connection;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Omeka\Db\Migration\ConstructedMigrationInterface;

class MigrateDefaultToPrivateSetting implements ConstructedMigrationInterface
{
private $settings;

public static function create(ServiceLocatorInterface $services)
{
return new self($services->get('Omeka\Settings'));
}

public function __construct($settings)
{
$this->settings = $settings;
}

public function up(Connection $conn)
{
// Migrate from the general "default_to_private" setting to granular settings.
$defaultToPrivate = (bool) $this->settings->get('default_to_private', false);
$this->settings->set('default_to_private_items', $defaultToPrivate);
$this->settings->set('default_to_private_item_sets', $defaultToPrivate);
$this->settings->set('default_to_private_sites', $defaultToPrivate);
$this->settings->set('default_to_private_site_pages', $defaultToPrivate);
$this->settings->delete('default_to_private');
}
}
45 changes: 32 additions & 13 deletions application/src/Form/SettingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,38 @@ public function init()

// Editing element group

$this->add([
'name' => 'default_to_private',
'type' => 'Checkbox',
'options' => [
'element_group' => 'editing',
'label' => 'Default content visibility to Private', // @translate
'info' => 'If checked, all items, item sets and sites newly created will have their visibility set to private by default.', // @translate
],
'attributes' => [
'value' => $this->settings->get('default_to_private'),
'id' => 'default_to_private',
],
]);
$defaultToPrivateElements = [
[
'name' => 'default_to_private_items',
'label' => 'Set default item visibility to private', // @translate
],
[
'name' => 'default_to_private_item_sets',
'label' => 'Set default item set visibility to private', // @translate
],
[
'name' => 'default_to_private_sites',
'label' => 'Set default site visibility to private', // @translate
],
[
'name' => 'default_to_private_site_pages',
'label' => 'Set default site page visibility to private', // @translate
],
];
foreach ($defaultToPrivateElements as $defaultToPrivateElement) {
$this->add([
'type' => 'checkbox',
'name' => $defaultToPrivateElement['name'],
'options' => [
'element_group' => 'editing',
'label' => $defaultToPrivateElement['label'],
],
'attributes' => [
'id' => $defaultToPrivateElement['name'],
'value' => $this->settings->get($defaultToPrivateElement['name'], false),
]
]);
}

$this->add([
'name' => 'value_languages',
Expand Down
2 changes: 1 addition & 1 deletion application/view/omeka/admin/item-set/form.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $form->prepare();
<input type="hidden" name="o:is_open" value="0">
<?php endif; ?>

<?php if ($itemSet && $itemSet->isPublic() || (!isset($itemSet) && !$this->setting('default_to_private')) ): ?>
<?php if ($itemSet && $itemSet->isPublic() || (!isset($itemSet) && !$this->setting('default_to_private_item_sets')) ): ?>
<?php echo $this->hyperlink('', '#', [
'class' => 'o-icon-public button',
'title' => $translate('Make private'),
Expand Down
2 changes: 1 addition & 1 deletion application/view/omeka/admin/item/form.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $form->prepare();
</fieldset>

<div id="page-actions">
<?php if ($item && $item->isPublic() || (!isset($item)) && !$this->setting('default_to_private')) : ?>
<?php if ($item && $item->isPublic() || (!isset($item)) && !$this->setting('default_to_private_items')) : ?>
<?php echo $this->hyperlink('', '#', [
'class' => 'o-icon-public button',
'title' => $translate('Make private'),
Expand Down
2 changes: 1 addition & 1 deletion application/view/omeka/site-admin/index/add-page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $form->prepare();
<?php echo $this->pageTitle($translate('New page'), 1, $translate('Pages')); ?>
<?php echo $this->form()->openTag($form); ?>
<div id="page-actions">
<?php if ($this->setting('default_to_private')) : ?>
<?php if ($this->setting('default_to_private_site_pages')) : ?>
<?php echo $this->hyperlink('', '#', [
'class' => 'o-icon-private button',
'title' => $translate('Make public'),
Expand Down
2 changes: 1 addition & 1 deletion application/view/omeka/site-admin/index/add.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $fallbackThumbnailUrl = $this->assetUrl('img/theme.jpg', 'Omeka');
<?php echo $this->form()->openTag($form); ?>

<div id="page-actions">
<?php if ($this->setting('default_to_private')) : ?>
<?php if ($this->setting('default_to_private_sites')) : ?>
<?php echo $this->hyperlink('', '#', [
'class' => 'o-icon-private button',
'title' => $translate('Make public'),
Expand Down

0 comments on commit 410097a

Please sign in to comment.