Development

Changeset 33248

You must first sign up to be able to contribute.

Changeset 33248

Show
Ignore:
Timestamp:
12/11/11 16:31:52 (3 years ago)
Author:
wjohnald
Message:

Added an --ignore-tables flag to the sync-content task

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSyncContentPlugin/branches/1.0

    • Property svn:ignore set to
      .README.swp
  • plugins/sfSyncContentPlugin/branches/1.0/README

    r24693 r33248  
    8787          # If you use P'unk Avenue stuff 
    8888          - "data/pk_writable" 
     89 
     90There is also an option to ignore specified database tables.  Call this with 
     91 
     92symfony project:sync-content frontend dev to prod@staging --ignore-tables=table1,table2 
     93 
     94The target of the sync will drop and rebuild its database in this scenario so 
     95that you don't trigger any 500 errors when navigating to the site. 
    8996           
    9097== About Those Pesky Password Prompts == 
  • plugins/sfSyncContentPlugin/branches/1.0/lib/task/mysqldumpTask.class.php

    r22583 r33248  
    2121      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), 
    2222      // add your own options here 
     23      new sfCommandOption('ignore-tables', null, sfCommandOption::PARAMETER_OPTIONAL, 'Comma-separated list of tables from the remote database to ignore'), 
    2324    )); 
    2425 
     
    4142      $conn = $args['connection']; 
    4243    } 
    43     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration, $conn)); 
     44    $dbparams = sfSyncContentTools::getDatabaseParams($this->configuration, $conn); 
     45    $params = sfSyncContentTools::shellDatabaseParams($dbparams); 
     46 
     47    // set up the ignore flag 
     48    $ignoreFlag = ''; 
     49    if (isset($options['ignore-tables']) && !empty($options['ignore-tables'])) 
     50    { 
     51        foreach(explode(',', $options['ignore-tables']) as $ignoreTable) 
     52        { 
     53            $ignoreFlag .= ' ' . escapeshellarg('--ignore-table=' . $dbparams['dbname'] . '.' . $ignoreTable) . ' '; 
     54        } 
     55    } 
    4456 
    4557    // Right to stdout for the convenience of the remote ssh connection from 
    4658    // sync-content 
    47     system("mysqldump --skip-opt --add-drop-table --create-options " . 
    48       "--disable-keys --extended-insert --set-charset $params ", $result); 
     59    $command = "mysqldump --skip-opt --add-drop-table --create-options " . 
     60      "--disable-keys --extended-insert --set-charset $params $ignoreFlag"; 
     61    system($command, $result); 
    4962     
    5063    if ($result != 0) 
  • plugins/sfSyncContentPlugin/branches/1.0/lib/task/synccontentTask.class.php

    r22882 r33248  
    3232        'The remote environment and site. The site name must be defined in properties.ini'))); 
    3333 
     34    $this->addOptions(array( 
     35      new sfCommandOption('ignore-tables', null, sfCommandOption::PARAMETER_OPTIONAL, 'Comma-separated list of tables from the remote database to ignore'), 
     36    )); 
     37 
    3438    $this->namespace        = 'project'; 
    3539    $this->name             = 'sync-content'; 
     
    102106      $this->sshPort = $data['port'] + 0; 
    103107    } 
    104      
     108 
     109    $ignoreTables = (!empty($options['ignore-tables']))? '--ignore-tables=' . $options['ignore-tables'] : ''; 
    105110    $binary = $_SERVER['SCRIPT_FILENAME']; 
    106111    // A further simplification: use the subsidiary tasks locally too. This resolves issues with the 
     
    108113    if ($direction == 'to') 
    109114    { 
    110       $cmd = "$binary project:mysql-dump --application=$application --env=$env | " . $this->_content_sync_build_remote_cmd($pathRemote, "./symfony project:mysql-load --application=$application --env=$envRemote"); 
     115      if (!empty($options['ignore-tables'])) 
     116      { 
     117        $this->_content_sync_remote_system($pathRemote, "$binary doctrine:drop-db --no-confirmation; $binary doctrine:create-db; $binary doctrine:build-sql; $binary doctrine:insert-sql;"); 
     118      } 
     119      $cmd = "$binary project:mysql-dump --application=$application --env=$env $ignoreTables | " . $this->_content_sync_build_remote_cmd($pathRemote, "./symfony project:mysql-load --application=$application --env=$envRemote"); 
    111120      $this->_content_sync_system($cmd); 
    112121    } 
    113122    else 
    114123    { 
    115       $cmd = $this->_content_sync_build_remote_cmd($pathRemote, "./symfony project:mysql-dump --application=$application --env=$envRemote") . " | $binary project:mysql-load --application=$application --env=$env"; 
     124      if (!empty($options['ignore-tables'])) 
     125      { 
     126        $this->_content_sync_system("$binary doctrine:drop-db --no-confirmation; $binary doctrine:create-db; $binary doctrine:build-sql; $binary doctrine:insert-sql;"); 
     127      } 
     128      $cmd = $this->_content_sync_build_remote_cmd($pathRemote, "./symfony project:mysql-dump --application=$application --env=$envRemote $ignoreTables") . " | $binary project:mysql-load --application=$application --env=$env"; 
    116129      $this->_content_sync_system($cmd); 
    117130    }