src/EventListener/UploadListener.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. namespace App\EventListener;
  8. use Vich\UploaderBundle\Event\Event;
  9. /**
  10.  * Description of UploadListener
  11.  *
  12.  * @author Carsten
  13.  */
  14. class UploadListener {
  15.     public function onVichUploaderPostUpload(Event $event) {
  16.         $object $event->getObject();
  17.         $mapping $event->getMapping();
  18.         if (file_exists('/var/www/server.info')) {
  19.             $OwnInfo file_get_contents('/var/www/server.info');
  20.             $OwnInfo explode(' '$OwnInfo);            
  21.         }
  22.         if (isset($OwnInfo[0])) {
  23.             switch ($OwnInfo[0]) {
  24.                 case 'web1':
  25.                     $this->sync($object->getFile()->getPathName(), '10.8.0.51');
  26.                     break;
  27.                 case 'web2':
  28.                     $this->sync($object->getFile()->getPathName(), '10.8.0.50');
  29.                     break;
  30.                 case 'dev':
  31.                     
  32.                     break;
  33.             }
  34.         }
  35.         return true;
  36.     }
  37.     private function sync($object$server) {
  38.         $connection = \ssh2_connect($server22);
  39.         \ssh2_auth_password($connection'www-data''www-data');
  40.         \ssh2_scp_send($connection$object$object0644);
  41.         \ssh2_disconnect($connection);
  42.     }
  43. }