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

Add translatable string context #422

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fef6e99
Add command to update Modules, Themes and Layouts (#290)
TheMetMan Jun 26, 2023
9316f13
Add support for command level short form options (#286)
yorkshire-pudding Jun 26, 2023
d368408
Remove BWPanda as maintainer
yorkshire-pudding Jul 11, 2023
3f0fd47
Merge branch 'backdrop-contrib:1.x-1.x' into 1.x-1.x
yorkshire-pudding Jul 13, 2023
682ef7e
Merge branch '1.x-1.x' of github.com:yorkshire-pudding/bee into 1.x-1.x
yorkshire-pudding Jul 14, 2023
ee096fe
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Jul 14, 2023
98c774b
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Nov 22, 2023
ad751b0
Issue #301: Added an argument to the update command to limit the proj…
hosef Nov 22, 2023
c68c706
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Nov 23, 2023
a04a6f9
Issue #303: Added a check that the latest_release is set on projects.…
hosef Nov 23, 2023
51977a9
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Dec 7, 2023
dfd8683
Issue #300: Add support for downloading only security updates to the …
anemirovsky Dec 9, 2023
b40b256
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Dec 12, 2023
be5c687
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Dec 13, 2023
f7482a7
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Dec 13, 2023
5a214e0
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Dec 13, 2023
ffd8ea3
Issue #350: Add an update-list command (#351)
anemirovsky Dec 18, 2023
9c086bc
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Feb 10, 2024
e7378fb
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Mar 8, 2024
4903ecc
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding May 2, 2024
3d96869
Allow switch bee version in lando with rebuild
yorkshire-pudding May 9, 2024
fcd4349
Merge branch '1.x-1.x' of github.com:backdrop-contrib/bee into 1.x-1.x
yorkshire-pudding May 9, 2024
167ae18
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding May 9, 2024
895f556
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding May 11, 2024
4e2edd4
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding May 23, 2024
f449e4b
Merge branch '1.x-1.x' of github.com:backdrop-contrib/bee into issue-…
yorkshire-pudding May 23, 2024
ae6ffdf
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Jul 4, 2024
ff017db
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Jul 15, 2024
22ea89a
Merge branch '1.x-1.x' into issue-111-update-command
yorkshire-pudding Aug 15, 2024
fcd85eb
Issue #410: Add context to translatable strings passed to t()
yorkshire-pudding Aug 17, 2024
45ac2e6
Update CHANGELOG.md
yorkshire-pudding Aug 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ execute permissions have not been added to the file.
- Changed the version number normally present to be more meaningful and added the latest version number.
- Messages output at the conclusion of the operation are now output as text rather than tables.
- The Wiki is now edited via the `docs` folder of the main repo. Pages can be edited as part of a pull request.
- Added 'context' of 'Bee' to any translatable strings passed to `t()`.

### Fixed
- Unhandled Error if the executables called in the database commands does
Expand Down
178 changes: 177 additions & 1 deletion commands/update.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,54 @@ function update_bee_command() {
'bee update-db' => bt('Show a list of any pending database updates. You will then be prompted to apply them.'),
),
),
'update' => array(
'description' => bt('Updates backdrop, modules, themes and layouts with new releases'),
'callback' => 'update_bee_callback',
'aliases' => array('up', 'pm-update'),
'bootstrap' => BEE_BOOTSTRAP_FULL,
'arguments' => array(
'projects' => bt('One or more projects to update.'),
),
'optional_arguments' => array('projects'),
'multiple_argument' => 'projects',
'options' => array(
'security-only' => array(
'description' => bt('Only update modules that have security updates available.'),
'short' => 's',
),
),
'examples' => array(
'bee update' => bt('Update everything with a new release.'),
'bee update --security-only' => bt('Update everything that is a security update only'),
'bee update webform tatsu' => bt('Updates the Webform module and Tatsu theme only'),
),
),
'update-list' => array(
'description' => bt('Lists available updates for backdrop, modules, themes and layouts with new releases'),
'callback' => 'update_list_bee_callback',
'aliases' => array('ups', 'pm-updatestatus', 'update-status', 'upl'),
'bootstrap' => BEE_BOOTSTRAP_FULL,
'arguments' => array(
'projects' => bt('One or more projects to list updates for.'),
),
'optional_arguments' => array('projects'),
'multiple_argument' => 'projects',
'options' => array(
'security-only' => array(
'description' => bt('Only list updates for modules that have security updates available.'),
'short' => 's',
),
'format' => array(
'description' => bt('Format to output update information in. Options are "table" (default), "list".'),
'value' => bt('table'),
),
),
'examples' => array(
'bee update-list' => bt('List updates for everything with a new release.'),
'bee update-list --security-only' => bt('List only security updates for everything with a new release.'),
'bee update-list webform tatsu' => bt('List updates for the Webform module and Tatsu theme only'),
),
),
);
}

