<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\EventListener;
use Vich\UploaderBundle\Event\Event;
/**
* Description of UploadListener
*
* @author Carsten
*/
class UploadListener {
public function onVichUploaderPostUpload(Event $event) {
$object = $event->getObject();
$mapping = $event->getMapping();
if (file_exists('/var/www/server.info')) {
$OwnInfo = file_get_contents('/var/www/server.info');
$OwnInfo = explode(' ', $OwnInfo);
}
if (isset($OwnInfo[0])) {
switch ($OwnInfo[0]) {
case 'web1':
$this->sync($object->getFile()->getPathName(), '10.8.0.51');
break;
case 'web2':
$this->sync($object->getFile()->getPathName(), '10.8.0.50');
break;
case 'dev':
break;
}
}
return true;
}
private function sync($object, $server) {
$connection = \ssh2_connect($server, 22);
\ssh2_auth_password($connection, 'www-data', 'www-data');
\ssh2_scp_send($connection, $object, $object, 0644);
\ssh2_disconnect($connection);
}
}