|
From: <os...@us...> - 2012-04-14 20:30:30
|
Revision: 4231
http://oscss.svn.sourceforge.net/oscss/?rev=4231&view=rev
Author: oscim
Date: 2012-04-14 20:30:23 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
Suite du travail d'intgeration et d'exploitation des fichier sql , et leur liaision lors de la manipulation des langues
Modified Paths:
--------------
trunk/catalog/admin/includes/classes/oscss_DBIndex.php
trunk/catalog/admin/includes/languages/fr_FR/modules/pages/backup.txt
trunk/catalog/common/classes/DataTypes.php
Added Paths:
-----------
trunk/catalog/admin/includes/classes/DataFileSql.php
trunk/catalog/admin/includes/gabarit/backup/display_view.viewalldb.gab
Copied: trunk/catalog/admin/includes/classes/DataFileSql.php (from rev 4225, trunk/catalog/admin/includes/classes/DataSqlFile.php)
===================================================================
--- trunk/catalog/admin/includes/classes/DataFileSql.php (rev 0)
+++ trunk/catalog/admin/includes/classes/DataFileSql.php 2012-04-14 20:30:23 UTC (rev 4231)
@@ -0,0 +1,229 @@
+<?php if (!defined('HTTP_SERVER')) die('You can not access this file directly!');
+/**
+ @licence GPL 2005-2012 The osCSS developers - osCSS Open Source E-commerce
+ @portion code Copyright (c) 2002 osCommerce
+ @package osCSS-2 <www http://www.oscss.org>
+ @version 2.1.1
+ @date 11/04/2012, 18:17
+ @author oscim <mail aur...@os...> <www http://www.oscim.fr>
+ @encode UTF-8
+ @brief Manipluate files.sql And execute
+*/
+
+Class DataFileSql{
+ /**
+ @def FOLDER_TABLES
+ */
+ const FOLDER_TABLES = 'tables/';
+ /**
+ @def FOLDER_DATAS
+ */
+ const FOLDER_DATAS = 'data/';
+
+
+ /**
+ @var path base folder for list and
+ */
+ public $basepath = '';
+ /**
+ @var boolean process keys
+ */
+ public $exekey = false;
+
+
+ /**
+ @brief constructor
+ @param $basepath string absolute path folder base
+ */
+ public function __construct($basepath){
+
+// if(tep_not_null($basepath) )
+ $this->Set('basepath', $basepath);
+
+ $this->Set('exekey', (DB_MOTOR_TYPE =='InnoDB'));
+
+ }
+
+ /**
+ @brief Define config value
+ @param $type string
+ basepath : absolute path folder base (include action install/remove)
+ @param $value string/int/bool
+ @return $value | false if type not exists
+ */
+ function Set($type, $value){
+ if(isset($this->$type))
+ return $this->$type = $value;
+ else
+ return false;
+ }
+
+ /**
+ @brief ordonne les fichier pour l'install
+ @param path path directory for scan
+ @return array
+ [t] tables
+ [k] keys
+ [d] data
+ */
+ function Browse($type='t'){
+
+ $result=array();
+
+ if($type =='t')
+ $path = $this->basepath . self::FOLDER_TABLES ;
+ elseif($type =='d')
+ $path = $this->basepath . self::FOLDER_DATAS ;
+ else
+ return false;
+
+ foreach(scan($path) as $row){
+ if(in_array(substr($row,-1) , array('~', '.') )) {
+ if(strpos($row , '.key')===false)
+ $result[$type][]=$row;
+
+ elseif(strpos($row , '.key') > 0){
+ if($this->exekey)
+ $result['k'][]=$row;
+ }
+ }
+ }
+
+ return $result;
+
+ }
+
+ /**
+ @brief Traite et analyse le fichier de clef pouren extraire les caratéristiques remarquable
+
+ @return false |
+ object {
+ [language] = 0/1 for link table languages
+ [categorie] = 0/1 for link table languages
+ }
+ */
+ function AnalyseFile($file){
+ $obj = new stdClass();
+
+ if(!file_exists($this->basepath . self::FOLDER_TABLES . $file))
+ return false;
+ /*
+ Traitement des clef et recherche des liaision vers la table language
+ Si une liaison existe, celle ci considere la table associé comme une table de langue et celle ci sera duspliqué lors de l'ajout d'une nouvelle language
+ */
+ $fp = @fopen($this->basepath . self::FOLDER_TABLES . $file, 'rb');
+ $test = $test2 =$test3 =array();
+ while (!feof ($fp)) {
+ $buf = fgets($fp, 4096);
+ if (substr($buf, 0, 2) <> '--' ) {
+ preg_match_all ('#(REFERENCES[ ]{1,}osc_languages[ ]{1,}[\(]languages_id[\)])#i' ,$buf, $match);
+ $test1[] = ((count($match[0])>0)? true : false );
+
+ preg_match_all ('#(REFERENCES[ ]{1,}osc_categories[ ]{1,}[\(]categories_id[\)])#i' ,$buf, $match);
+ $test2[] = ((count($match[0])>0)? true : false );
+
+ preg_match_all ('#(PRIMARY KEY[ ]{1,}[\(]([a-z_, ]*)[\)])#i' ,$buf, $match3);
+ $test3[] = ((count($match3[0])>0)? true : false );
+// print_r($match);
+ if(count($match3[0])>0)
+ $obj->primarykey = @$match3[2][0];
+ }
+ }
+ fclose($fp);
+
+ $obj->primary = (in_array(true, $test3 ));
+ $obj->language = (in_array(true,$test1 ));
+ $obj->categorie = (in_array(true,$test2 ));
+
+ return $obj;
+ }
+
+
+ /**
+ @brief Process for load and install file Datas, and translate in multiple languages
+
+TODO Ajouter multi-langue
+ */
+ function ProcessFileData( $sql_file, $table_prefix = -1,$file_lg_sample='') {
+ global $language;
+ $buffer = '';
+ $lg=false;
+
+ $DB=Database::getInstance();
+
+ if( $file_lg_sample !='')
+ include($file_lg_sample);
+
+ $fp = fopen($sql_file, 'rb');
+
+ while (!feof ($fp)){
+ $buf = fgets($fp, 4096);
+ if (substr($buf, 0, 2) <> '--' ){
+ $buf=preg_replace('/--(.+)*/' ,'',$buf);
+ $buffer .= $buf;
+ }
+ }
+
+
+ $repl = ((is_array($lg) && count($lg) >0)? true : false);
+ $buffer=preg_replace('/[ ](OSC_)([A-Z])/i', ' '.$table_prefix.'$2',$buffer);
+ $buffer = trim($buffer);
+
+ $query=preg_split("/\n/i",$buffer,-1,PREG_SPLIT_NO_EMPTY);
+
+
+ if($repl) {
+ $lg_k = array_keys($lg);
+ $lg_v = array_map('addslashes',$lg);
+ }
+
+ foreach($query as $row){
+ $row = trim($row);
+ if(strlen($row) > 3){
+ $sql=($repl)? str_replace($lg_k,$lg_v,$row) : $row ;
+
+ $DB->query($row);
+ }
+ }
+
+ }
+
+ /**
+ @brief Process for load and install .sql or .key.sql
+ */
+ function ProcessFile( $sql_file, $table_prefix = -1) {
+
+ $buffer = '';
+ $lg=false;
+
+ $fp = fopen($sql_file, 'rb');
+
+ while (!feof ($fp)){
+ $buf = fgets($fp, 4096);
+ if (substr($buf, 0, 2) <> '--' ){
+ $buf=preg_replace('/--(.+)*/' ,'',$buf);
+ $buffer .= $buf;
+ }
+ }
+ fclose($fp);
+
+
+ $DB=Database::getInstance();
+
+ $buffer=preg_replace('/[ ](OSC_)([A-Z])/i', ' '.$table_prefix.'$2',$buffer);
+
+ $query=explode(';',$buffer);
+ foreach($query as $row){
+ $row = trim($row);
+ if(strlen($row) > 3){
+ $DB->query($row);
+ }
+ }
+
+ }
+
+
+}
+
+
+?>
\ No newline at end of file
Modified: trunk/catalog/admin/includes/classes/oscss_DBIndex.php
===================================================================
--- trunk/catalog/admin/includes/classes/oscss_DBIndex.php 2012-04-14 17:41:44 UTC (rev 4230)
+++ trunk/catalog/admin/includes/classes/oscss_DBIndex.php 2012-04-14 20:30:23 UTC (rev 4231)
@@ -9,10 +9,6 @@
@encode UTF-8
@brief Base manipulate and track all table in core osCSS.
Manage add /install / dusplique for multi-language
-
-
-
- Not used !!! In dev
*/
@@ -21,7 +17,7 @@
/**
@def path
*/
- const T_AVAILABLE = 'admin/origin/db/tables/';
+ const T_AVAILABLE = 'admin/origin/db/';
/**
@var
*/
@@ -31,6 +27,11 @@
@brief constructor
*/
function __construct(){
+ // load class manipulate fileSql
+ $this->DFS = new DataFileSql(DIR_FS_ROOT_DOCS . self::T_AVAILABLE);
+ // call instance datatype
+ $this->DT = DataTypes::getInstance();
+
// index all tables
$this->ListTablesAvailable();
@@ -45,59 +46,66 @@
@brief Browse Folder stock file define table
*/
function ListTablesAvailable(){
-// $contents = array();
+ $this->all['lang'] = array();
+ $this->all['DataType'] = array();
- foreach (scan(DIR_FS_ROOT_DOCS . self::T_AVAILABLE ) as $file ) {
+ foreach (scan(DIR_FS_ROOT_DOCS . self::T_AVAILABLE .'tables/' ) as $file ) {
if(substr($file, 0,1) =='.') continue;
-// var_dump($file);
+
+
$ext=substr($file,-3);
- $name = substr($file,0,-4);
-// var_dump($file.'-'.$name);
+ $name0 = substr($file,0,-4) ;
+ $name1 = preg_replace('/(OSC_)([A-Z])/i', '$2',$name0) ;
+ $name = preg_replace('/(OSC_)([A-Z])/i', DB_TABLE_PREFIX.'$2',$name0) ;
$key = false;
+ $datatype='';
+
if( ( $pos =strpos($name, '.')) > 0 && ($new_name = substr($name, 0, $pos))){
- $name = $new_name;
+ $name = trim($new_name);
$key = true;
}
+ foreach($this->DT->GetAllDataType() as $key=>$row) {
+ if(isset($row->db_tables) && in_array($name1,array_values($row->db_tables)))
+ $datatype .= $row->DataType.',' ;
+// elseif( preg_match('/('.strtoupper($row->DataType).')([A-Z])/i', $name ) )
+// $datatype .= $row->DataType.',' ;
+ }
+
if (in_array($ext, array('sql')) ){
$tmp = array(
'file'=>$file,
- 'name'=>$name ,
+ 'name'=> $name,
'extension'=>$ext,
'type'=>(($key) ? 't' : 'k' ),
'installed'=>'0',
'Rows'=>0,
+ 'keyPrim'=>'',
+ 'datatype'=>$datatype,
+ 'action'=>(!strpos($name, 'admin')),
);
- if($key){
+ $test=$this->DFS->AnalyseFile($file);
+
+ if($test !=false && $test->primary)
+ $tmp['keyPrim'] = $test->primarykey;
+
+ $this->all['table'][$name] = $tmp;
+
+
+ if($key && !in_array($name, array(DB_TABLE_PREFIX.'customers'))) {
/*
Traitement des clef et recherche des liaision vers la table language
Si une liaison existe, celle ci considere la table associé comme une table de langue et celle ci sera duspliqué lors de l'ajout d'une nouvelle language
*/
- $fp = fopen(DIR_FS_ROOT_DOCS . self::T_AVAILABLE .$file , 'rb');
- $test = array();
- while (!feof ($fp)) {
- $buf = fgets($fp, 4096);
- if (substr($buf, 0, 2) <> '--' ) {
- $buf=preg_match_all ('#(REFERENCES[ ]{1,}osc_languages[ ]{1,}[\(]languages_id[\)])#i' ,$buf, $match);
-// print_r($match);
- $test[]= ((count($match[0])>0)? true : false );
- }
- }
- fclose($fp);
-
- if(in_array(true,$test ))
+ if($test !=false && $test->language)
$this->all['lang'][$name] = $tmp;
}
- $this->all['table'][$name] = $tmp;
- }
-
+ }
}
-// sort($contents);
-
// foreach ($contents as $row ) {
// }$this->all =
@@ -111,40 +119,22 @@
function ListTablesInstalled(){
$DB = Database::getInstance();
-// $res = $DB->query('SHOW TABLES FROM '.DB_DATABASE );
-// // print_r($res->fetchAllAssoc() );
-// // exit;
-// foreach ($res->fetchAllAssoc() as $key=>$row ) {
-// $row = array_values($row);
-//
-// if(!isset($this->all['table'][$row[0]])){
-// $this->all['inconnue'][$row[0]]['name'] = $row[0];
-// $this->all['inconnue'][$row[0]]['installed'] = '1';
-// }
-// else
-// $this->all['table'][$row[0]]['installed'] = '1';
-//
-// }
-
$res = $DB->query('SHOW TABLE STATUS ' );
foreach ($res->fetchAllAssoc() as $key=>$row ) {
if(!isset($this->all['table'][$row['Name']])){
+
$this->all['inconnue'][$row['Name']] = $row;
- $this->all['inconnue'][$row['Name']]['name'] = $row;
+ $this->all['inconnue'][$row['Name']]['name'] = $row['Name'];
$this->all['inconnue'][$row['Name']]['installed'] = '1';
$this->all['inconnue'][$row['Name']]['Create_time'] = $row['Create_time'];
$this->all['inconnue'][$row['Name']]['Rows'] = (int)$row['Rows'];
}
else{
-// $row['Name']
$this->all['table'][$row['Name']]['Create_time'] = $row['Create_time'];
$this->all['table'][$row['Name']]['Rows'] =(int)$row['Rows'];
$this->all['table'][$row['Name']]['installed'] = '1';
-
-// print_r($res->fetchAllAssoc() );
-// exit;
}
}
Added: trunk/catalog/admin/includes/gabarit/backup/display_view.viewalldb.gab
===================================================================
--- trunk/catalog/admin/includes/gabarit/backup/display_view.viewalldb.gab (rev 0)
+++ trunk/catalog/admin/includes/gabarit/backup/display_view.viewalldb.gab 2012-04-14 20:30:23 UTC (rev 4231)
@@ -0,0 +1,130 @@
+<?php
+/**
+ @licence GPL 2005-2012 The osCSS developers - osCSS Open Source E-commerce
+ @portion code Copyright (c) 2002 osCommerce
+ @package osCSS-2 <www http://www.oscss.org>
+ @version 2.1.1
+ @date 26/03/2012, 17:29
+ @author oscim <mail aur...@os...> <www http://www.oscim.fr>
+ @encode UTF-8
+*/
+
+$DBIndex = new oscss_DBIndex();
+
+?>
+<?php echo tep_draw_form('backup', backup::FILENAME, 'action=backupnow') ?>
+<div class="box_uniq block_form">
+ <h3><?php echo __('text info heading backup view tables') ?></h3>
+
+
+ <div id="tabs">
+ <ul>
+ <li><a href="#tabs-1"><?php echo __('backup tab tables'); ?></a></li>
+ <li><a href="#tabs-2"><?php echo __('backup tab tables link language'); ?></a></li>
+ </ul>
+
+
+
+
+ <div id="tabs-1" class="tabPage">
+ <fieldset class="block_field">
+ <h3><?php echo __('backup title all tables available') ?></h3>
+ <table class="dataTableBase">
+ <thead>
+ <tr>
+ <th><?php echo __('table heading name'); ?></th>
+ <th><?php echo __('table heading datatype'); ?></th>
+ <th><?php echo __('table heading installed'); ?></th>
+ <th><?php echo __('table heading rows'); ?></th>
+ <th><?php echo __('table heading primary key'); ?></th>
+ <th><?php echo __('table heading action'); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php foreach($DBIndex->all['table'] as $row): ?>
+ <tr>
+ <td><?php echo $row['name'] ; ?></td>
+ <td><?php echo $row['datatype'] ; ?></td>
+ <td class="tcenter">
+ <span class="edit-input-value">
+ <span class="Val Flag-<?php echo $row['installed'] ?> txt"><?php echo (($row['installed'] ==1)? __('backup txt active') : __('backup txt inactive') ) ?></span>
+ <span class="Val Flag-<?php echo $row['installed'] ?> img"></span>
+ </span>
+ </td>
+ <td><?php echo $row['Rows'] ; ?></td>
+ <td><?php echo $row['keyPrim'] ; ?></td>
+ <td>
+ <?php if($row['action']): ?>
+ <?php echo '' ; ?></td>
+ <?php else: ?>
+ <?php echo 'N/C' ; ?></td>
+ <?php endif; ?>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+ </fieldset>
+
+ <h3><?php echo __('backup title tables installed and inconnue') ?></h3>
+ <table class="dataTableBase">
+ <thead>
+ <tr>
+ <th><?php echo __('table heading name'); ?></th>
+ <th><?php echo __('table heading installed'); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php foreach($DBIndex->all['inconnue'] as $row): ?>
+ <tr>
+ <td><?php echo $row['name'] ; ?></td>
+ <td class="tcenter">
+ <span class="edit-input-value">
+ <span class="Val Flag-<?php echo $row['installed'] ?> txt"><?php echo (($row['installed'] ==1)? __('backup txt active') : __('backup txt inactive') ) ?></span>
+ <span class="Val Flag-<?php echo $row['installed'] ?> img"></span>
+ </span>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+ </fieldset>
+ </div>
+
+
+ <div id="tabs-2" class="tabPage">
+ <fieldset class="block_field">
+ <h3><?php echo __('backup title all tables language') ?></h3>
+ <table class="dataTableBase">
+ <thead>
+ <tr>
+ <th><?php echo __('table heading name'); ?></th>
+ <th><?php echo __('table heading key used'); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php foreach($DBIndex->all['lang'] as $k=>$row): /*print_r($row);*/ ?>
+ <tr>
+ <td><?php echo $row['name'] ; ?></td>
+ <td><?php echo $DBIndex->all['table'][$k]['keyPrim'] ; ?></td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+ </fieldset>
+
+ </div>
+
+
+
+
+ <div class="button_nav">
+ <?php echo tep_image_submit('button_backup.gif', __('image backup')). tep_js_back(tep_href_link(backup::FILENAME), IMAGE_CANCEL);?>
+ </div>
+
+
+
+
+
+</div>
+
+</form>
\ No newline at end of file
Modified: trunk/catalog/admin/includes/languages/fr_FR/modules/pages/backup.txt
===================================================================
--- trunk/catalog/admin/includes/languages/fr_FR/modules/pages/backup.txt 2012-04-14 17:41:44 UTC (rev 4230)
+++ trunk/catalog/admin/includes/languages/fr_FR/modules/pages/backup.txt 2012-04-14 20:30:23 UTC (rev 4231)
@@ -1,10 +1,10 @@
<?php
/**
- @licence GPL 2005-2011 The osCSS developers - osCSS Open Source E-commerce
+ @licence GPL 2005-2012 The osCSS developers - osCSS Open Source E-commerce
@portion code Copyright (c) 2002 osCommerce
@package osCSS-2 <www http://www.oscss.org>
- @version 2.1.0
- @date 05/06/11, 18:10
+ @version 2.1.1
+ @date 26/03/2012, 17:29
@author oscim <mail aur...@os...> <www http://www.oscim.fr>
@encode UTF-8
*/
@@ -21,6 +21,7 @@
$lang['image backup']="Sauvegarde" ;
$lang['image db restore']="Restaurer" ;
$lang['image restore file ext']="Restaurer un fichier téléchargé" ;
+ $lang['image viewalldb']="Voir les tables" ;
/* backup */
$lang['text info heading new backup']="Nouvelle sauvegarde" ;
@@ -50,12 +51,23 @@
/* viewalldb */
- $lang['backup tab all tables available']="Toutes" ;
+
+ $lang['text info heading backup view tables']="Vues et operations sur les tables" ;
+
+ $lang['backup tab tables']="Toutes" ;
$lang['backup tab tables link language']="Langues" ;
+ $lang['backup title all tables available']="Les tables d'osCSS et ces modules" ;
+ $lang['backup title tables installed and inconnue']="Table(s) trouvée(s) non prise en charge" ;
+ $lang['backup title all tables language']="Tables liées à la table de language" ;
+
$lang['table heading name']="Nom" ;
$lang['table heading installed']="Installé" ;
- $lang['table heading Rows']="Nbr Lignes" ;
+ $lang['table heading rows']="Nbr Lignes" ;
+ $lang['table heading datatype']="DataType" ;
+ $lang['table heading primary key']="Clef Primaire" ;
+ $lang['table heading action']="" ;
+ $lang['table heading key used']="colonnes utilisées manip. language" ;
/* other */
Modified: trunk/catalog/common/classes/DataTypes.php
===================================================================
--- trunk/catalog/common/classes/DataTypes.php 2012-04-14 17:41:44 UTC (rev 4230)
+++ trunk/catalog/common/classes/DataTypes.php 2012-04-14 20:30:23 UTC (rev 4231)
@@ -108,7 +108,7 @@
/**
- @remarks Force er-init after define prev
+ @remarks Force re-init after define prev
*/
foreach($alltype as $test){
if(!empty($test)) {
@@ -119,8 +119,13 @@
}
/**
+ @brief Get all datatype
+ @note backoffice used
+ @return array
*/
-// public function Get
+ public function GetAllDataType(){
+ return self::$env->modlist;
+ }
/**
@@ -177,7 +182,6 @@
// Ajout des regles spcifique au datatype hierachique (categorie / naufacturer)
foreach(self::$env->modlist as $class=>$module){
-
if(
( isset(self::$env->RootListing[$class]) && is_array(self::$env->RootListing[$class]) && count(self::$env->RootListing[$class])>0 )// this module is RootListing (manufacturer, categories)
// && in_array($type, $module->RootListing) // RootListing array require content current type
@@ -187,9 +191,6 @@
// echo $class;
// print_r(self::$env->RootListing[$class]);
}
-
-
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|