Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

7.1. Upgrade to 3.0

Shin Okada edited this page Aug 13, 2015 · 3 revisions

How to upgrade from 2.* to 3.0

Uppercase first

Change all file names in controllers, models, and libraries with uppercase first.

controllers/admin.php should be controller/Admin.php

Download CodeIgniter3.0

Replace all system dir and /index.php.

Compare directories

application dir. Add cache dir, logs dir, add all config dir files and replace index.html in all dir.

Update config/config.php

base_url

$config['base_url'] = 'http://localhost/newwebsite3.0/';

session

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

encryption

$config['encryption_key'] = "some-encryption-key";

composer

$config['composer_autoload'] = TRUE;

config/database.php

Use mysqli.

$db['default'] = array(
'dsn'	=> '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'password',
'database' => 'newwebsite3.0',
'dbdriver' => 'mysqli',
'dbprefix' => '',
    ....
    ....
);

Use composer to install simplepie and oauth2

Install it

cd application/
composer require league/oauth2-client:^0.11.0 
composer require simplepie/simplepie:^1.3

Update modules/welcome/controllers/Auth.php

Get clientId and clientSecret from google console.

<?php

class Auth extends Public_Controller
{

    public function __construct()
    {
        parent::__construct();
    }


    public function session($provider)
    {
      $provider = new League\OAuth2\Client\Provider\Google([
        'clientId'      => 'add clientid here',
        'clientSecret'  => 'add clientsecret',
        'redirectUri'   => 'http://localhost/newwebsite3.0/index.php/welcome/auth/session/google',
        'scopes'        => ['email'],
      ]);

      if (!isset($_GET['code'])) {

        // If we don't have an authorization code then get one
        $authUrl = $provider->getAuthorizationUrl();
        $_SESSION['oauth2state'] = $provider->state;
        header('Location: '.$authUrl);
        exit;

        // Check given state against previously stored one to mitigate CSRF attack
      } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

        unset($_SESSION['oauth2state']);
        exit('Invalid state');

      } else {

        // Try to get an access token (using the authorization code grant)
        $token = $provider->getAccessToken('authorization_code', [
          'code' => $_GET['code']
        ]);

        // Optional: Now you have a token you can look up a users profile data
        try {

          // We got an access token, let's now get the user's details
          $userDetails = $provider->getUserDetails($token);

          // Use these details to create a new profile
          //printf('Hello %s!', $userDetails->firstName);

                $tokenemail =$userDetails->email;
                // check user $user['email'] in the db 
                $emailcheck = $this->user_model->checkUserEmail($tokenemail);
                //$emailcheck = $this->userlib->checkOpenIdEmail($user['email']);
                if(!$emailcheck==FALSE)
                {
                    $id = $emailcheck['id'];
                    $user = $this->userlib->set_userlogin($id);
                    flashMsg('success', 'You are logged in.');
                    redirect('welcome','location');       
                }
                else
                {
                    // if it does not exist then redirect to registration
                    flashMsg('warning', 'Your email is not in our database. Please register.');
                    redirect('auth/register','location');
                }

        } catch (Exception $e) {

          // Failed to get user details
          exit('Oh dear...');
        }

        // Use this to interact with an API on the users behalf
        echo $token->accessToken;

        // Use this to get a new access token if the old one expires
        echo $token->refreshToken;

        // Unix timestamp of when the token will expire, and need refreshing
        echo $token->expires;
      }}
}

?>

Replace MX

Replace all files in application/third_party/MX/.

Update application/controllers/admin/settings.php

Add rules to all. Use numeric for boolean and alpha_numeric_spaces for dropdown.

$config['field']['xxxxx'] = array('type'=>'boolean','rules'=>'numeric');
$config['field']['xxxxx'] = array('type'=>'dropdown','rules'=>'alpha_numeric_spaces','params'=>array('options'=>array('text'=>'Plaintext','html'=>'HTML')));

Update class file names with Ucfirst.php

Not for config but need to update all class file name with Ucfirst.php. This includes libraries.

core/MY_Model.php

Comment out line 77.

//public function MY_Model() { $this->__construct(); }

session DB

Update session DB.

CREATE TABLE IF NOT EXISTS `ci_sessions` (
    `id` varchar(40) NOT NULL,
    `ip_address` varchar(45) NOT NULL,
    `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
    `data` blob NOT NULL,
    PRIMARY KEY (id),
    KEY `ci_sessions_timestamp` (`timestamp`)
);

application/module/auth/libraries/Userlib.php

Correct $CI to $this->CI in line 122.

$result = $this->CI->user_model->validateLogin($check,$this->CI->session->userdata('password'));

Delete session_start()

In core/PublicController.php line 42, delete session_start().

Delete sess_create()

libraries/Auth_form_processing.php line 217

Change path index.php/admin

to index.php/admin/home/index

/application/modules/auth/config/userlib.php|30 col 10| $config['userlib_action_admin_login'] = 'admin/home/index';

views/admin/menu

<li><?php print anchor('admin/home/index','<i class="fa fa-dashboard fa-fw"></i> '.$this->lang->line('backendpro_dashboard')); ?></li>

application/core/Admin_controler

$this->bep_site->set_crumb($this->lang->line('backendpro_control_panel'),'admin/home/index');

application/modules/dashboard/libraries

Replace all

Add system/cache

auth/admin/members

$row = str_replace("'","\'",$row);
//$delete  = form_checkbox("select[]",$row["id"],FALSE);  
$delete = '<input type="checkbox" name="select[]" value="'.$row['id'].'"  />';
$active =  ($row['active']?'tick':'cross');   
$myemail = $row['email'];
$size = 20;
//anchor(uri segments, text, attributes)
$editlink = anchor('auth/admin/members/form/'.$row['id'],$this->bep_assets->icon('pencil'));
$gravatar = str_replace("'","\'",gravatar($myemail, $size));
echo "['".$row['id']."', '".$row['username']."', '".$row['email']
."', '".$row['group']."', '".$row['last_visit']."', '".$this->bep_assets->icon($active)."','".$editlink."','".$delete."'],";

fix menu Log in/ Log out, Profile

In application/views/public/topnav.php line 120, change to,

$loggedin = $this->cecilielib->ifloggedin();
if ($loggedin)

7. CodeIgniter.md


  1. Upgrade to 3.0

Clone this wiki locally