Merge branch 'feature-items-per-page'
This commit is contained in:
commit
5d3d64ebd4
31
README.md
31
README.md
|
@ -1,7 +1,7 @@
|
|||
PHP Censor
|
||||
----------
|
||||
|
||||
PHP Censor is a fork of PHPCI (And B8Framework). PHP Censor is a free and open source (BSD-2-Clause license) continuous
|
||||
PHP Censor is a fork of PHPCI (And B8Framework) and is a free and open source (BSD-2-Clause license) continuous
|
||||
integration tool specifically designed for PHP. We've built it with simplicity in mind, so whilst it doesn't
|
||||
do *everything* Jenkins can do, it is a breeze to set up and use.
|
||||
|
||||
|
@ -23,11 +23,6 @@ What it doesn't do (yet)
|
|||
* Install PEAR or PECL extensions.
|
||||
* Deployments
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
[PHP Censor documentation](docs/README.md)
|
||||
|
||||
Tests
|
||||
=====
|
||||
|
||||
|
@ -40,7 +35,29 @@ For Phar plugin tests set 'phar.readonly' setting to Off (0) in `php.ini` config
|
|||
|
||||
For database B8Framework tests create empty 'b8_test' MySQL database on 'localhost' with user/password: `root/root`.
|
||||
|
||||
Migrations
|
||||
==========
|
||||
|
||||
Run to apply latest migrations:
|
||||
|
||||
```bash
|
||||
cd /path/to/php-censor
|
||||
./bin/console php-censor-migrations:migrate
|
||||
```
|
||||
|
||||
Run to create new migration:
|
||||
|
||||
```bash
|
||||
cd /path/to/php-censor
|
||||
./bin/console php-censor-migrations:create NewMigrationName
|
||||
```
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
[PHP Censor documentation](docs/README.md)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
The PHP Censor is open source software licensed under the BSD-2-Clause license.
|
||||
PHP Censor is open source software licensed under the BSD-2-Clause license.
|
||||
|
|
|
@ -8,7 +8,9 @@ b8:
|
|||
username: php-censor-user
|
||||
password: php-censor-password
|
||||
php-censor:
|
||||
url: 'http://php-censor.local'
|
||||
language: en
|
||||
per_page: 10
|
||||
url: 'http://php-censor.local'
|
||||
worker:
|
||||
host: localhost
|
||||
queue: php-censor-queue
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . '/bootstrap.php');
|
||||
|
||||
$writeServers = $config->get('b8.database.servers.write');
|
||||
|
||||
if (!is_array($writeServers)) {
|
||||
$writeServers = [$writeServers];
|
||||
}
|
||||
|
||||
$conf = [
|
||||
'paths' => [
|
||||
'migrations' => 'src/PHPCensor/Migrations',
|
||||
],
|
||||
'environments' => [
|
||||
'default_migration_table' => 'migration',
|
||||
'default_database' => 'php-censor',
|
||||
'php-censor' => [
|
||||
'adapter' => 'mysql',
|
||||
'host' => end($writeServers),
|
||||
'name' => $config->get('b8.database.name'),
|
||||
'user' => $config->get('b8.database.username'),
|
||||
'pass' => $config->get('b8.database.password'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $conf;
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
use PHPCensor\Command\RunCommand;
|
||||
use PHPCensor\Command\RebuildCommand;
|
||||
use PHPCensor\Command\UpdateCommand;
|
||||
use PHPCensor\Command\InstallCommand;
|
||||
use PHPCensor\Command\DaemonCommand;
|
||||
use PHPCensor\Command\PollCommand;
|
||||
|
@ -20,8 +19,8 @@ use PHPCensor\Command\CreateBuildCommand;
|
|||
use PHPCensor\Command\WorkerCommand;
|
||||
use PHPCensor\Command\RebuildQueueCommand;
|
||||
use PHPCensor\Service\BuildService;
|
||||
use Symfony\Component\Console\Application;
|
||||
use b8\Store\Factory;
|
||||
use PHPCensor\Console\Application;
|
||||
|
||||
define('IS_CONSOLE', true);
|
||||
|
||||
|
@ -32,7 +31,6 @@ $application = new Application();
|
|||
$application->add(new RunCommand($loggerConfig->getFor('RunCommand')));
|
||||
$application->add(new RebuildCommand($loggerConfig->getFor('RunCommand')));
|
||||
$application->add(new InstallCommand);
|
||||
$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand')));
|
||||
$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand')));
|
||||
$application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
|
||||
$application->add(new CreateAdminCommand(Factory::getStore('User')));
|
||||
|
|
|
@ -19,7 +19,7 @@ Installing PHP Censor from Composer
|
|||
* Download Composer if you haven't already: `curl -sS https://getcomposer.org/installer | php`
|
||||
* Download PHP Censor: `./composer.phar create-project corpsee/php-censor php-censor --keep-vcs --no-dev`
|
||||
* Go to the newly created PHP Censor directory, and install Composer dependencies: `cd php-censor && ../composer.phar install`
|
||||
* Run the PHP Censor installer: `./console php-censor:install`
|
||||
* Run the PHP Censor installer: `./bin/console php-censor:install`
|
||||
* [Add a virtual host to your web server](virtual_host.md), pointing to the `public` directory within your new PHP Censor directory. You'll need to set up rewrite rules to point all non-existent requests to PHP Censor.
|
||||
* [Set up the PHP Censor Worker](workers/worker.md), or you can run builds using the [daemon](workers/daemon.md) or [a cron-job](workers/cron.md) to run PHP Censor builds.
|
||||
|
||||
|
@ -30,6 +30,6 @@ Installing PHP Censor Manually
|
|||
* [Download PHP Censor](https://github.com/corpsee/php-censor/releases/latest) and unzip it.
|
||||
* Go to the PHP Censor directory: `cd /var/www/php-censor`
|
||||
* Install dependencies using Composer: `composer install`
|
||||
* Install PHP Censor itself: `./console php-censor:install`
|
||||
* Install PHP Censor itself: `./bin/console php-censor:install`
|
||||
* [Add a virtual host to your web server](virtual_host.md), pointing to the `public` directory within your new PHP Censor directory. You'll need to set up rewrite rules to point all non-existent requests to PHP Censor.
|
||||
* [Set up the PHP Censor Worker](workers/worker.md), or you can run builds using the [daemon](workers/daemon.md) or [a cron-job](workers/cron.md) to run PHP Censor builds.
|
||||
|
|
|
@ -5,7 +5,7 @@ Updating PHP Censor to the latest release, or even dev-master updates is somethi
|
|||
|
||||
1. Go to your PHP Censor root folder in a Terminal.
|
||||
2. Pull the latest code. This would look like this: `git pull`
|
||||
3. Update the PHP Censor database: `./console php-censor:update`
|
||||
3. Update the PHP Censor database: `./bin/console php-censor-migrations:migrate`
|
||||
4. Update the composer and its packages: `composer self-update && composer update`
|
||||
5. Return to the PHP Censor admin screens and check your desired plugins are still installed correctly.
|
||||
7. Run a build to make sure everything is working as expected.
|
||||
|
|
|
@ -11,7 +11,7 @@ Setting up the Cron Job
|
|||
You'll want to set up PHP Censor to run as a regular cronjob, so run `crontab -e` and enter the following:
|
||||
|
||||
```sh
|
||||
* * * * * /usr/bin/php /path/to/php-censor/console php-censor:run-builds
|
||||
* * * * * /usr/bin/php /path/to/php-censor/bin/console php-censor:run-builds
|
||||
```
|
||||
|
||||
**Note:** Make sure you change the `/path/to/php-censor` to the directory in which you installed PHP Censor, and update the PHP path if necessary.
|
||||
|
|
|
@ -37,7 +37,7 @@ Using your preferred text editor, create a file named `php-censor.conf` under `/
|
|||
|
||||
```
|
||||
[program:php-censor]
|
||||
command=/path/to/php-censor/latest/console php-censor:worker
|
||||
command=/path/to/php-censor/bin/console php-censor:worker
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
stdout_logfile=/var/log/php-censor.log
|
||||
stderr_logfile=/var/log/php-censor-err.log
|
||||
|
|
|
@ -45,7 +45,7 @@ var PHPCensor = {
|
|||
|
||||
getProjectBuilds: function () {
|
||||
$.ajax({
|
||||
url: APP_URL + 'project/builds/' + PROJECT_ID + '?branch=' + PROJECT_BRANCH,
|
||||
url: APP_URL + 'project/builds/' + PROJECT_ID + '?branch=' + PROJECT_BRANCH + '&per_page=' + PER_PAGE,
|
||||
|
||||
success: function (data) {
|
||||
$('#latest-builds').html(data);
|
||||
|
|
|
@ -192,7 +192,7 @@ class InstallCommand extends Command
|
|||
}
|
||||
|
||||
if (!$adminName = $input->getOption('admin-name')) {
|
||||
$questionName = new Question(Lang::get('admin-name'));
|
||||
$questionName = new Question(Lang::get('admin_name'));
|
||||
$adminName = $helper->ask($input, $output, $questionName);
|
||||
}
|
||||
|
||||
|
@ -240,6 +240,9 @@ class InstallCommand extends Command
|
|||
$url = $helper->ask($input, $output, $question);
|
||||
}
|
||||
|
||||
$config['language'] = 'en';
|
||||
$config['per_page'] = 10;
|
||||
|
||||
$config['url'] = $url;
|
||||
$config['worker'] = $this->getQueueInformation($input, $output, $helper);
|
||||
|
||||
|
@ -382,9 +385,7 @@ class InstallCommand extends Command
|
|||
{
|
||||
$output->write(Lang::get('setting_up_db'));
|
||||
|
||||
$phinxBinary = escapeshellarg(ROOT_DIR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phinx');
|
||||
$phinxScript = escapeshellarg(APP_DIR . 'phinx.php');
|
||||
shell_exec($phinxBinary . ' migrate -c ' . $phinxScript);
|
||||
shell_exec(ROOT_DIR . 'bin/console php-censor-migrations:migrate');
|
||||
|
||||
$output->writeln('<info>'.Lang::get('ok').'</info>');
|
||||
}
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Command;
|
||||
|
||||
use b8\Config;
|
||||
use Monolog\Logger;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Generate console command - Reads the database and generates models and stores.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Console
|
||||
*/
|
||||
class UpdateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct(Logger $logger, $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('php-censor:update')
|
||||
->setDescription(Lang::get('update_app'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Model and Store classes by reading database meta data.
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!$this->verifyInstalled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output->write(Lang::get('updating_app'));
|
||||
|
||||
shell_exec(ROOT_DIR . 'vendor/bin/phinx migrate -c "' . APP_DIR . 'phinx.php"');
|
||||
|
||||
$output->writeln('<info>'.Lang::get('ok').'</info>');
|
||||
}
|
||||
|
||||
protected function verifyInstalled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$url = $config->get('php-censor.url');
|
||||
|
||||
return !empty($url);
|
||||
}
|
||||
}
|
68
src/PHPCensor/Console/Application.php
Normal file
68
src/PHPCensor/Console/Application.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Console;
|
||||
|
||||
use b8\Config;
|
||||
use Symfony\Component\Console\Application as BaseApplication;
|
||||
use Phinx\Console\Command\Create;
|
||||
use Phinx\Console\Command\Migrate;
|
||||
use Phinx\Console\Command\Rollback;
|
||||
use Phinx\Console\Command\Status;
|
||||
use Phinx\Config\Config as PhinxConfig;
|
||||
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the application
|
||||
* @param string $version The version of the application
|
||||
*/
|
||||
public function __construct($name = 'PHP Censor - Continuous Integration for PHP', $version = '')
|
||||
{
|
||||
parent::__construct($name, $version);
|
||||
|
||||
$applicationConfig = Config::getInstance();
|
||||
$databaseSettings = $applicationConfig->get('b8.database', []);
|
||||
|
||||
$phinxSettings = [
|
||||
'paths' => [
|
||||
'migrations' => 'src/PHPCensor/Migrations',
|
||||
],
|
||||
'environments' => [
|
||||
'default_migration_table' => 'migration',
|
||||
'default_database' => 'php-censor',
|
||||
'php-censor' => [
|
||||
'adapter' => 'mysql',
|
||||
'host' => $databaseSettings['servers']['write'],
|
||||
'name' => $databaseSettings['name'],
|
||||
'user' => $databaseSettings['username'],
|
||||
'pass' => $databaseSettings['password'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$phinxConfig = new PhinxConfig($phinxSettings);
|
||||
|
||||
$this->add(
|
||||
(new Create())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:create')
|
||||
);
|
||||
$this->add(
|
||||
(new Migrate())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:migrate')
|
||||
);
|
||||
$this->add(
|
||||
(new Rollback())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:rollback')
|
||||
);
|
||||
$this->add(
|
||||
(new Status())
|
||||
->setConfig($phinxConfig)
|
||||
->setName('php-censor-migrations:status')
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
@ -9,7 +10,6 @@
|
|||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Plugin\Util\ComposerPluginInformation;
|
||||
use PHPCensor\Plugin\Util\FilesPluginInformation;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
@ -72,10 +73,10 @@ class ProjectController extends PHPCensor\Controller
|
|||
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
|
||||
}
|
||||
|
||||
$per_page = 10;
|
||||
$perPage = $_SESSION['php-censor-user']->getFinalPerPage();
|
||||
$page = $this->getParam('p', 1);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($branch), (($page - 1) * $per_page));
|
||||
$pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $per_page);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($branch), (($page - 1) * $perPage), $perPage);
|
||||
$pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $perPage);
|
||||
|
||||
if ($page > $pages) {
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
|
@ -90,8 +91,9 @@ class ProjectController extends PHPCensor\Controller
|
|||
$this->view->branches = $this->projectStore->getKnownBranches($projectId);
|
||||
$this->view->page = $page;
|
||||
$this->view->pages = $pages;
|
||||
$this->view->perPage = $perPage;
|
||||
|
||||
$this->layout->title = $project->getTitle();
|
||||
$this->layout->title = $project->getTitle();
|
||||
$this->layout->subtitle = $this->view->branch;
|
||||
|
||||
return $this->view->render();
|
||||
|
@ -141,12 +143,17 @@ class ProjectController extends PHPCensor\Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* AJAX get latest builds.
|
||||
*/
|
||||
* AJAX get latest builds.
|
||||
*
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function builds($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', '');
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($branch));
|
||||
$branch = $this->getParam('branch', '');
|
||||
$perPage = (integer)$this->getParam('per_page', 10);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($branch), 0, $perPage);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($builds[0]);
|
||||
|
@ -156,12 +163,14 @@ class ProjectController extends PHPCensor\Controller
|
|||
/**
|
||||
* Render latest builds for project as HTML table.
|
||||
*
|
||||
* @param $projectId
|
||||
* @param string $branch A urldecoded branch name.
|
||||
* @param int $start
|
||||
* @param int $projectId
|
||||
* @param string $branch A urldecoded branch name.
|
||||
* @param int $start
|
||||
* @param int $perPage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getLatestBuildsHtml($projectId, $branch = '', $start = 0)
|
||||
protected function getLatestBuildsHtml($projectId, $branch = '', $start = 0, $perPage = 10)
|
||||
{
|
||||
$criteria = ['project_id' => $projectId];
|
||||
if (!empty($branch)) {
|
||||
|
@ -169,7 +178,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
}
|
||||
|
||||
$order = ['id' => 'DESC'];
|
||||
$builds = $this->buildStore->getWhere($criteria, 10, $start, [], $order);
|
||||
$builds = $this->buildStore->getWhere($criteria, $perPage, $start, [], $order);
|
||||
$view = new b8\View('BuildsTable');
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -14,6 +14,7 @@ use b8\Exception\HttpException\NotFoundException;
|
|||
use b8\Form;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\UserService;
|
||||
|
||||
/**
|
||||
|
@ -61,36 +62,25 @@ class UserController extends Controller
|
|||
*/
|
||||
public function profile()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
$language = $this->getParam('language', null);
|
||||
$perPage = $this->getParam('per_page', null);
|
||||
|
||||
$currentLang = Lang::getLanguage();
|
||||
$chosenLang = $this->getParam('language', $currentLang);
|
||||
|
||||
if ($chosenLang !== $currentLang) {
|
||||
setcookie('php-censor-language', $chosenLang, time() + (10 * 365 * 24 * 60 * 60), '/');
|
||||
Lang::setLanguage($chosenLang);
|
||||
}
|
||||
|
||||
$_SESSION['php-censor-user'] = $this->userService->updateUser($user, $name, $email, $password);
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$_SESSION['php-censor-user'] = $this->userService->updateUser($user, $name, $email, $password, null, $language, $perPage);
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
$this->view->updated = 1;
|
||||
}
|
||||
|
||||
$this->layout->title = $user->getName();
|
||||
$this->layout->title = $user->getName();
|
||||
$this->layout->subtitle = Lang::get('edit_profile');
|
||||
|
||||
$values = $user->getDataArray();
|
||||
|
||||
if (array_key_exists('php-censor-language', $_COOKIE)) {
|
||||
$values['language'] = $_COOKIE['php-censor-language'];
|
||||
}
|
||||
|
||||
$form = new Form();
|
||||
$form->setAction(APP_URL.'user/profile');
|
||||
$form->setMethod('POST');
|
||||
|
@ -100,6 +90,7 @@ class UserController extends Controller
|
|||
$name->setContainerClass('form-group');
|
||||
$name->setLabel(Lang::get('name'));
|
||||
$name->setRequired(true);
|
||||
$name->setValue($user->getName());
|
||||
$form->addField($name);
|
||||
|
||||
$email = new Form\Element\Email('email');
|
||||
|
@ -107,6 +98,7 @@ class UserController extends Controller
|
|||
$email->setContainerClass('form-group');
|
||||
$email->setLabel(Lang::get('email_address'));
|
||||
$email->setRequired(true);
|
||||
$email->setValue($user->getEmail());
|
||||
$form->addField($email);
|
||||
|
||||
$password = new Form\Element\Password('password');
|
||||
|
@ -114,24 +106,41 @@ class UserController extends Controller
|
|||
$password->setContainerClass('form-group');
|
||||
$password->setLabel(Lang::get('password_change'));
|
||||
$password->setRequired(false);
|
||||
$password->setValue(null);
|
||||
$form->addField($password);
|
||||
|
||||
$lang = new Form\Element\Select('language');
|
||||
$lang->setClass('form-control');
|
||||
$lang->setContainerClass('form-group');
|
||||
$lang->setLabel(Lang::get('language'));
|
||||
$lang->setRequired(true);
|
||||
$lang->setOptions(Lang::getLanguageOptions());
|
||||
$lang->setValue(Lang::getLanguage());
|
||||
$form->addField($lang);
|
||||
$language = new Form\Element\Select('language');
|
||||
$language->setClass('form-control');
|
||||
$language->setContainerClass('form-group');
|
||||
$language->setLabel(Lang::get('language'));
|
||||
$language->setRequired(true);
|
||||
$language->setOptions(array_merge(
|
||||
['' => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.language') . ')'],
|
||||
Lang::getLanguageOptions())
|
||||
);
|
||||
$language->setValue($user->getLanguage());
|
||||
$form->addField($language);
|
||||
|
||||
$perPage = new Form\Element\Select('per_page');
|
||||
$perPage->setClass('form-control');
|
||||
$perPage->setContainerClass('form-group');
|
||||
$perPage->setLabel(Lang::get('per_page'));
|
||||
$perPage->setRequired(true);
|
||||
$perPage->setOptions([
|
||||
null => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.per_page') . ')',
|
||||
10 => 10,
|
||||
25 => 25,
|
||||
50 => 50,
|
||||
100 => 100,
|
||||
]);
|
||||
$perPage->setValue($user->getPerPage());
|
||||
$form->addField($perPage);
|
||||
|
||||
$submit = new Form\Element\Submit();
|
||||
$submit->setClass('btn btn-success');
|
||||
$submit->setValue(Lang::get('save'));
|
||||
$form->addField($submit);
|
||||
|
||||
$form->setValues($values);
|
||||
|
||||
$this->view->form = $form;
|
||||
|
||||
return $this->view->render();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Config;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
/**
|
||||
* Languages Helper Class - Handles loading strings files and the strings within them.
|
||||
|
@ -18,6 +19,8 @@ use b8\Config;
|
|||
*/
|
||||
class Lang
|
||||
{
|
||||
const DEFAULT_LANGUAGE = 'en';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -36,7 +39,7 @@ class Lang
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $en_strings = [];
|
||||
protected static $default_strings = [];
|
||||
|
||||
/**
|
||||
* Get a specific string from the language file.
|
||||
|
@ -51,8 +54,8 @@ class Lang
|
|||
if (array_key_exists($string, self::$strings)) {
|
||||
$vars[0] = self::$strings[$string];
|
||||
return call_user_func_array('sprintf', $vars);
|
||||
} elseif ('en' !== self::$language && array_key_exists($string, self::$en_strings)) {
|
||||
$vars[0] = self::$en_strings[$string];
|
||||
} elseif (self::DEFAULT_LANGUAGE !== self::$language && array_key_exists($string, self::$default_strings)) {
|
||||
$vars[0] = self::$default_strings[$string];
|
||||
return call_user_func_array('sprintf', $vars);
|
||||
}
|
||||
|
||||
|
@ -129,41 +132,28 @@ class Lang
|
|||
*/
|
||||
public static function init(Config $config, $language_force = null)
|
||||
{
|
||||
self::$en_strings = self::loadLanguage('en');
|
||||
self::$default_strings = self::loadLanguage(self::DEFAULT_LANGUAGE);
|
||||
self::loadAvailableLanguages();
|
||||
|
||||
if ($language_force && self::setLanguage($language_force)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try cookies first:
|
||||
if (isset($_COOKIE) && array_key_exists('php-censor-language', $_COOKIE) && self::setLanguage($_COOKIE['php-censor-language'])) {
|
||||
return;
|
||||
|
||||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
if (!is_object($user) && gettype($user) == 'object') {
|
||||
$user = unserialize(serialize($_SESSION['php-censor-user']));
|
||||
}
|
||||
|
||||
// Try user language:
|
||||
if (isset($_SERVER) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
|
||||
$langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
|
||||
foreach ($langs as $lang) {
|
||||
$parts = explode(';', $lang);
|
||||
$language = strtolower($parts[0]);
|
||||
|
||||
if (self::setLanguage($language)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try the installation default language:
|
||||
$language = $config->get('php-censor.basic.language', null);
|
||||
$language = $user->getLanguage();
|
||||
if (self::setLanguage($language)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to English:
|
||||
self::$language = 'en';
|
||||
self::$strings = self::loadLanguage();
|
||||
// Try the installation default language:
|
||||
$language = $config->get('php-censor.language', self::DEFAULT_LANGUAGE);
|
||||
if (self::setLanguage($language)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
return [
|
||||
'language_name' => 'English',
|
||||
'language' => 'Language',
|
||||
'language' => 'Language',
|
||||
'per_page' => 'Items per page',
|
||||
'default' => 'Default',
|
||||
|
||||
// Log in:
|
||||
'log_in_to_app' => 'Log in to PHP Censor',
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
return [
|
||||
'language_name' => 'Pусский',
|
||||
'language' => 'язык',
|
||||
'language' => 'Язык',
|
||||
'per_page' => 'Количество элементов на странице',
|
||||
'default' => 'По умолчанию',
|
||||
|
||||
// Log in:
|
||||
'log_in_to_app' => 'Войти в PHP Censor',
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddedLanguageAndPerPageForUser extends AbstractMigration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$table = $this->table('user');
|
||||
|
||||
if (!$table->hasColumn('language')) {
|
||||
$table->addColumn('language', 'string', ['limit' => 5, 'null' => true])->save();
|
||||
}
|
||||
|
||||
if (!$table->hasColumn('per_page')) {
|
||||
$table->addColumn('per_page', 'integer', ['null' => true])->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$table = $this->table('user');
|
||||
|
||||
if ($table->hasColumn('language')) {
|
||||
$table->removeColumn('language')->save();
|
||||
}
|
||||
|
||||
if ($table->hasColumn('per_page')) {
|
||||
$table->removeColumn('per_page')->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
namespace PHPCensor\Model\Base;
|
||||
|
||||
use b8\Config;
|
||||
use PHPCensor\Model;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,8 @@ class UserBase extends Model
|
|||
'hash' => null,
|
||||
'is_admin' => null,
|
||||
'name' => null,
|
||||
'language' => null,
|
||||
'per_page' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -49,6 +52,8 @@ class UserBase extends Model
|
|||
'hash' => 'getHash',
|
||||
'is_admin' => 'getIsAdmin',
|
||||
'name' => 'getName',
|
||||
'language' => 'getLanguage',
|
||||
'per_page' => 'getPerPage',
|
||||
// Foreign key getters:
|
||||
];
|
||||
|
||||
|
@ -62,6 +67,8 @@ class UserBase extends Model
|
|||
'hash' => 'setHash',
|
||||
'is_admin' => 'setIsAdmin',
|
||||
'name' => 'setName',
|
||||
'language' => 'setLanguage',
|
||||
'per_page' => 'setPerPage',
|
||||
// Foreign key setters:
|
||||
];
|
||||
|
||||
|
@ -95,6 +102,16 @@ class UserBase extends Model
|
|||
'length' => 250,
|
||||
'default' => null,
|
||||
],
|
||||
'language' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 5,
|
||||
'default' => null,
|
||||
],
|
||||
'per_page' => [
|
||||
'type' => 'int',
|
||||
'length' => 11,
|
||||
'default' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -119,7 +136,7 @@ class UserBase extends Model
|
|||
*/
|
||||
public function getId()
|
||||
{
|
||||
$rtn = $this->data['id'];
|
||||
$rtn = $this->data['id'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -131,7 +148,7 @@ class UserBase extends Model
|
|||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
$rtn = $this->data['email'];
|
||||
$rtn = $this->data['email'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -143,7 +160,7 @@ class UserBase extends Model
|
|||
*/
|
||||
public function getHash()
|
||||
{
|
||||
$rtn = $this->data['hash'];
|
||||
$rtn = $this->data['hash'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -155,7 +172,7 @@ class UserBase extends Model
|
|||
*/
|
||||
public function getIsAdmin()
|
||||
{
|
||||
$rtn = $this->data['is_admin'];
|
||||
$rtn = $this->data['is_admin'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -167,7 +184,31 @@ class UserBase extends Model
|
|||
*/
|
||||
public function getName()
|
||||
{
|
||||
$rtn = $this->data['name'];
|
||||
$rtn = $this->data['name'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of Language / language.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
$rtn = $this->data['language'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of PerPage / per_page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPerPage()
|
||||
{
|
||||
$rtn = $this->data['per_page'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -271,4 +312,51 @@ class UserBase extends Model
|
|||
|
||||
$this->_setModified('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of Language / language.
|
||||
*
|
||||
* Must not be null.
|
||||
* @param $value string
|
||||
*/
|
||||
public function setLanguage($value)
|
||||
{
|
||||
if ($this->data['language'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['language'] = $value;
|
||||
|
||||
$this->_setModified('language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of PerPage / per_page.
|
||||
*
|
||||
* Must not be null.
|
||||
* @param $value string
|
||||
*/
|
||||
public function setPerPage($value)
|
||||
{
|
||||
if ($this->data['per_page'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['per_page'] = $value;
|
||||
|
||||
$this->_setModified('per_page');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getFinalPerPage()
|
||||
{
|
||||
$perPage = $this->getPerPage();
|
||||
if ($perPage) {
|
||||
return (integer)$perPage;
|
||||
}
|
||||
|
||||
return (integer)Config::getInstance()->get('php-censor.per_page', 10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace PHPCensor\Service;
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
||||
|
@ -34,33 +35,43 @@ class UserService
|
|||
|
||||
/**
|
||||
* Create a new user within PHPCI.
|
||||
* @param $name
|
||||
* @param $emailAddress
|
||||
* @param $password
|
||||
* @param bool $isAdmin
|
||||
* @return \PHPCensor\Model\User
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $emailAddress
|
||||
* @param string $password
|
||||
* @param bool $isAdmin
|
||||
* @param string $language
|
||||
* @param integer $perPage
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function createUser($name, $emailAddress, $password, $isAdmin = false)
|
||||
public function createUser($name, $emailAddress, $password, $isAdmin = false, $language = null, $perPage = null)
|
||||
{
|
||||
$user = new User();
|
||||
$user->setName($name);
|
||||
$user->setEmail($emailAddress);
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
$user->setIsAdmin(($isAdmin ? 1 : 0));
|
||||
$user->setLanguage($language);
|
||||
$user->setPerPage($perPage);
|
||||
|
||||
return $this->store->save($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a user.
|
||||
* @param User $user
|
||||
* @param $name
|
||||
* @param $emailAddress
|
||||
* @param null $password
|
||||
* @param null $isAdmin
|
||||
* @return \PHPCensor\Model\User
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $name
|
||||
* @param string $emailAddress
|
||||
* @param string $password
|
||||
* @param bool $isAdmin
|
||||
* @param string $language
|
||||
* @param integer $perPage
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function updateUser(User $user, $name, $emailAddress, $password = null, $isAdmin = null)
|
||||
public function updateUser(User $user, $name, $emailAddress, $password = null, $isAdmin = null, $language = null, $perPage = null)
|
||||
{
|
||||
$user->setName($name);
|
||||
$user->setEmail($emailAddress);
|
||||
|
@ -73,6 +84,9 @@ class UserService
|
|||
$user->setIsAdmin(($isAdmin ? 1 : 0));
|
||||
}
|
||||
|
||||
$user->setLanguage($language);
|
||||
$user->setPerPage($perPage);
|
||||
|
||||
return $this->store->save($user);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<script>
|
||||
var PROJECT_ID = <?php print $project->getId(); ?>;
|
||||
var PROJECT_BRANCH = '<?php print $branch; ?>';
|
||||
var PER_PAGE = <?php print $perPage; ?>;
|
||||
</script>
|
||||
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
|
|
Loading…
Reference in a new issue