function main() { // Start the page global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log, $cache; $this->db = $db; $this->config = $config; $this->template = $template; $this->user = $user; $this->cache = $cache; $this->request = $request; $this->log = $phpbb_log; $user->add_lang(array('install', 'acp/extensions', 'migrator')); $this->page_title = 'ACP_EXTENSIONS'; $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = ini_get('max_execution_time') / 2; $start_time = time(); // Cancel action if ($request->is_set_post('cancel')) { $action = 'list'; $ext_name = ''; } if (in_array($action, array('enable', 'disable', 'delete_data')) && !check_link_hash($request->variable('hash', ''), $action . '.' . $ext_name)) { trigger_error('FORM_INVALID', E_USER_WARNING); } // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path); try { $md_manager->get_metadata('all'); } catch (\phpbb\extension\exception $e) { trigger_error($e, E_USER_WARNING); } } // What are we doing? switch ($action) { case 'set_config_version_check_force_unstable': $force_unstable = $this->request->variable('force_unstable', false); if ($force_unstable) { $s_hidden_fields = build_hidden_fields(array('force_unstable' => $force_unstable)); confirm_box(false, $user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields); } else { $config->set('extension_force_unstable', false); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } break; case 'list': default: if (confirm_box(true)) { $config->set('extension_force_unstable', true); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $this->list_enabled_exts($phpbb_extension_manager); $this->list_disabled_exts($phpbb_extension_manager); $this->list_available_exts($phpbb_extension_manager); $this->template->assign_vars(array('U_VERSIONCHECK_FORCE' => $this->u_action . '&action=list&versioncheck_force=1', 'FORCE_UNSTABLE' => $config['extension_force_unstable'], 'U_ACTION' => $this->u_action)); add_form_key('version_check_settings'); $this->tpl_name = 'acp_ext_list'; break; case 'enable_pre': if (!$md_manager->validate_dir()) { trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$md_manager->validate_enable()) { trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } $extension = $phpbb_extension_manager->get_extension($ext_name); if (!$extension->is_enableable()) { trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } $this->tpl_name = 'acp_ext_enable'; $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')), 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name))); break; case 'enable': if (!$md_manager->validate_dir()) { trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$md_manager->validate_enable()) { trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } $extension = $phpbb_extension_manager->get_extension($ext_name); if (!$extension->is_enableable()) { trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } try { while ($phpbb_extension_manager->enable_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name)); } } $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name)); } catch (\phpbb\db\migration\exception $e) { $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_enable'; $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list')); break; case 'disable_pre': if (!$phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } $this->tpl_name = 'acp_ext_disable'; $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')), 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name))); break; case 'disable': if (!$phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } while ($phpbb_extension_manager->disable_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name)); } } $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name)); $this->tpl_name = 'acp_ext_disable'; $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list')); break; case 'delete_data_pre': if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } $this->tpl_name = 'acp_ext_delete_data'; $template->assign_vars(array('PRE' => true, 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')), 'U_PURGE' => $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name))); break; case 'delete_data': if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } try { while ($phpbb_extension_manager->purge_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name)); } } $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_PURGE', time(), array($ext_name)); } catch (\phpbb\db\migration\exception $e) { $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_delete_data'; $template->assign_vars(array('U_RETURN' => $this->u_action . '&action=list')); break; case 'details': // Output it to the template $md_manager->output_template_data(); try { $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false)); $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')))); foreach ($updates_available as $branch => $version_data) { $template->assign_block_vars('updates_available', $version_data); } } catch (\RuntimeException $e) { $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : '')); } $template->assign_vars(array('U_BACK' => $this->u_action . '&action=list', 'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')))); $this->tpl_name = 'acp_ext_details'; break; } }
function main() { // Start the page global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log, $cache; $this->db = $db; $this->config = $config; $this->template = $template; $this->user = $user; $this->cache = $cache; $this->request = $request; $this->log = $phpbb_log; $user->add_lang(array('install', 'acp/extensions', 'migrator')); $user->add_lang_ext('lavigor/reenable', 'reenable'); $this->page_title = 'ACP_REENABLE'; $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = ini_get('max_execution_time') / 2; $start_time = time(); // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path); try { $md_manager->get_metadata('all'); } catch (\phpbb\extension\exception $e) { trigger_error($e, E_USER_WARNING); } } // What are we doing? switch ($action) { case 'list': default: $this->list_enabled_exts($phpbb_extension_manager, $ext_name); $this->template->assign_vars(array('U_VERSIONCHECK_FORCE' => $this->u_action . '&action=list&versioncheck_force=1', 'FORCE_UNSTABLE' => $config['extension_force_unstable'], 'U_ACTION' => $this->u_action)); $this->tpl_name = 'acp_ext_reenable'; break; case 'reenable': case 'reinstall': if (!$phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); } // We do not want too many logs for reinstallation $this->log->disable('admin'); while ($phpbb_extension_manager->disable_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=' . $action . '&ext_name=' . urlencode($ext_name)); } } if ($action == 'reinstall') { try { while ($phpbb_extension_manager->purge_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=' . $action . '&ext_name=' . urlencode($ext_name)); } } } catch (\phpbb\db\migration\exception $e) { $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } } if (!$md_manager->validate_dir()) { trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$md_manager->validate_enable()) { trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } try { while ($phpbb_extension_manager->enable_step($ext_name)) { // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if (time() - $start_time >= $safe_time_limit) { $template->assign_var('S_NEXT_STEP', true); meta_refresh(0, $this->u_action . '&action=' . $action . '&ext_name=' . urlencode($ext_name)); } } } catch (\phpbb\db\migration\exception $e) { $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->log->enable('admin'); if ($action == 'reinstall') { $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_REINSTALL', time(), array($ext_name)); } else { $this->log->add('admin', $user->data['user_id'], $user->ip, 'LOG_EXT_REENABLE', time(), array($ext_name)); } redirect($this->u_action . '&action=list&ext_name=' . urlencode($ext_name)); break; } }