Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions config/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ services:
- [set_tool, ["@phpbb.titania.manage.tool.composer.rebuild_repo"]]
parent: phpbb.titania.controller.manage.tool

phpbb.titania.controller.manage.demo.install_all:
class: phpbb\titania\controller\manage\tool\demo\install_all
calls:
- [set_tool, ["@phpbb.titania.manage.tool.demo.install_all"]]
parent: phpbb.titania.controller.manage.tool

phpbb.titania.controller.manage.search.reindex:
shared: false
calls:
Expand Down
4 changes: 4 additions & 0 deletions config/routes/manage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ phpbb.titania.manage.contrib.update_release_topics:
path: /administration/contrib/update_release_topics
defaults: { _controller: phpbb.titania.controller.manage.contrib.update_release_topics:handle }

phpbb.titania.manage.demo.install_all:
path: /administration/demo/install_all
defaults: { _controller: phpbb.titania.controller.manage.demo.install_all:handle }

phpbb.titania.manage.search.reindex:
path: /administration/search/reindex
defaults: { _controller: phpbb.titania.controller.manage.search.reindex:handle }
Expand Down
8 changes: 8 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ services:
- '%tables.topics%'
- '%tables.users%'

phpbb.titania.manage.tool.demo.install_all:
class: phpbb\titania\manage\tool\demo\install_all
arguments:
- '@dbal.conn'
- '@user'
- '@phpbb.titania.config'
- '@phpbb.titania.style.demo.manager'

phpbb.titania.manage.tool.search.reindex:
class: phpbb\titania\manage\tool\search\reindex
shared: false
Expand Down
65 changes: 62 additions & 3 deletions contribution/style/demo/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class manager
/** @var \titania_contribution */
protected $contrib;

/** @var array|null Map of style_path to style_active on the demo board */
protected $installed_styles;

/**
* Constructor.
*
Expand Down Expand Up @@ -76,10 +79,24 @@ public function __construct(\phpbb\user $user, $container, $ext_config, $php_ext
*/
public function configure($branch, $contrib, $package)
{
$this->branch = $branch;
$this->contrib = $contrib;
$this->package = $package;

return $this->set_branch($branch);
}

/**
* Set the branch and connect to its demo board.
*
* @param int $branch
*
* @return bool Returns false if no usable demo board is configured for the branch.
*/
public function set_branch($branch)
{
$this->branch = $branch;
$this->installed_styles = null;

if (empty($this->ext_config->demo_style_path[$this->branch]))
{
return false;
Expand All @@ -99,6 +116,36 @@ public function configure($branch, $contrib, $package)
return $this->db_connect();
}

/**
* Check whether a style is present and active on the demo board.
*
* The board's styles table and the style directory are both checked, so a
* wiped database or a wiped filesystem each count as not installed.
*
* @param string $dir_name Style directory name, as built by get_style_dir_name().
*
* @return bool
*/
public function is_style_installed($dir_name)
{
if ($this->installed_styles === null)
{
$this->installed_styles = array();

$sql = 'SELECT style_path, style_active
FROM ' . $this->table_prefix . 'styles';
$result = $this->db->sql_query($sql);

while ($row = $this->db->sql_fetchrow($result))
{
$this->installed_styles[$row['style_path']] = (bool) $row['style_active'];
}
$this->db->sql_freeresult($result);
}

return !empty($this->installed_styles[$dir_name]) && is_dir($this->board_root_path . 'styles/' . $dir_name . '/');
}

/**
* Get result.
*
Expand Down Expand Up @@ -265,16 +312,28 @@ protected function db_connect()
return true;
}

/**
* Build the style directory name used on the demo board.
*
* @param string $contrib_name_clean
* @param int $contrib_id
* @return string
*/
public function get_style_dir_name($contrib_name_clean, $contrib_id)
{
return $contrib_name_clean . '_' . $contrib_id;
}

/**
* Get style directory name.
*
* @param bool $name_only If false, returns the full path to the directory,
* otherwise just the name.
* @retun string
* @return string
*/
public function get_style_dir($name_only = false)
{
$dir_name = $this->contrib->contrib_name_clean . '_' . $this->contrib->contrib_id;
$dir_name = $this->get_style_dir_name($this->contrib->contrib_name_clean, $this->contrib->contrib_id);

if ($name_only)
{
Expand Down
35 changes: 33 additions & 2 deletions controller/manage/administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,25 @@ public function list_tools()
),
);

foreach ($this->ext_config->demo_style_path as $branch => $path)
{
if (empty($path))
{
continue;
}
$tools['INSTALL_DEMO_STYLES_' . $branch] = array(
'route' => 'phpbb.titania.manage.demo.install_all',
'params' => array('branch' => $branch),
'title' => $this->user->lang('INSTALL_DEMO_STYLES', $this->get_branch_name($branch)),
'ajax' => true,
);
}

foreach ($tools as $title => $info)
{
$this->template->assign_block_vars('tools', array(
'L_TITLE' => $this->user->lang($title),
'U_TITLE' => $this->helper->route($info['route']),
'L_TITLE' => isset($info['title']) ? $info['title'] : $this->user->lang($title),
'U_TITLE' => $this->helper->route($info['route'], isset($info['params']) ? $info['params'] : array()),
'S_AJAX' => $info['ajax'],
));
}
Expand All @@ -78,6 +92,23 @@ public function list_tools()
return $this->helper->render('manage/administration.html', 'ADMINISTRATION');
}

