示例#1
0
 /**
  * DOCUMENT ME
  * @param mixed $args
  * @param mixed $options
  */
 protected function execute($args = array(), $options = array())
 {
     $conn = 'doctrine';
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration, $conn));
     $dataDir = aFiles::getWritableDataFolder();
     $uploadDir = aFiles::getUploadFolder();
     // $dataDir will be a_writable, sf_data_dir is its parent, so we can put things there and
     // trust that they are not crushed by the unzip
     $dataZip = sfConfig::get('sf_data_dir') . '/apostrophedemo-awritable.zip';
     if (!copy('http://content.apostrophenow.com/uploads/apostrophedemo-awritable.zip', $dataZip)) {
         throw new sfException("Unable to copy http://content.apostrophenow.com/uploads/apostrophedemo-awritable.zip to {$dataZip}");
     }
     $uploadZip = sfConfig::get('sf_data_dir') . '/apostrophedemo-uploads.zip';
     if (!copy("http://content.apostrophenow.com/uploads/apostrophedemo-uploads.zip", $uploadZip)) {
         throw new sfException('Unable to copy http://content.apostrophenow.com/uploads/apostrophedemo-uploads.zip to $dataZip');
     }
     $this->unzip($dataDir, $dataZip, $options);
     $this->unzip($uploadDir, $uploadZip, $options);
     // Yes, you need to have mysql to use this feature.
     // However you can set app_syncContent_mysql to
     // the path of your mysql utility if it is called something
     // else or not in the PATH
     $mysql = sfConfig::get('app_syncContent_mysql', 'mysql');
     system(escapeshellarg($mysql) . " {$params} < " . escapeshellarg($dataDir . '/ademocontent.sql'), $result);
     if ($result != 0) {
         throw new sfException("mysql failed. Maybe you don't have it in your PATH");
     }
     // Undo the little dance we did to send the demo password across without forcing the use
     // of a known password salt or a particular encryption scheme on the receiving site.
     // The demo password is no secret, but new passwords set later should be, so we don't
     // want to force a salt when generating the demo dump. See aSyncActions for details
     if ($options['verbose']) {
         echo "Postprocessing users\n";
     }
     $users = Doctrine::getTable('sfGuardUser')->findAll();
     foreach ($users as $user) {
         // If there is a salt, and no password, it's really a hint to turn the cleartext password
         // into a proper one and establish a salt
         if (!strlen($user->getPassword())) {
             $demoPassword = $user->getSalt();
             if (strlen($demoPassword)) {
                 $user->setSalt('');
                 $user->setPassword($demoPassword);
                 $user->save();
             }
         }
     }
     if ($options['verbose']) {
         echo "Content loaded.\n";
     }
     system('./symfony apostrophe:rebuild-search-index', $result);
     if ($result != 0) {
         throw new sfException('Problem executing apostrophe:rebuild-search-index task.');
     }
 }
示例#2
0
 protected function execute($args = array(), $options = array())
 {
     $conn = false;
     if (isset($args['connection'])) {
         $conn = $args['connection'];
     }
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration, $conn));
     // Right to stdout for the convenience of the remote ssh connection from
     // sync-content
     system("mysqldump --skip-opt --add-drop-table --create-options " . "--disable-keys --extended-insert --set-charset {$params} ", $result);
     if ($result != 0) {
         throw new sfException("mysqldump failed");
     }
 }
示例#3
0
 protected function execute($args = array(), $options = array())
 {
     $conn = false;
     if (isset($args['connection'])) {
         $conn = $args['connection'];
     }
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration, $conn));
     // Accept SQL right from stdin for the convenience of the remote ssh connection from
     // sync-content
     passthru("mysql {$params}", $result);
     if ($result != 0) {
         throw new sfException("mysql failed");
     }
 }