Expand All @@ -40,7 +88,6 @@ function update_db_bee_callback() {
bee_message(bt('There are no pending database updates.'), 'info');
return;
}

// Process the list of updates.
foreach ($pending as $module => $updates) {
if (!isset($updates['start'])) {
Expand Down Expand Up @@ -101,3 +148,132 @@ function update_db_bee_callback() {
bee_message(bt('All pending updates applied.'), 'success');
}
}

/**
* Command callback: Show, and apply, module and theme updates.
*
* @todo Add core update.
* @todo Consider a way to download first, check the download has worked before delete.
*
*/
function update_bee_callback($arguments, $options) {
global $_bee_backdrop_root;
require_once $_bee_backdrop_root . '/core/includes/file.inc';
$data = update_bee_get_available_updates($arguments, $options);
if ($data != NULL) {
update_bee_render_table_output($data);
// Prompt to continue.
if (!bee_confirm(bt('Would you like to continue?'), FALSE)) {
return;
}
foreach ($data as $item) {
$folder = backdrop_get_path($item['project_type'], $item['name']);
if (is_dir($folder)) {
bee_delete($folder);
}
download_bee_callback(array('projects' => array($item['name']),), []);
echo '';
}
} else {
bee_message(bt('No Modules or Themes to Update'));
}
}

/**
* Command callback: Show module and theme updates.
*/
function update_list_bee_callback(array $arguments, array $options) {
$data = update_bee_get_available_updates($arguments, $options);
$is_list_format = isset($options['format']) && $options['format'] === 'list';
if ($data == NULL) {
if (!$is_list_format) {
bee_message(bt('No Modules or Themes to Update'));
}
return;
}
if ($is_list_format) {
update_bee_render_list_output($data);
} else {
update_bee_render_table_output($data);
}
}

/**
* Get an array of available project updates.
*
* @param array $arguments
* A list of arguments passed to the command.
* @param array $options
* A list of options passed to the command.
*
* @return array|NULL
* An array of projects with updates available, or NULL if there are none.
*/
function update_bee_get_available_updates(array $arguments, array $options) {
$data = NULL;
if ($available = update_get_available(TRUE)) {
module_load_include('inc', 'update', 'update.compare');
$data = update_calculate_project_data($available);
}
if ($data != NULL) {
foreach ($data as $item) {
if ($item['name'] == 'backdrop') {
unset($data['backdrop']);
continue;
}
if (!empty($arguments['projects']) && !in_array($item['name'], $arguments['projects'])) {
unset($data[$item['name']]);
continue;
}
if (!isset($item['latest_version'])) {
unset($data[$item['name']]);
continue;
}
if ($item['existing_version'] == $item['latest_version']) {
unset($data[$item['name']]);
continue;
}
if (isset($options['security-only']) && $item['status'] !== UPDATE_NOT_SECURE) {
unset($data[$item['name']]);
}
}
}
return $data;
}

/**
* Render available updates as a table.
*
* @param array $data
* An array of projects with updates available.
*/
function update_bee_render_table_output(array $data) {
foreach ($data as $item) {
$rows[] = array(
array('value' => $item['name']),
array('value' => $item['existing_version']),
array('value' => $item['latest_version']),
);
}
bee_render_text(array('value' => bt("These are the items being updated:\n")));
bee_render_table(array(
'rows' => $rows,
'header' => array(
array('value' => bt('Module')),
array('value' => bt('Existing')),
array('value' => bt('Latest')),
),
));
}

/**
* Render available updates as a list.
*
* @param array $data
* An array of projects with updates available.
*/
function update_bee_render_list_output(array $data) {
foreach ($data as $item) {
bee_render_text(array('value' => $item['name']));
}
}
5 changes: 4 additions & 1 deletion includes/miscellaneous.inc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ function bee_message($message, $type = 'info') {
*/
function bt($string, array $args = array()) {
if (function_exists('t')) {
return t($string, $args);
$options = array(
'context' => 'Bee',
);
return t($string, $args, $options);
}
else {
if (!empty($args)) {
Expand Down
Loading