/**
* Get the display name of a phpBB branch.
*
* @param int $branch Branch in the form of 33 for 3.3.
* @return string Returns the configured branch name, like phpBB 3.3.x.
*/
protected function get_branch_name($branch)
{
$versions = $this->ext_config->phpbb_versions;

if (isset($versions[$branch]['name']))
{
return $versions[$branch]['name'];
}
return 'phpBB ' . implode('.', str_split((string) $branch));
}

/**
* Check user's authorization.
*
Expand Down
84 changes: 84 additions & 0 deletions controller/manage/tool/demo/install_all.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb\titania\controller\manage\tool\demo;

use phpbb\exception\http_exception;
use phpbb\titania\controller\manage\tool\tool;

class install_all extends tool
{
/**
* {@inheritDoc}
*
* Tells the user how many styles are missing from the demo board before
* asking for confirmation.
*
* @throws http_exception If the branch has no usable demo board.
*/
protected function confirm_action()
{
$submit = $this->request->is_set('submit');
$hash = $this->request->variable('hash', '');

if (confirm_box(true) || ($submit && check_link_hash($hash, 'titania_manage')))
{
return true;
}
$pending = $this->tool
->set_branch($this->request->variable('branch', 0))
->count_pending();

if ($pending === false)
{
throw new http_exception(200, 'INSTALL_DEMO_STYLES_NOT_CONFIGURED');
}
confirm_box(false, $this->user->lang('INSTALL_DEMO_STYLES_CONFIRM', $pending));

return false;
}

/**
* {@inheritDoc}
*/
protected function get_next_params(array $result)
{
return array_merge(
parent::get_next_params($result),
array(
'branch' => $result['branch'],
'installed' => $result['installed'],
'already' => $result['already'],
'skipped' => $result['skipped'],
'failed' => $result['failed'],
)
);
}

/**
* {@inheritDoc}
*/
protected function run()
{
return $this->tool
->set_branch($this->request->variable('branch', 0))
->set_start($this->request->variable('start', 0))
->run(
$this->request->variable('installed', 0),
$this->request->variable('already', 0),
$this->request->variable('skipped', 0),
$this->request->variable('failed', 0)
)
;
}
}
6 changes: 6 additions & 0 deletions language/en/manage_tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'SECTION_STATUS' => 'part %d of %d',
'TRUNCATING_SEARCH' => 'Truncating Search',

'INSTALL_DEMO_STYLES' => 'Install all approved styles on the %s demo board',
'INSTALL_DEMO_STYLES_COMPLETE' => 'Styles installed on the demo board: %1$d. Already installed and skipped: %2$d. Skipped with no package for this branch: %3$d. Failed to install: %4$d.',
'INSTALL_DEMO_STYLES_CONFIRM' => '%d approved styles are not installed on this demo board. Are you sure you want to run this tool?',
'INSTALL_DEMO_STYLES_NOT_CONFIGURED' => 'No style demo board is configured for this branch.',
'INSTALL_DEMO_STYLES_PROGRESS' => '%1$d styles completed of %2$d. Please wait…',

'PLEASE_WAIT' => 'Please wait...',

'REBUILD_COMPOSER_REPO' => 'Rebuild Composer repository',
Expand Down
Loading