install/uninstall file modification

in this tutorial you will learn 

  • how to change/modify a existin codes.
  • which file make modifications for existing code or files for each plugin.
  • modification array
  • modification types (after, before, replace).
  • modification examples
  • when modification happens actually during installation or opening (activating) status.

File name:  /admin/libraries/plugins/plugin_key.php

install/uninstall file modification is a file under admin libraries folder (plugin_key.php)  when the plugin require to write new code to existing code, plugin developer specify modification proccess in this file by using midification type (after ,before ,replace).

After installing a plugin, the status of plugin comes 0 closed at first. During status changes if status opened modification function will first control the modification if changes match then install or modify the files otherwise modification to file would not happen.

Modification Proccess array


 

/// FULL EXAMPLE ///

$modification[]=array(

"action"=> $action,

"filename"=>'application/admin/views/templates/example.tpl',

"type"=>"before",

"find"=>'function product_list(',

"plugin"=>'

new 

 '

);

if ($action=="install"){

/// check if content table has sort order ///

if(array_search("sort_order",$this->CI->db->list_fields('content'))==false){

$this->CI->db->query("alter table content add sort_order int default '0'");

}

/// 

}else{

/// uninstall action code here

}

return $this->CI->modify_file($modification,$action);

 

/// FULL EXAMPLE ///

 

 

Modification Examples

  • before is writing plugin code before find code in specified file. 
  • after  is writing plugin code after find code in specified file.
  • replace is replacing plugin code with find code in specified file.

 

Before Example


 

/// BEFORE EXAMPLE ///

$modification[]=array(

"action"=> $action,

"filename"=>'application/admin/views/templates/example.tpl',

"type"=>"before",

"find"=>'find me ',

"plugin"=>'new code before find me'

);

/// BEFORE EXAMPLE ///

 

 

 

After Example


 

/// AFTER EXAMPLE ///

$modification[]=array(

"action"=> $action,

"filename"=>'application/admin/views/templates/example.tpl',

"type"=>"after",

"find"=>'find me ',

"plugin"=>'new code after find me '

);

/// AFTER EXAMPLE ///

 

 

Replace Example


 

/// REPLACE EXAMPLE ///

$modification[]=array(

"action"=> $action,

"filename"=>'application/admin/views/templates/example.tpl',

"type"=>"replace",

"find"=>'find me',

"plugin"=>'replace this new code instead find me'

);

/// REPLACE EXAMPLE ///

 



Posted by: Müslüm ÇEN
Date Added: 21/02/2016
Last Update:




Not Commented Yet !
Please login in order to comment . Login