示例#4
0
 public function executeZipDemo(sfWebRequest $request)
 {
     if (!$this->get('zip_demo', false)) {
         throw new sfException('Zip demo feature is not enabled in properties.ini');
     }
     $uploads = aFiles::getUploadFolder();
     $uploadsDemo = "{$uploads}/apostrophedemo-uploads.zip";
     file_put_contents("{$uploads}/readme.txt", "This is the Symfony uploads folder. This file is here so that zipping this folder does not\nresult in an error when it happens to be empty. Move along, nothing to see here.");
     $this->zip($uploadsDemo, $uploads);
     // Has to be in the writable folder or we won't be able to write to it in many cases
     $data = aFiles::getWritableDataFolder();
     $dump = "{$data}/ademocontent.sql";
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams(sfContext::getInstance()->getConfiguration(), 'doctrine'));
     // Yes, you need to have mysql and mysqldump to use this feature.
     // However you can set app_syncContent_mysqldump to
     // the path of your mysqldump utility if it is called something
     // else or not in the PATH
     $mysql = sfConfig::get('app_syncContent_mysql', 'mysql');
     $mysqldump = sfConfig::get('app_syncContent_mysqldump', 'mysqldump');
     $cmd = escapeshellarg($mysqldump) . " --skip-opt --add-drop-table --create-options " . "--disable-keys --extended-insert --set-charset {$params} > " . escapeshellarg($dump);
     system($cmd, $result);
     if ($result != 0) {
         throw new sfException("mysqldump failed");
     }
     // You can explicitly set demo_password to an empty string to keep
     // the passwords in your demo unchanged
     $demoPassword = $this->get('demo_password', 'demo');
     if (!preg_match('/^\\w+$/', $demoPassword)) {
         throw new sfException("demo_password must contain only alphanumeric characters and underscores");
     }
     if ($demoPassword) {
         // New set of parameters for a temporary database in which we'll fix the passwords so that
         // the demo doesn't allow dictionary attacks on your real passwords
         $params = array();
         $params['dbname'] = $this->get('demo_tempdb');
         $params['username'] = $this->get('demo_tempuser');
         $params['password'] = $this->get('demo_temppassword');
         $params['host'] = $this->get('demo_temphost');
         $params = sfSyncContentTools::shellDatabaseParams($params);
         $cmd = escapeshellarg($mysql) . ' ' . $params . ' < ' . escapeshellarg($dump);
         system($cmd, $result);
         if ($result != 0) {
             throw new sfException("Unable to load sql into tempdb for password alteration. Did you configure tempdb, tempuser, temppassword and temphost in properties.ini?");
         }
         // I really ought to PDO this
         $cmd = escapeshellarg($mysql) . ' ' . $params;
         $out = popen($cmd, "w");
         // If we set the salt here, everyone who starts from the demo has the same salt.
         // If they change their passwords to real passwords, they are still vulnerable to
         // dictionary attack if their databases are compromised.
         // That's no good, so we'll fix the passwords with a clever trick in the demo fixtures
         // task that imports all this. We stash the demo password (not a secret) in the salt field
         // as cleartext for now, and the demo fixtures task grabs that, clears the salt field and
         // calls setPassword, resulting in a new, robustly unique salt on the new site.
         fwrite($out, "UPDATE sf_guard_user SET salt = '{$demoPassword}';\n");
         fwrite($out, "UPDATE sf_guard_user SET password = '';\n");
         $result = pclose($out);
         $cmd = escapeshellarg($mysqldump) . " --skip-opt --add-drop-table --create-options " . "--disable-keys --extended-insert --set-charset {$params} > " . escapeshellarg($dump);
         system($cmd, $result);
         if ($result != 0) {
             throw new sfException('Second mysqldump failed after password adjustment');
         }
     }
     $dataDemo = "{$uploads}/apostrophedemo-awritable.zip";
     $this->zip($dataDemo, $data);
     unlink($dump);
 }
示例#5
0
 /**
  * Execution du dump intranet sur l'internet
  */
 protected function executeInternetDump()
 {
     $this->dump_internet_path = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('app_sync_dump_dir') . '/' . $this->sync_log->getGuid() . '.internet.dump.gz';
     $params = sfSyncContentTools::shellDatabaseParams(sfSyncContentTools::getDatabaseParams($this->configuration));
     if (file_exists($this->dump_internet_path)) {
         $file = gzfile($this->dump_internet_path);
     }
     if (isset($file) && $file) {
         $fp = fopen($this->dump_internet_path . '.tmp', "w");
         fwrite($fp, implode("", $file));
         fclose($fp);
         passthru("pv " . $this->dump_internet_path . ".tmp | mysql {$params} --default-character-set=utf8", $result);
         unlink($this->dump_internet_path . ".tmp");
     } else {
         $this->log("Rien à dumper");
     }
 }