Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function appendPreferences($context){
$group->appendChild(new XMLElement('legend', __('Export Ensemble')));


$div = new XMLElement('div', NULL, array('id' => 'file-actions', 'class' => 'label'));
$span = new XMLElement('span', NULL, array('class' => 'frame'));
$div = new XMLElement('div', null, array('id' => 'file-actions', 'class' => 'label'));
$span = new XMLElement('span', null, array('class' => 'frame'));

$span->appendChild(new XMLElement('button', __('Save Install Files'), array('name' => 'action[save-install-files]', 'type' => 'submit')));

Expand Down Expand Up @@ -119,17 +119,17 @@ private function __saveInstallFiles(){
$config_template = $this->__createDefaultConfigFile();

// Write the install files
if(FALSE !== @file_put_contents(DOCROOT . '/install/includes/install.sql', $sql_schema));
if(false !== @file_put_contents(DOCROOT . '/install/includes/install.sql', $sql_schema));
else {
Administration::instance()->Page->pageAlert(__('An error occurred while trying to write the <code>install.sql</code> file. Check the file permissions.'), Alert::ERROR);
return;
}
if(FALSE !== @file_put_contents(DOCROOT . '/install/includes/config_default.php', $config_template));
if(false !== @file_put_contents(DOCROOT . '/install/includes/config_default.php', $config_template));
else {
Administration::instance()->Page->pageAlert(__('An error occurred while trying to write the <code>config_default.php</code> file. Check the file permissions.'), Alert::ERROR);
return;
}
if(FALSE !== @file_put_contents(DOCROOT . '/workspace/install.sql', $sql_data));
if(false !== @file_put_contents(DOCROOT . '/workspace/install.sql', $sql_data));
else {
Administration::instance()->Page->pageAlert(__('An error occurred while trying to write the <code>workspace/install.sql</code> file. Check the file permissions.'), Alert::ERROR);
return;
Expand Down Expand Up @@ -209,7 +209,7 @@ private function __getDataTables($data_tables){

private function __dumpSchema($dump, $structure_tables, $tbl_prefix){
// Create variables for the dump files
$sql_schema = NULL;
$sql_schema = null;

// Grab the schema
foreach($structure_tables as $t) $sql_schema .= $dump->export($t, MySQLDump::STRUCTURE_ONLY);
Expand All @@ -221,14 +221,14 @@ private function __dumpSchema($dump, $structure_tables, $tbl_prefix){
);

// Remove any AUTO_INCREMENT counts
$sql_schema = preg_replace('/AUTO_INCREMENT=\d+/i', NULL, $sql_schema);
$sql_schema = preg_replace('/AUTO_INCREMENT=\d+/i', null, $sql_schema);

return $sql_schema;
}

private function __dumpData($dump, $data_tables, $tbl_prefix){
// Create variables for the dump files
$sql_data = NULL;
$sql_data = null;

// Field data and entry data schemas needs to be apart of the workspace sql dump
$sql_data = $dump->export('tbl_fields_%', MySQLDump::ALL);
Expand Down Expand Up @@ -280,7 +280,7 @@ private function __createZipArchive($config_template, $sql_schema, $sql_data){
$archive = new ZipArchive;
$res = $archive->open(TMP . '/ensemble.tmp.zip', ZipArchive::CREATE);

if ($res === TRUE) {
if ($res === true) {
$this->__addFolderToArchive($archive, 'extensions', DOCROOT);
$this->__addFolderToArchive($archive, 'symphony', DOCROOT);
$this->__addFolderToArchive($archive, 'workspace', DOCROOT);
Expand Down Expand Up @@ -329,7 +329,7 @@ private function __createZipArchive($config_template, $sql_schema, $sql_data){
}
}

private function __addFolderToArchive(&$archive, $path, $parent=NULL){
private function __addFolderToArchive(&$archive, $path, $parent = null){
$iterator = new DirectoryIterator($path);
foreach($iterator as $file){
if($file->isDot() || preg_match('/^\./', $file->getFilename())) continue;
Expand All @@ -338,7 +338,7 @@ private function __addFolderToArchive(&$archive, $path, $parent=NULL){
$this->__addFolderToArchive($archive, $file->getPathname(), $parent);
}

else $archive->addFile($file->getPathname(), ltrim(str_replace($parent, NULL, $file->getPathname()), '/'));
else $archive->addFile($file->getPathname(), ltrim(str_replace($parent, null, $file->getPathname()), '/'));
}
}
}
5 changes: 4 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
</author>
</authors>
<releases>
<release version="3.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Updated for Symphony 4.x
</release>
<release version="2.2.1" date="2016-10-06" min="2.6.0" max="2.6.x">
- Updated Russian translation
</release>
Expand Down Expand Up @@ -109,4 +112,4 @@
- Moved `installer.tpl`, found in the main S2 repository, into the /lib folder
</release>
</releases>
</extension>
</extension>
48 changes: 24 additions & 24 deletions lib/class.mysqldump.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php

Class MySQLDump{

const DATA_ONLY = 1;
const STRUCTURE_ONLY = 2;
const ALL = 3;
const CRLF = "\r\n";

private $_connection;

public function __construct(MySQL $connection){
$this->_connection = $connection;
}

public function export($match=null, $flag=self::ALL, $condition=NULL){
$data = NULL;
public function export($match = null, $flag = self::ALL, $condition = null){
$data = null;

$tables = $this->__getTables($match);
foreach ($tables as $name => $info){

if($flag == self::ALL || $flag == self::STRUCTURE_ONLY){
$data .= self::CRLF . "-- *** STRUCTURE: `{$name}` ***" . self::CRLF;
$data .= "DROP TABLE IF EXISTS `{$name}`;" . self::CRLF;
$data .= $this->__dumpTableSQL($name, $info['type'], $info['fields'], $info['indexes']);
}

if($flag == self::ALL || $flag == self::DATA_ONLY){
$data .= self::CRLF . "-- *** DATA: `$name` ***" . self::CRLF;
if(strtoupper($info['type']) == 'INNODB'){
$data .= 'SET FOREIGN_KEY_CHECKS = 0;' . self::CRLF;
}

$data .= $this->__dumpTableData ($name, $info['fields'], $condition);
if(strtoupper($info['type']) == 'INNODB'){
$data .= 'SET FOREIGN_KEY_CHECKS = 1;' . self::CRLF;
Expand All @@ -40,41 +40,41 @@ public function export($match=null, $flag=self::ALL, $condition=NULL){

return $data;
}
private function __dumpTableData($name, $fields, $condition=NULL){

private function __dumpTableData($name, $fields, $condition = null){
$fieldList = join (', ', array_map (create_function ('$x', 'return "`$x`";'), array_keys ($fields)));

$query = "SELECT {$fieldList} FROM `{$name}`";

if(!is_null($condition)){
$query .= ' WHERE ' . $condition;
}

$rows = $this->_connection->fetch ($query);

$value = NULL;
$value = null;

if(!is_array($rows) || empty($rows)) return NULL;
if(!is_array($rows) || empty($rows)) return null;

foreach ($rows as $row){
$value .= "INSERT INTO `{$name}` ({$fieldList}) VALUES (";
$fieldValues = array();

foreach ($fields as $fieldName => $info){
$fieldValue = $row[$fieldName];

if($info['null'] == 1 && strlen(trim($fieldValue)) == 0){
$fieldValues[] = 'NULL';
$fieldValues[] = 'null';
}

elseif(substr($info['type'], 0, 4) == 'enum'){
$fieldValues[] = "'{$fieldValue}'";
}

elseif(is_numeric ($fieldValue)){
$fieldValues[] = $fieldValue;
}

else{
$fieldValues[] = "'" . $this->_connection->cleanValue($fieldValue) . "'";
}
Expand All @@ -86,7 +86,7 @@ private function __dumpTableData($name, $fields, $condition=NULL){

return $value;
}

private function __dumpTableSQL($table, $type, $fields, $indexes){

$query = "SHOW CREATE TABLE `{$table}`";
Expand All @@ -95,9 +95,9 @@ private function __dumpTableSQL($table, $type, $fields, $indexes){
return $result[1] . ";" . self::CRLF;
}

private function __getTables($match=null){
$query = 'SHOW TABLES' . (!is_null($match) ? " LIKE '$match'" : NULL);
private function __getTables($match = null){
$query = 'SHOW TABLES' . (!is_null($match) ? " LIKE '$match'" : null);

$rows = $this->_connection->fetch ($query);
$rows = array_map (create_function ('$x', 'return array_values ($x);'), $rows);
$tables = array_map (create_function ('$x', 'return $x[0];'), $rows);
Expand Down Expand Up @@ -138,7 +138,7 @@ private function __getTableFields($table){
'default' => $default,
'extra' => $extra
);

$result[$name] = $field;
}

Expand Down