mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-25 16:09:28 +00:00
CodeSniffer
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
if (! defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Database Class
|
||||
@@ -15,28 +16,27 @@ class DBTools extends FHC_Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_seed_path = APPPATH.'seeds/';
|
||||
protected $seed_path = APPPATH.'seeds/';
|
||||
|
||||
/**
|
||||
* Seed basename regex
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_seed_regex = '/^\d{3}_(\w+)$/';
|
||||
protected $seed_regex = '/^\d{3}_(\w+)$/';
|
||||
|
||||
/**
|
||||
* Initialize DB-Tools Class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli=true;
|
||||
$cli = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,16 +45,15 @@ class DBTools extends FHC_Controller
|
||||
}
|
||||
|
||||
// can only be run in the development environment
|
||||
if (ENVIRONMENT !== 'development') {
|
||||
if (ENVIRONMENT !== 'development')
|
||||
exit('Wowsers! You don\'t want to do that!');
|
||||
}
|
||||
$this->load->database('system'); //Use the system-Connection for DB-Manipulation
|
||||
$this->load->library('migration');
|
||||
|
||||
// If not set, set it
|
||||
//$this->_seed_path !== '' OR $this->_seed_path = APPPATH.'seeds/';
|
||||
//$this->seed_path !== '' OR $this->seed_path = APPPATH.'seeds/';
|
||||
// Add trailing slash if not set
|
||||
//$this->_seed_path = rtrim($this->_seed_path, '/').'/';
|
||||
//$this->seed_path = rtrim($this->seed_path, '/').'/';
|
||||
|
||||
// Load seed language
|
||||
$this->lang->load('seed');
|
||||
@@ -68,43 +67,51 @@ class DBTools extends FHC_Controller
|
||||
log_message('info', 'DB-Tools Controller Initialized');
|
||||
}
|
||||
|
||||
public function index()
|
||||
/**
|
||||
* Main function index as help
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php index.ci.php DBTools migrate [\"version_number\"] Run all migrations. The version number is optional.\n";
|
||||
$result .= "php index.ci.php DBTools migrate [\"version_number\"] Run all migrations. "
|
||||
$result .= "The version number is optional.\n";
|
||||
$result .= "php index.ci.php DBTools seed \"file_name\" Run the specified seed file.\n";
|
||||
|
||||
echo $result . PHP_EOL;
|
||||
echo $result.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate to latest or current version
|
||||
*
|
||||
* @param string $version One of either "latest" or "current"
|
||||
* @return void
|
||||
*/
|
||||
public function migrate($version = 'latest')
|
||||
{
|
||||
|
||||
if ($this->cli && $this->migration->current() === FALSE)
|
||||
if ($this->cli && $this->migration->current() === false)
|
||||
{
|
||||
show_error($this->migration->error_string());
|
||||
}
|
||||
elseif ($version != 'latest' && $version != 'current')
|
||||
{
|
||||
$this->_failed('Migration version must be either latest or current');
|
||||
$this->__failed('Migration version must be either latest or current');
|
||||
}
|
||||
|
||||
if (!$this->migration->$version())
|
||||
{
|
||||
$this->_failed();
|
||||
$this->__failed();
|
||||
}
|
||||
|
||||
$this->_succeeded();
|
||||
$this->__succeeded();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Migrate to a specific version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
@@ -116,36 +123,39 @@ class DBTools extends FHC_Controller
|
||||
|
||||
if (!$this->migrate->version($version))
|
||||
{
|
||||
$this->_failed();
|
||||
$this->__failed();
|
||||
}
|
||||
|
||||
$this->_succeeded();
|
||||
$this->__succeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll-back to the last version before current
|
||||
*
|
||||
* @param int $version The migration to rollback to, defaults to previous
|
||||
* @return void
|
||||
*/
|
||||
public function rollback($version = null)
|
||||
{
|
||||
if (is_null($version))
|
||||
{
|
||||
$version = $this->_get_version() ?: 1;
|
||||
$version = $this->__getVersion() ?: 1;
|
||||
$version--;
|
||||
}
|
||||
|
||||
// Check it's definitely false, we could be rolling back to v0
|
||||
if (false === $this->migration->version($version))
|
||||
{
|
||||
$this->_failed();
|
||||
$this->__failed();
|
||||
}
|
||||
|
||||
$this->_succeeded('rolled back');
|
||||
$this->__succeeded('rolled back');
|
||||
}
|
||||
|
||||
/**
|
||||
* ROLLBACK ALL THE THINGS!
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
@@ -155,17 +165,17 @@ class DBTools extends FHC_Controller
|
||||
/**
|
||||
* Seeds DB with Testdata
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name Name of the seed file.
|
||||
* @return bool
|
||||
*/
|
||||
function seed($name = null)
|
||||
public function seed($name = null)
|
||||
{
|
||||
$seeds = $this->find_seeds();
|
||||
$seeds = $this->findSeeds();
|
||||
|
||||
if (empty($seeds))
|
||||
{
|
||||
$this->_error_string = $this->lang->line('seed_none_found');
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
$method = 'seed';
|
||||
@@ -173,21 +183,21 @@ class DBTools extends FHC_Controller
|
||||
foreach ($seeds as $number => $file)
|
||||
{
|
||||
include_once($file);
|
||||
$class = 'Seed_'.ucfirst(strtolower($this->_get_seed_name(basename($file, '.php'))));
|
||||
$class = 'Seed_'.ucfirst(strtolower($this->_getSeedName(basename($file, '.php'))));
|
||||
|
||||
// Validate the seed file structure
|
||||
if ( ! class_exists($class, FALSE))
|
||||
if (! class_exists($class, false))
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('seed_class_doesnt_exist'), $class);
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
// method_exists() returns true for non-public methods,
|
||||
// while is_callable() can't be used without instantiating.
|
||||
// Only get_class_methods() satisfies both conditions.
|
||||
elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class))))
|
||||
elseif (! in_array($method, array_map('strtolower', get_class_methods($class))))
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('seed_missing_'.$method.'_method'), $class);
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
$pending[$number] = array($class, $method);
|
||||
@@ -207,19 +217,19 @@ class DBTools extends FHC_Controller
|
||||
*
|
||||
* @return array list of seed file paths sorted by version
|
||||
*/
|
||||
public function find_seeds()
|
||||
public function findSeeds()
|
||||
{
|
||||
$seeds = array();
|
||||
|
||||
// Load all *_*.php files in the seeds path
|
||||
foreach (glob($this->_seed_path.'*_*.php') as $file)
|
||||
foreach (glob($this->seed_path.'*_*.php') as $file)
|
||||
{
|
||||
$name = basename($file, '.php');
|
||||
|
||||
// Filter out non-seed files
|
||||
if (preg_match($this->_seed_regex, $name))
|
||||
if (preg_match($this->seed_regex, $name))
|
||||
{
|
||||
$number = $this->_get_seed_number($name);
|
||||
$number = $this->_getSeedNumber($name);
|
||||
|
||||
// There cannot be duplicate seed numbers
|
||||
if (isset($seeds[$number]))
|
||||
@@ -239,10 +249,10 @@ class DBTools extends FHC_Controller
|
||||
/**
|
||||
* Extracts the seed number from a filename
|
||||
*
|
||||
* @param string $seed
|
||||
* @param string $seed Filename of the seed.
|
||||
* @return string Numeric portion of a seed filename
|
||||
*/
|
||||
protected function _get_seed_number($seed)
|
||||
protected function _getSeedNumber($seed)
|
||||
{
|
||||
return sscanf($seed, '%[0-9]+', $number)
|
||||
? $number : '0';
|
||||
@@ -250,10 +260,10 @@ class DBTools extends FHC_Controller
|
||||
/**
|
||||
* Extracts the seed class name from a filename
|
||||
*
|
||||
* @param string $seed
|
||||
* @param string $seed Filename of the seed.
|
||||
* @return string text portion of a migration filename
|
||||
*/
|
||||
protected function _get_seed_name($seed)
|
||||
protected function _getSeedName($seed)
|
||||
{
|
||||
$parts = explode('_', $seed);
|
||||
array_shift($parts);
|
||||
@@ -264,10 +274,11 @@ class DBTools extends FHC_Controller
|
||||
* Yay, it worked! Tell the user.
|
||||
*
|
||||
* @param string $task What did we just do? We...
|
||||
* @return void
|
||||
*/
|
||||
private function _succeeded($task = 'migrated')
|
||||
private function __succeeded($task = 'migrated')
|
||||
{
|
||||
$version = $this->_get_version();
|
||||
$version = $this->__getVersion();
|
||||
exit('Successfully '.$task.' to version '.$version);
|
||||
}
|
||||
|
||||
@@ -275,19 +286,20 @@ class DBTools extends FHC_Controller
|
||||
* Output an error message when it all goes tits up
|
||||
*
|
||||
* @param string $message Error to output (default to CI's migration error)
|
||||
* @return void
|
||||
*/
|
||||
private function _failed($message = null)
|
||||
private function __failed($message = null)
|
||||
{
|
||||
$message = $message ?: $this->migration->error_string();
|
||||
show_error($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Carbon copy of parent::_get_version, but that's protected.
|
||||
* Carbon copy of parent::__getVersion, but that's protected.
|
||||
*
|
||||
* @return int Currently installed migration number
|
||||
*/
|
||||
private function _get_version()
|
||||
private function __getVersion()
|
||||
{
|
||||
$row = $this->db->get('ci_migrations')->row();
|
||||
return $row ? $row->version : 0;
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Migrate extends FHC_Controller
|
||||
{
|
||||
private $class_version = '1.0';
|
||||
private $cli = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if ($this->input->is_cli_request())
|
||||
{
|
||||
$cli=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//$this->output->set_status_header(403, 'Migrations must be run from the CLI');
|
||||
//exit;
|
||||
}
|
||||
$this->load->database('system'); //Use the system-Connection for DB-Manipulation
|
||||
$this->load->library('migration');
|
||||
$this->load->library('FHC_Seed');
|
||||
}
|
||||
|
||||
|
||||
public function help() {
|
||||
$result = "The following are the available command line interface commands\n\n";
|
||||
$result .= "php index.ci.php db migrate [\"version_number\"] Run all migrations. The version number is optional.\n";
|
||||
$result .= "php index.ci.php db seed \"file_name\" Run the specified seed file. Filename is optional.\n";
|
||||
|
||||
echo $result . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate to latest or current version
|
||||
*
|
||||
* @param string $version One of either "latest" or "current"
|
||||
*/
|
||||
public function migrate($version = 'latest')
|
||||
{
|
||||
|
||||
if ($this->cli && $this->migration->current() === FALSE)
|
||||
{
|
||||
show_error($this->migration->error_string());
|
||||
}
|
||||
elseif ($version != 'latest' && $version != 'current')
|
||||
{
|
||||
$this->_failed('Migration version must be either latest or current');
|
||||
}
|
||||
|
||||
if (!$this->migration->version())
|
||||
{
|
||||
$this->_failed();
|
||||
}
|
||||
|
||||
$this->_succeeded();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Migrate to a specific version
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if ($version == 'latest' || $version == 'current')
|
||||
{
|
||||
$this->index($version);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$this->migrate->version($version))
|
||||
{
|
||||
$this->_failed();
|
||||
}
|
||||
|
||||
$this->_succeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll-back to the last version before current
|
||||
*
|
||||
* @param int $version The migration to rollback to, defaults to previous
|
||||
*/
|
||||
public function rollback($version = null)
|
||||
{
|
||||
if (is_null($version))
|
||||
{
|
||||
$version = $this->_get_version() ?: 1;
|
||||
$version--;
|
||||
}
|
||||
|
||||
// Check it's definitely false, we could be rolling back to v0
|
||||
if (false === $this->migration->version($version))
|
||||
{
|
||||
$this->_failed();
|
||||
}
|
||||
|
||||
$this->_succeeded('rolled back');
|
||||
}
|
||||
|
||||
/**
|
||||
* ROLLBACK ALL THE THINGS!
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$this->rollback(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed DB with TestData
|
||||
*
|
||||
* @param string $name Name of the SeedFile
|
||||
*/
|
||||
|
||||
public function seed($name = null)
|
||||
{
|
||||
$this->fhc_seed->seed($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Yay, it worked! Tell the user.
|
||||
*
|
||||
* @param string $task What did we just do? We...
|
||||
*/
|
||||
private function _succeeded($task = 'migrated')
|
||||
{
|
||||
$version = $this->_get_version();
|
||||
exit('Successfully '.$task.' to version '.$version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an error message when it all goes tits up
|
||||
*
|
||||
* @param string $message Error to output (default to CI's migration error)
|
||||
*/
|
||||
private function _failed($message = null)
|
||||
{
|
||||
$message = $message ?: $this->migration->error_string();
|
||||
show_error($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Carbon copy of parent::_get_version, but that's protected.
|
||||
*
|
||||
* @return int Currently installed migration number
|
||||
*/
|
||||
private function _get_version()
|
||||
{
|
||||
$row = $this->db->get('ci_migrations')->row();
|
||||
return $row ? $row->version : 0;
|
||||
}
|
||||
|
||||
public function about()
|
||||
{
|
||||
echo "CI-Migrate_CLI v".$this->class_version;
|
||||
echo "\nCheck http://github.com/dshoreman/ci-migrate_cli/ for updates";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class TblStudiengang extends FHC_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('organisation/studiengang_model');
|
||||
$this->load->library('form_validation');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$keyword = '';
|
||||
$this->load->library('pagination');
|
||||
|
||||
$config['base_url'] = base_url() . 'studiengang/index/';
|
||||
$config['total_rows'] = $this->studiengang_model->total_rows();
|
||||
$config['per_page'] = 10;
|
||||
$config['uri_segment'] = 3;
|
||||
$config['suffix'] = '.html';
|
||||
$config['first_url'] = base_url() . 'studiengang.html';
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$start = $this->uri->segment(3, 0);
|
||||
$studiengang = $this->studiengang_model->index_limit($config['per_page'], $start);
|
||||
|
||||
$data = array(
|
||||
'studiengang_data' => $studiengang,
|
||||
'keyword' => $keyword,
|
||||
'pagination' => $this->pagination->create_links(),
|
||||
'total_rows' => $config['total_rows'],
|
||||
'start' => $start,
|
||||
);
|
||||
|
||||
$this->load->view('tbl_studiengang_list', $data);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$keyword = $this->uri->segment(3, $this->input->post('keyword', TRUE));
|
||||
$this->load->library('pagination');
|
||||
|
||||
if ($this->uri->segment(2)=='search') {
|
||||
$config['base_url'] = base_url() . 'studiengang/search/' . $keyword;
|
||||
} else {
|
||||
$config['base_url'] = base_url() . 'studiengang/index/';
|
||||
}
|
||||
|
||||
$config['total_rows'] = $this->studiengang_model->search_total_rows($keyword);
|
||||
$config['per_page'] = 10;
|
||||
$config['uri_segment'] = 4;
|
||||
$config['suffix'] = '.html';
|
||||
$config['first_url'] = base_url() . 'studiengang/search/'.$keyword.'.html';
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$start = $this->uri->segment(4, 0);
|
||||
$studiengang = $this->studiengang_model->search_index_limit($config['per_page'], $start, $keyword);
|
||||
|
||||
$data = array(
|
||||
'studiengang_data' => $studiengang,
|
||||
'keyword' => $keyword,
|
||||
'pagination' => $this->pagination->create_links(),
|
||||
'total_rows' => $config['total_rows'],
|
||||
'start' => $start,
|
||||
);
|
||||
$this->load->view('tbl_studiengang_list', $data);
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
$row = $this->studiengang_model->get_by_id($id);
|
||||
if ($row) {
|
||||
$data = array(
|
||||
);
|
||||
$this->load->view('tbl_studiengang_read', $data);
|
||||
} else {
|
||||
$this->session->set_flashdata('message', 'Record Not Found');
|
||||
redirect(site_url('studiengang'));
|
||||
}
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = array(
|
||||
'button' => 'Create',
|
||||
'action' => site_url('studiengang/create_action'),
|
||||
);
|
||||
$this->load->view('tbl_studiengang_form', $data);
|
||||
}
|
||||
|
||||
public function create_action()
|
||||
{
|
||||
$this->_rules();
|
||||
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$this->create();
|
||||
} else {
|
||||
$data = array(
|
||||
);
|
||||
|
||||
$this->studiengang_model->insert($data);
|
||||
$this->session->set_flashdata('message', 'Create Record Success');
|
||||
redirect(site_url('studiengang'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$row = $this->studiengang_model->get_by_id($id);
|
||||
|
||||
if ($row) {
|
||||
$data = array(
|
||||
'button' => 'Update',
|
||||
'action' => site_url('studiengang/update_action'),
|
||||
);
|
||||
$this->load->view('tbl_studiengang_form', $data);
|
||||
} else {
|
||||
$this->session->set_flashdata('message', 'Record Not Found');
|
||||
redirect(site_url('studiengang'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_action()
|
||||
{
|
||||
$this->_rules();
|
||||
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$this->update($this->input->post('', TRUE));
|
||||
} else {
|
||||
$data = array(
|
||||
);
|
||||
|
||||
$this->studiengang_model->update($this->input->post('', TRUE), $data);
|
||||
$this->session->set_flashdata('message', 'Update Record Success');
|
||||
redirect(site_url('studiengang'));
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$row = $this->studiengang_model->get_by_id($id);
|
||||
|
||||
if ($row) {
|
||||
$this->studiengang_model->delete($id);
|
||||
$this->session->set_flashdata('message', 'Delete Record Success');
|
||||
redirect(site_url('studiengang'));
|
||||
} else {
|
||||
$this->session->set_flashdata('message', 'Record Not Found');
|
||||
redirect(site_url('studiengang'));
|
||||
}
|
||||
}
|
||||
|
||||
public function _rules()
|
||||
{
|
||||
|
||||
$this->form_validation->set_rules('', '', 'trim');
|
||||
$this->form_validation->set_error_delimiters('<span class="text-danger">', '</span>');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* End of file Studiengang.php */
|
||||
/* Location: ./application/controllers/Studiengang.php */
|
||||
Reference in New Issue
Block a user