A
A
AlikDex2015-05-13 17:43:07
PHP
AlikDex, 2015-05-13 17:43:07

Centralized update of multiple sites?

There are several sites on the same engine, which is constantly being improved, new features are introduced and so on. At the moment, I update each site manually via ftp, which is not good. I would like to somehow do it all automatically through the central repository by pressing a button (without configs and templates with css and js, only the core). Tell me what tools allow you to do this and in general what steppe to dig into.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Khomenko, 2015-05-13
@AlikDex

Git/* Composer. I think there are many different ways to do this.

H
He11ion, 2015-05-13
@He11ion

Google Continuous Delivery/Continuous Integration

M
marble, 2015-05-13
_

There was a similar problem. The git did not solve the problem, because everything was on shared servers, on one we got the git, but there were a lot of hosts, more than 60 projects. In short, it was not possible to beg for a git for everyone. I had to write an application in Python, which synchronized all the others with the master host via sftp. Also from the database, I wrote an instruction file that was executed on each host with sssh, also with scripts.
Well, annoyingly, a PHP database analysis script was written after all the changes, in case something went wrong, which took the master host database, packed its structure into an array, and then checked for the presence / absence of fields / tables for all databases. I won’t post the whole script, but I did the following to collect the database into an array:

function createStruct($shop){
    
    if(!isset($shop['db'])) return false;
    $tablesArray = array();
    
    $link = mysql_connect($shop['db']['host'], $shop['db']['user'], $shop['db']['password']);
    mysql_select_db($shop['db']['name'], $link);
    
    $resultTables = mysql_query("show tables", $link);
    if(mysql_affected_rows($link) > 0){
        while($table = mysql_fetch_array($resultTables)){
                $tablesArray[$table[0]] = array();
        }        
    }
    
    if(empty($tablesArray)) return false;
    
    foreach($tablesArray as $tableName => $tmpval){
        $resultFields = mysql_query('DESCRIBE '.$tableName, $link); 
        if(mysql_affected_rows($link) > 0){
            while($rowField = mysql_fetch_assoc($resultFields)){
                $tablesArray[$tableName][$rowField['Field']] = array(
                    'type'  => $rowField['Type'],
                    'null'  => $rowField['Null'],
                    'key'   => $rowField['Key'],
                    'default' => $rowField['Default'],
                    'extra' => $rowField['Extra']
                
                );
            }
        }       
    }
    
    mysql_close($link);
    return $tablesArray;    
}

The code is not perfect, but it did not pursue ideality.
Here is the reconciliation processing part:
$ideal = createStruct($shops[0]);
    
    $equal = createStruct($shops[$_SESSION['sc']]);
    
    if($equal === false || empty($equal)){
        $html = '<table><tr><td><h3>Проблемы с подключение к базе сайта <b>'.$s->shop_name.'</b>, возможно база не была создана, либо не верные коды доступа, либо прекратила свое существование.</h3></td></tr></table>';
    }else{
    
    $html = '<table>';
    $html .= '<tr><td><h3>'.$s->shop_name.'</h3></td></tr>';
    foreach($ideal as $table => $fields){
        if(!isset($equal[$table])){
            $html .= '<tr><td>Отсутствует таблица <b>'.$table.'</b></td></tr>';
        }else{
            $html .= '<tr><td>';
                foreach($ideal[$table] as $key => $fieldRow){
                    if(!isset($equal[$table][$key])){
                        $html .= 'В таблице <b>'.$table.'</b> не хватает поля <b>'.$key.'</b><br>';
                    }else{
                        foreach($ideal[$table][$key] as $okey => $oval){
                            if($equal[$table][$key][$okey] !== $oval){
                                
                                $text = $equal[$table][$key][$okey];
                                if($equal[$table][$key][$okey] === NULL){
                                    $text = 'NULL';
                                }elseif($equal[$table][$key][$okey] === ''){
                                    $text = ' (ПУСТОТА) ';
                                }elseif($equal[$table][$key][$okey] === TRUE){
                                    $text = 'TRUE';
                                }elseif($equal[$table][$key][$okey] === FALSE){
                                    $text = 'FALSE';
                                }
                                
                                $html .= 'Опции поля <b>'.$key.'</b> в таблице <b>'.$table.'</b> не идентичны. Идеал: '.$oval.' Исследуемый: '.$text.'<br>';
                            }
                        }
                    }
                }
            
            $html .= '</td></tr>';
        }
        
        if(isset($equal[$table])){
            unset($equal[$table]);
            unset($ideal[$table]);
        }
    }

E
Evgeny Lavrentiev, 2015-05-13
@lavrentiev

I used to also think about how to update some projects using a minimum of time costs. And as it turned out, the solution was to use Git & Composer. I will say very conveniently and quickly, I was satisfied up to the 7th heaven.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question