Commit bbed4c9a authored by Sigrid Suski's avatar Sigrid Suski

(#) Template installation does not handle select lists with parent groups correctly

	usage of Framework
parent cd0006fd
......@@ -51,6 +51,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
(#) Uploading images with uppercase extensions (Issue #135)
(#) Show correct uninstallation message for modules and plugins when uninstalling via SobiPro application messenger
(#) Template installation does not add the icon fonts correctly
(#) Template installation does not handle select lists with parent groups correctly
### 1.4.8 (14 September 2018)
......
......@@ -324,7 +324,6 @@ class SPTemplateInstaller extends SPInstaller
}
}
/**
* @param DOMElement $field
* @param array $data
......@@ -399,14 +398,15 @@ class SPTemplateInstaller extends SPInstaller
$values = [];
foreach ( $options as $option ) {
$id = strlen( $option->getAttribute( 'name' ) ) ? $option->getAttribute( 'name' ) : 0;
if ( strlen( $option->getAttribute( 'group' ) ) && $option->getAttribute( 'group' ) != 'root' ) {
if ( !( isset( $values[ $option->getAttribute( 'group' ) ] ) ) ) {
$values[ $option->getAttribute( 'group' ) ] = [ 'gid' => $option->getAttribute( 'group' ), 'name' => $option->getAttribute( 'group' ) ];
}
$values[ $option->getAttribute( 'group' ) ][] = [ 'id' => $id, 'name' => $option->nodeValue ];
}
elseif ( $id ) {
$values[] = [ 'id' => $id, 'name' => $option->nodeValue ];
$parent = strlen( $option->getAttribute( 'parent' ) ) ? $option->getAttribute( 'parent' ) : null;
// if ( strlen( $option->getAttribute( 'group' ) ) && $option->getAttribute( 'group' ) != 'root' ) {
// if ( !( isset( $values[ $option->getAttribute( 'group' ) ] ) ) ) {
// $values[ $option->getAttribute( 'group' ) ] = [ 'gid' => $option->getAttribute( 'group' ), 'name' => $option->getAttribute( 'group' ) ];
// }
// $values[ $option->getAttribute( 'group' ) ][] = [ 'id' => $id, 'name' => $option->nodeValue ];
// }
if ( $id ) {
$values[] = [ 'id' => $id, 'name' => $option->nodeValue, 'parent' => $parent ];
}
else {
$addOptions[ $option->parentNode->getAttribute( 'attribute' ) ][] = $option->nodeValue;
......
<?php
/**
* @version: $Id$
* @package: SobiPro Component for Joomla!
*
* @author
* Name: Sigrid Suski & Radek Suski, Sigsiu.NET GmbH
* Email: sobi[at]sigsiu.net
* Url: http://www.Sigsiu.NET
* @copyright Copyright (C) 2006 - 2015 Sigsiu.NET GmbH (http://www.sigsiu.net). All rights reserved.
* Url: https://www.Sigsiu.NET
*
* @copyright Copyright (C) 2006 - 2018 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @license GNU/GPL Version 3
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
* See http://www.gnu.org/licenses/gpl.html and https://www.sigsiu.net/licenses.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* $Date$
* $Revision$
* $Author$
* $HeadURL$
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
* See https://www.gnu.org/licenses/gpl.html and https://www.sigsiu.net/licenses.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
use \Sobi\Input\Input;
use Sobi\FileSystem\Archive;
use Sobi\FileSystem\FileSystem;
defined( 'SOBIPRO' ) || exit( 'Restricted access' );
SPLoader::loadClass( 'opt.fields.select' );
......@@ -27,6 +31,12 @@ SPLoader::loadClass( 'opt.fields.select' );
*/
class SPField_SelectAdm extends SPField_Select
{
/**
* @param $attr
*
* @throws SPException
* @throws \Sobi\Error\Exception
*/
public function save( &$attr )
{
static $lang = null;
......@@ -38,7 +48,7 @@ class SPField_SelectAdm extends SPField_Select
$lang = Sobi::Lang();
$defLang = Sobi::DefLang();
}
$file = SPRequest::file( 'spfieldsopts', 'tmp_name' );
$file = Input::File( 'spfieldsopts', 'tmp_name' );
if ( $file ) {
$data = parse_ini_file( $file, true );
}
......@@ -62,7 +72,7 @@ class SPField_SelectAdm extends SPField_Select
while ( isset( $hold[ $oid ] ) ) {
$oid = $o[ 'id' ] . '_' . ++$i;
}
$options[ ] = [ 'id' => $oid, 'name' => $o[ 'name' ], 'parent' => null, 'position' => ++$p ];
$options[] = [ 'id' => $oid, 'name' => $o[ 'name' ], 'parent' => $o[ 'parent' ], 'position' => ++$p ];
$hold[ $oid ] = $oid;
}
}
......@@ -81,14 +91,14 @@ class SPField_SelectAdm extends SPField_Select
continue;
}
if ( $option[ 'id' ] == $opt[ 'id' ] ) {
$option[ 'id' ] = $option[ 'id' ] . '_' . substr( ( string )microtime(), 2, 8 ) . rand( 1, 100 );
$option[ 'id' ] = $option[ 'id' ] . '_' . substr( ( string ) microtime(), 2, 8 ) . rand( 1, 100 );
$duplicates = true;
}
}
$optionsArr[ ] = [ 'fid' => $this->id, 'optValue' => $option[ 'id' ], 'optPos' => $option[ 'position' ], 'optParent' => $option[ 'parent' ] ];
$defLabelsArr[ ] = [ 'sKey' => $option[ 'id' ], 'sValue' => $option[ 'name' ], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id ];
$labelsArr[ ] = [ 'sKey' => $option[ 'id' ], 'sValue' => $option[ 'name' ], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id ];
$optsIds[ ] = $option[ 'id' ];
$optionsArr[] = [ 'fid' => $this->id, 'optValue' => $option[ 'id' ], 'optPos' => $option[ 'position' ], 'optParent' => $option[ 'parent' ] ];
$defLabelsArr[] = [ 'sKey' => $option[ 'id' ], 'sValue' => $option[ 'name' ], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id ];
$labelsArr[] = [ 'sKey' => $option[ 'id' ], 'sValue' => $option[ 'name' ], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id ];
$optsIds[] = $option[ 'id' ];
}
if ( $duplicates ) {
SPFactory::message()->warning( 'FIELD_WARN_DUPLICATE_OPT_ID' );
......@@ -99,7 +109,8 @@ class SPField_SelectAdm extends SPField_Select
$db->delete( 'spdb_field_option', [ 'fid' => $this->id ] );
$db->delete( 'spdb_language', [ 'oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage() ), SPC::ERROR, 500, __LINE__, __FILE__ );
}
/* insert new values */
......@@ -110,7 +121,8 @@ class SPField_SelectAdm extends SPField_Select
$db->insertArray( 'spdb_language', $defLabelsArr, false, true );
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage() ), SPC::ERROR, 500, __LINE__, __FILE__ );
}
}
......@@ -125,18 +137,19 @@ class SPField_SelectAdm extends SPField_Select
}
}
$this->sets[ 'field.options' ] = SPFactory::Instance( 'types.array' )
->toINIString( $data );
->toINIString( $data );
/** handle upload of new definition file */
$XMLFile = SPRequest::file( 'select-list-dependency', 'tmp_name' );
$XMLFile = Input::File( 'select-list-dependency', 'tmp_name' );
if ( $XMLFile && file_exists( $XMLFile ) ) {
$XMLFileName = SPRequest::file( 'select-list-dependency', 'name' );
if ( SPFs::getExt( $XMLFileName ) == 'zip' ) {
$arch = SPFactory::Instance( 'base.fs.archive' );
$XMLFileName = Input::File( 'select-list-dependency', 'name' );
if ( FileSystem::GetExt( $XMLFileName ) == 'zip' ) {
// $arch = SPFactory::Instance( 'base.fs.archive' );
$arch = new Archive();
$name = str_replace( '.zip', null, $XMLFileName );
$path = SPLoader::dirPath( 'tmp.install.' . $name, 'front', false );
$c = 0;
while ( SPFs::exists( $path ) ) {
while ( FileSystem::Exists( $path ) ) {
$path = SPLoader::dirPath( 'tmp.install.' . $name . '_' . ++$c, 'front', false );
}
$arch->upload( $XMLFile, $path . '/' . $XMLFileName );
......@@ -144,24 +157,24 @@ class SPField_SelectAdm extends SPField_Select
$files = scandir( $path );
if ( count( $files ) ) {
foreach ( $files as $defFile ) {
switch ( SPFs::getExt( $defFile ) ) {
switch ( FileSystem::GetExt( $defFile ) ) {
case 'xml':
$properties[ 'dependencyDefinition' ] = $defFile;
SPFs::move( $path . '/' . $defFile, SOBI_PATH . '/etc/fields/select-list/' . $defFile );
FileSystem::Move( $path . '/' . $defFile, SOBI_PATH . '/etc/fields/select-list/' . $defFile );
break;
case 'ini':
$defLang = explode( '.', $defFile );
$defLang = $defLang[ 0 ];
if ( file_exists( SOBI_ROOT . '/language/' . $defLang ) ) {
SPFs::move( $path . '/' . $defFile, SOBI_ROOT . '/language/' . $defLang . '/' . $defFile );
FileSystem::Move( $path . '/' . $defFile, SOBI_ROOT . '/language/' . $defLang . '/' . $defFile );
}
break;
}
}
}
}
elseif ( SPFs::getExt( $XMLFileName ) == 'xml' ) {
if ( SPFs::upload( $XMLFile, SOBI_PATH . '/etc/fields/select-list/' . $XMLFileName ) ) {
elseif ( FileSystem::GetExt( $XMLFileName ) == 'xml' ) {
if ( FileSystem::Upload( $XMLFile, SOBI_PATH . '/etc/fields/select-list/' . $XMLFileName ) ) {
$properties[ 'dependencyDefinition' ] = $XMLFileName;
}
}
......@@ -175,6 +188,11 @@ class SPField_SelectAdm extends SPField_Select
$this->saveSelectLabel( $attr );
}
/**
* @param $file
*
* @throws \Sobi\Error\Exception
*/
protected function parseDependencyDefinition( $file )
{
$dom = new DOMDocument();
......@@ -186,7 +204,7 @@ class SPField_SelectAdm extends SPField_Select
$definition[ 'translation' ] = $root->item( 0 )->attributes->getNamedItem( 'translation' )->nodeValue;
$definition[ 'options' ] = [];
$this->_parseXML( $xpath->query( '/definition/option' ), $definition[ 'options' ] );
SPFs::write( SOBI_PATH . '/etc/fields/select-list/definitions/' . ( str_replace( '.xml', '.json', $file ) ), json_encode( $definition ) );
FileSystem::Write( SOBI_PATH . '/etc/fields/select-list/definitions/' . ( str_replace( '.xml', '.json', $file ) ), json_encode( $definition ) );
}
/**
......@@ -200,8 +218,8 @@ class SPField_SelectAdm extends SPField_Select
continue;
}
$option = [
'id' => $node->attributes->getNamedItem( 'id' )->nodeValue,
'childs' => []
'id' => $node->attributes->getNamedItem( 'id' )->nodeValue,
'childs' => [],
];
if ( $node->attributes->getNamedItem( 'child-type' ) ) {
$option[ 'child-type' ] = $node->attributes->getNamedItem( 'child-type' )->nodeValue;
......@@ -213,13 +231,17 @@ class SPField_SelectAdm extends SPField_Select
}
}
/**
*
*/
public function delete()
{
/* @var SPdb $db */
$db = SPFactory::db();
try {
$db->delete( 'spdb_field_option', [ 'fid' => $this->id ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment