Client * Attention le script doit s'executer avec l'utilisateur root, afin de lire le fichier même * s'il n'a pas les droits */ // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); try { $opts = new Zend_Console_Getopt( //Options array( 'help|?' => "Displays usage information.", 'cron' => "Mandatory option in crontab", 'file=s' => "Manually define the file to process", 'client=s' => "Define the client name for getting the file manually", 'debug' => "Send a mail for debug", ) ); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); exit; } //Usage if( isset($opts->help) || count($opts->getOptions())==0 ) { echo "Place files in right directory for sending to the customer.\n"; echo $opts->getUsageMessage(); exit; } $c = new Zend_Config($application->getOptions()); $db = Zend_Db::factory($c->profil->db->metier); Zend_Db_Table::setDefaultAdapter($db); $fluxM = new Application_Model_Sdv1FluxFileOut(); $sql = $fluxM->select()->where('dateEnd!=?','0000-00-00 00:00:00'); //Get specific file if ( isset($opts->file) && isset($opts->client) ) { $sql->where('client=?', $opts->client) ->where('fileOut=?', $opts->file); } else { $sql->where('dateEnd!=?', '0000-00-00 00:00:00'); $sql->where('depotDate=?', '0000-00-00 00:00:00'); } $result = $fluxM->fetchAll($sql); if ( $result->count() > 0 ) { foreach ( $result as $item ) { $source = $c->profil->path->storage . '/' . $item->client . '/' . 'recv' . '/' . $item->fileOut; $depotDir = 'recv'; if ($item->depotDir != '') { $depotDir = $item->depotDir; } switch ($item->depotType) { case 'FTP': $dest = $c->profil->path->ftp . '/' . $item->client . '/' . $depotDir . '/' . $item->fileOut; break; case 'SFTP': $dest = $c->profil->path->sftp . '/' . $item->client . '/' . $depotDir . '/' . $item->fileOut; break; } if ( copy($source, $dest) ) { $lines = file($source); $nbLines = count($lines); chown($dest, $item->client); $fluxM->update(array( 'depotDate' => date('YmdHis'), ), 'id='.$item->id); $subject = "[Flux] - Envoi d'un fichier " . $item->client; $txt = "Envoi d'un fichier après traitement\n"; $txt.= "Client : ".$item->client."\n"; $txt.= "Mode de transmission : ".$item->depotType."\n"; $txt.= "Fichier : ".$item->fileOut."\n"; $txt.= "Nombre de Lignes : $nbLines\n"; $mail = new Zend_Mail('UTF-8'); $tr = new Zend_Mail_Transport_Sendmail(); $mail->setDefaultTransport($tr); $mail->setBodyText($txt); $mail->setFrom('supportdev@scores-decisions.com', 'Machine'); $mail->addTo('suivi@scores-decisions.com', 'Suivi'); $mail->setSubject($subject); $mail->send(); } } }