Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1069344
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 19, 6:03 PM
Size
20 KB
Mime Type
text/x-diff
Expires
Mon, Jul 21, 6:03 PM (10 h, 11 m)
Engine
blob
Format
Raw Data
Handle
692268
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/unlabeled/unlabeled-1.8.64/admin/import/import_funcs.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.64/admin/import/import_funcs.php (revision 4336)
+++ branches/unlabeled/unlabeled-1.8.64/admin/import/import_funcs.php (revision 4337)
@@ -1,197 +1,199 @@
<?php
// Import script common functions
// ========================================================================================================
/**
* @return void
* @param Array $import_steps
* @desc Prints out step status information table
*/
function DrawScreen($import_steps)
{
global $objSession, $current_step;
$title = admin_language('la_performing_import').' - '.admin_language('la_Step').' 4';
int_header(null,NULL,$title);
$inner_table = '';
foreach($import_steps as $import_step) $inner_table .= PrintStep($import_step);
$is_count = count($import_steps);
int_table_color(1);
$RowColor = int_table_color(0, true);
echo <<<SCREEN_END
<form id="import_form" action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableborder">
<tr $RowColor>
<td width="1000000"> </td>
<td rowspan="$is_count" align="center">
<img src="img/s.gif" height="0" width="500">
<table width="100%" border="0" cellspacing="0">
$inner_table
</table>
</td>
<td width="1000000"> </td>
</tr>
SCREEN_END;
$i = 1;
while($i < $is_count)
{
echo PrintDummy();
$i++;
}
$run_time = GetMC() - $objSession->GetVariable('import_begins');
$run_time .= 's';
int_subsection_title( admin_language("la_performing_import").' - '.$current_step['caption'].'...', 3);
$RowColor = int_table_color(0, true);
echo <<<SCREEN_END
<tr $RowColor>
<td colspan="3">Script Running: $run_time</td>
</tr>
</table>
</form>
SCREEN_END;
int_footer();
flush();
}
/**
* @return string
* @param Array $step_rec
* @desc Returns one row of step-info table
*/
function PrintStep($step_rec)
{
$step_rec['percent'] = round( ($step_rec['rec_no'] / $step_rec['recs_count']) * 100, 2);
$step_rec['details'] = '('.$step_rec['rec_no'].' of '.$step_rec['recs_count'].')';
return '
<tr '.int_table_color(0, true).'>
<td width="50%" valign="top"><span class="text">'.$step_rec['caption'].'</span></td>
<td width="50%">
<span class="text">'.$step_rec['percent'].'</span>% '.$step_rec['details'].'</span>
</td>
</tr>';
}
/**
* @return void
* @param Array $import_steps
* @desc Save step info to database
*/
function DumpStepsInfo($import_steps)
{
global $dst_db, $ImportTable, $cache;
$sql = 'UPDATE '.$ImportTable.' SET bbi_rec_no = %s, bbi_recs_count = %s, bbi_current = %s, bbi_cache = %s WHERE bbi_step = \'%s\'';
foreach ($import_steps as $istep)
{
$sc = serialize( $cache[ $istep['id'] ] );
$tmp = sprintf($sql, $istep['rec_no'], $istep['recs_count'], $istep['current'], $dst_db->qstr($sc), $istep['id']);
$dst_db->Execute($tmp);
}
}
/**
* @return void
* @param Array $step_info
* @param Array $import_steps
* @desc Redirects to next step or continues this step
*/
function StepRedirect($step_info)
{
global $rootURL, $admin, $StepIndex, $import_steps, $dst_db, $db, $ImportTable, $objCatList;
if($step_info['rec_no'] == $step_info['recs_count'])
{
$import_steps[ $step_info['id'] ]['current'] = 0;
$NewCurrent = array_search( $step_info['id'], $StepIndex) + 1;
if( array_key_exists($NewCurrent, $StepIndex) )
{
$import_steps[ $StepIndex[$NewCurrent] ]['current'] = 1;
}
else
{
global $objSession, $adminURL;
$objSession->SetVariable('PermCache_UpdateRequired', 1);
$objSession->SetVariable('ReturnScript', 'browse.php'); // redirect to catalog when finished
// $NumCats = TableCount($objCatList->SourceTable,'',0);
$dst_db->Execute('DROP TABLE IF EXISTS '.$ImportTable);
$db->Close();
+
+ m_ParseEnv(); // sets default values to "m" prefix, because it is not passed through import anymore
echo '<script>window.location = "'.$adminURL.'/category/category_maint.php?env='.BuildEnv().'&force=1";</script>';
}
}
DumpStepsInfo($import_steps);
echo '<script>window.location = "'.$rootURL.'in-bulletin/'.$admin.'/import/phpbb_import.php?env='.BuildEnv().'";</script>';
}
// ========================================================================================================
function GetStepName($step_id)
{
global $import_steps;
$ret = '';
foreach($import_steps as $istep)
if($istep['id'] == $step_id)
{
$ret = $istep['caption'];
break;
}
return $ret;
}
function PrintDummy()
{
return '<tr '.int_table_color(0, true).'>
<td> </td>
<td> </td>
</tr>';
}
function GetMC()
{
$tmp = explode(' ', microtime() );
return $tmp[1];
}
function SetPersistantVariable($user_id, $var_name, $var_value)
{
global $dst_db;
$sql_template = "REPLACE INTO ".GetTablePrefix()."PersistantSessionData (PortalUserId, VariableName, VariableValue) VALUES (%s,'%s','%s')";
$dst_db->Execute( sprintf($sql_template, $user_id, $var_name, addslashes($var_value) ) );
}
function DecodeIP($ip)
{
$i = 0;
$ip_len = strlen($ip);
$ip_parts = Array();
while($i < $ip_len)
{
$ip_parts[] = hexdec( substr($ip, $i, 2) );
$i += 2;
}
return implode('.', $ip_parts);
}
function GetUserID($old_user_id)
{
global $cache;
return $cache['users'][ $old_user_id ]['new_id'];
}
function GetUserName($old_user_id)
{
global $cache;
return $cache['users'][ $old_user_id ]['username'];
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.64/admin/import/import_funcs.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.8
\ No newline at end of property
+1.8.64.1
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.3.2/kernel/units/general/helpers/multilanguage.php
===================================================================
--- branches/unlabeled/unlabeled-1.3.2/kernel/units/general/helpers/multilanguage.php (revision 4336)
+++ branches/unlabeled/unlabeled-1.3.2/kernel/units/general/helpers/multilanguage.php (revision 4337)
@@ -1,205 +1,210 @@
<?php
/**
* Performs action on multilingual fields
*
*/
class kMultiLanguageHelper extends kHelper {
var $languageCount = 0;
/**
* Structure of table, that is currently processed
*
* @var Array
*/
var $curStructure = Array();
/**
* Field, to get structure information from
*
* @var string
*/
var $curSourceField = false;
/**
* Fields from config, that are currently used
*
* @var Array
*/
var $curFields = Array();
function kMultiLanguageHelper()
{
parent::kHelper();
$this->languageCount = $this->getLanguageCount();
}
/**
* Returns language count in system (always is divisible by 5)
*
*/
function getLanguageCount()
{
$table_name = $this->Application->getUnitOption('lang', 'TableName');
$languages_count = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$table_name);
if (!$languages_count) {
// during installation we have not languages, but we need to created custom field columns
$languages_count = 1;
}
return $languages_count + 5 - ( $languages_count % 5 ? ($languages_count % 5) : 5 );
}
function scanTable($mask)
{
$i = 0;
$fields_found = 0;
$fields = array_keys($this->curStructure);
foreach ($fields as $field_name) {
if (preg_match($mask, $field_name)) {
$fields_found++;
}
}
return $fields_found;
}
function readTableStructure($table_name)
{
static $structure_status = Array();
if (!getArrayValue($structure_status, $table_name)) {
$this->curStructure = $this->Conn->Query('DESCRIBE '.$table_name, 'Field');
$structure_status[$table_name] = true;
}
}
/**
* Creates missing multilanguage fields in table by specified prefix
*
* @param string $prefix
+ * @param bool $refresh Forces config field structure to be re-read from database
*/
- function createFields($prefix)
+ function createFields($prefix, $refresh = false)
{
+ if ($refresh) {
+ $this->Application->HandleEvent( new kEvent($prefix.':OnCreateCustomFields') );
+ }
+
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$this->curFields = $this->Application->getUnitOption($prefix, 'Fields');
if (!($table_name && $this->curFields) ) {
// invalid config found or prefix not found
return true;
}
$sqls = Array();
foreach($this->curFields as $field_name => $field_options)
{
if (getArrayValue($field_options, 'formatter') == 'kMultiLanguage') {
$this->readTableStructure($table_name);
$created_count = $this->getCreatedCount($field_name);
$create_count = $this->languageCount - $created_count;
if ($create_count > 0) {
// `l77_Name` VARCHAR( 255 ) NULL DEFAULT '0';
$field_mask = Array();
$field_mask['name'] = 'l%s_'.$field_name;
$field_mask['null'] = getArrayValue($field_options, 'not_null') ? 'NOT NULL' : 'NULL';
if ($this->curSourceField) {
$default_value = $this->getFieldParam('Default') != 'NULL' ? $this->Conn->qstr($this->getFieldParam('Default')) : $this->getFieldParam('Default');
$field_mask['type'] = $this->getFieldParam('Type');
}
else {
$default_value = is_null($field_options['default']) ? 'NULL' : $this->Conn->qstr($field_options['default']);
$field_mask['type'] = $field_options['db_type'];
}
$field_mask['default'] = 'DEFAULT '.$default_value;
$field_mask = $field_mask['name'].' '.$field_mask['type'].' '.$field_mask['null'].' '.$field_mask['default'];
$sqls[] = 'ALTER TABLE '.$table_name.( $this->generateAlterSQL($field_mask, $created_count + 1, $create_count) );
}
}
}
foreach ($sqls as $sql_query) {
$this->Conn->Query($sql_query);
}
}
function deleteField($prefix, $custom_id)
{
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$sql = 'DESCRIBE '.$table_name.' "l%_cust_'.$custom_id.'"';
$fields = $this->Conn->GetCol($sql);
$sql = 'ALTER TABLE '.$table_name.' ';
$sql_template = 'DROP COLUMN %s, ';
foreach ($fields as $field_name) {
$sql .= sprintf($sql_template, $field_name);
}
$sql = preg_replace('/(.*), $/', '\\1', $sql);
$this->Conn->Query($sql);
}
/**
* Returns parameter requested of current source field
*
* @param string $param_name
* @return string
*/
function getFieldParam($param_name)
{
return $this->curStructure[$this->curSourceField][$param_name];
}
function getCreatedCount($field_name)
{
$ret = $this->scanTable('/^l[\d]+_'.preg_quote($field_name, '/').'/');
if (!$ret) {
// no multilingual fields at all (but we have such field without language prefix)
$original_found = $this->scanTable('/'.preg_quote($field_name, '/').'/');
$this->curSourceField = $original_found ? $field_name : false;
}
else {
$this->curSourceField = 'l1_'.$field_name;
}
return $ret;
}
/**
* Returns ALTER statement part for adding required fields to table
*
* @param string $field_mask sql mask for creating field with correct definition (type & size)
* @param int $start_index add new fields starting from this index
* @param int $create_count create this much new multilingual field translations
* @return string
*/
function generateAlterSQL($field_mask, $start_index, $create_count)
{
$i_count = $start_index + $create_count;
$ret = ' ';
while ($start_index < $i_count) {
list($prev_field,$type) = explode(' ', sprintf($field_mask, $start_index - 1) );
if (substr($prev_field, 0, 3) == 'l0_') {
$prev_field = substr($prev_field, 3, strlen($prev_field));
if (!$this->curSourceField) {
// get field name before this one
$fields = array_keys($this->curFields);
$prev_field = $fields[array_search($prev_field, $fields) - 1];
if (getArrayValue($this->curFields[$prev_field], 'formatter') == 'kMultiLanguage') {
$prev_field = 'l'.$this->languageCount.'_'.$prev_field;
}
}
}
$field_expression = sprintf($field_mask, $start_index);
$ret .= 'ADD COLUMN '.$field_expression.' AFTER `'.$prev_field.'`, ';
list($field_name, $field_params) = explode(' ', $field_expression, 2);
$ret .= 'ADD INDEX (`'.$field_name.'` (5) ), ';
$start_index++;
}
return preg_replace('/, $/',';',$ret);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.3.2/kernel/units/general/helpers/multilanguage.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3.2.1
\ No newline at end of property
+1.3.2.2
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/multilanguage.php
===================================================================
--- branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/multilanguage.php (revision 4336)
+++ branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/multilanguage.php (revision 4337)
@@ -1,205 +1,210 @@
<?php
/**
* Performs action on multilingual fields
*
*/
class kMultiLanguageHelper extends kHelper {
var $languageCount = 0;
/**
* Structure of table, that is currently processed
*
* @var Array
*/
var $curStructure = Array();
/**
* Field, to get structure information from
*
* @var string
*/
var $curSourceField = false;
/**
* Fields from config, that are currently used
*
* @var Array
*/
var $curFields = Array();
function kMultiLanguageHelper()
{
parent::kHelper();
$this->languageCount = $this->getLanguageCount();
}
/**
* Returns language count in system (always is divisible by 5)
*
*/
function getLanguageCount()
{
$table_name = $this->Application->getUnitOption('lang', 'TableName');
$languages_count = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$table_name);
if (!$languages_count) {
// during installation we have not languages, but we need to created custom field columns
$languages_count = 1;
}
return $languages_count + 5 - ( $languages_count % 5 ? ($languages_count % 5) : 5 );
}
function scanTable($mask)
{
$i = 0;
$fields_found = 0;
$fields = array_keys($this->curStructure);
foreach ($fields as $field_name) {
if (preg_match($mask, $field_name)) {
$fields_found++;
}
}
return $fields_found;
}
function readTableStructure($table_name)
{
static $structure_status = Array();
if (!getArrayValue($structure_status, $table_name)) {
$this->curStructure = $this->Conn->Query('DESCRIBE '.$table_name, 'Field');
$structure_status[$table_name] = true;
}
}
/**
* Creates missing multilanguage fields in table by specified prefix
*
* @param string $prefix
+ * @param bool $refresh Forces config field structure to be re-read from database
*/
- function createFields($prefix)
+ function createFields($prefix, $refresh = false)
{
+ if ($refresh) {
+ $this->Application->HandleEvent( new kEvent($prefix.':OnCreateCustomFields') );
+ }
+
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$this->curFields = $this->Application->getUnitOption($prefix, 'Fields');
if (!($table_name && $this->curFields) ) {
// invalid config found or prefix not found
return true;
}
$sqls = Array();
foreach($this->curFields as $field_name => $field_options)
{
if (getArrayValue($field_options, 'formatter') == 'kMultiLanguage') {
$this->readTableStructure($table_name);
$created_count = $this->getCreatedCount($field_name);
$create_count = $this->languageCount - $created_count;
if ($create_count > 0) {
// `l77_Name` VARCHAR( 255 ) NULL DEFAULT '0';
$field_mask = Array();
$field_mask['name'] = 'l%s_'.$field_name;
$field_mask['null'] = getArrayValue($field_options, 'not_null') ? 'NOT NULL' : 'NULL';
if ($this->curSourceField) {
$default_value = $this->getFieldParam('Default') != 'NULL' ? $this->Conn->qstr($this->getFieldParam('Default')) : $this->getFieldParam('Default');
$field_mask['type'] = $this->getFieldParam('Type');
}
else {
$default_value = is_null($field_options['default']) ? 'NULL' : $this->Conn->qstr($field_options['default']);
$field_mask['type'] = $field_options['db_type'];
}
$field_mask['default'] = 'DEFAULT '.$default_value;
$field_mask = $field_mask['name'].' '.$field_mask['type'].' '.$field_mask['null'].' '.$field_mask['default'];
$sqls[] = 'ALTER TABLE '.$table_name.( $this->generateAlterSQL($field_mask, $created_count + 1, $create_count) );
}
}
}
foreach ($sqls as $sql_query) {
$this->Conn->Query($sql_query);
}
}
function deleteField($prefix, $custom_id)
{
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
$sql = 'DESCRIBE '.$table_name.' "l%_cust_'.$custom_id.'"';
$fields = $this->Conn->GetCol($sql);
$sql = 'ALTER TABLE '.$table_name.' ';
$sql_template = 'DROP COLUMN %s, ';
foreach ($fields as $field_name) {
$sql .= sprintf($sql_template, $field_name);
}
$sql = preg_replace('/(.*), $/', '\\1', $sql);
$this->Conn->Query($sql);
}
/**
* Returns parameter requested of current source field
*
* @param string $param_name
* @return string
*/
function getFieldParam($param_name)
{
return $this->curStructure[$this->curSourceField][$param_name];
}
function getCreatedCount($field_name)
{
$ret = $this->scanTable('/^l[\d]+_'.preg_quote($field_name, '/').'/');
if (!$ret) {
// no multilingual fields at all (but we have such field without language prefix)
$original_found = $this->scanTable('/'.preg_quote($field_name, '/').'/');
$this->curSourceField = $original_found ? $field_name : false;
}
else {
$this->curSourceField = 'l1_'.$field_name;
}
return $ret;
}
/**
* Returns ALTER statement part for adding required fields to table
*
* @param string $field_mask sql mask for creating field with correct definition (type & size)
* @param int $start_index add new fields starting from this index
* @param int $create_count create this much new multilingual field translations
* @return string
*/
function generateAlterSQL($field_mask, $start_index, $create_count)
{
$i_count = $start_index + $create_count;
$ret = ' ';
while ($start_index < $i_count) {
list($prev_field,$type) = explode(' ', sprintf($field_mask, $start_index - 1) );
if (substr($prev_field, 0, 3) == 'l0_') {
$prev_field = substr($prev_field, 3, strlen($prev_field));
if (!$this->curSourceField) {
// get field name before this one
$fields = array_keys($this->curFields);
$prev_field = $fields[array_search($prev_field, $fields) - 1];
if (getArrayValue($this->curFields[$prev_field], 'formatter') == 'kMultiLanguage') {
$prev_field = 'l'.$this->languageCount.'_'.$prev_field;
}
}
}
$field_expression = sprintf($field_mask, $start_index);
$ret .= 'ADD COLUMN '.$field_expression.' AFTER `'.$prev_field.'`, ';
list($field_name, $field_params) = explode(' ', $field_expression, 2);
$ret .= 'ADD INDEX (`'.$field_name.'` (5) ), ';
$start_index++;
}
return preg_replace('/, $/',';',$ret);
}
}
?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/multilanguage.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3.2.1
\ No newline at end of property
+1.3.2.2
\ No newline at end of property
Event Timeline
Log In to Comment