I have a php artisan command that I created, and executed as bheng
user
php /home/forge/site.com/artisan products:exportdiff --env=production
that export the file into my /files/product-exports/
directory
Also, I've already did
chmod -R 777 files/product-exports/
Result
The export part is working fine, I got the file exported as you can see in the image below
What is the different between white
and green
color code ?
Why does it place under the dot .
?
Does it mean anything at all ?
Question
Is this something that have to do with the permission ?
How would one go about and debug this further ?
I'm opening to any suggestions at this moment.
Any hints / suggestions / helps on this be will be much appreciated !
Update
As requested from @Tensibai
cd /home/forge/site.com/ && pwd && php /home/forge/site.com/artisan products:exportdiff --env=production
/home/forge/site.com
.
Export created successfully. Export ID is 1085
Source: /home/forge/site/files/product-exports/export1085_2016-11-23.csv
Destination: /Site/inbound/products/productexport1085_2016-11-23.csv
$source NOT exist !
[Exception]
Could not open local file: /home/forge/site/files/product-exports/export1085_2016-11-23.csv.
products:exportdiff
Update2
$source = /home/forge/site/files/product-exports/export1088_2016-11-23.csv
I've tried dd(file_exists($source));
It kept return bool(false)
Is it because of the way I check for file_exists ?
Update3
Here is my whole PHP code for ExportProductsDiff.php
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ExportProductsDiff extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'products:exportdiff';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Export all products to Diff.';
/**
* The system export message.
*
* @var string
*/
protected $system_message = '[System Diff Export]';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// Export the products by calling the ExportProducts Command
$options = [
'--format' => "distributor",
'--encoding' => "standard csv",
'--categories' => "all categories",
'--conjugate' => 1,
'--include_disabled'=> 1,
'--export_notes' => $this->system_message
];
// Run the export
$this->call('products:export', $options);
$last_run_export = ProductExport::where('notes', '=', $this->system_message)
->where('status', '=', 'finished')
->where('format', '=', 'distributor')
->orderBy('id', 'desc')
->firstOrFail();
$this->info('Export created successfully. Export ID is ' . $last_run_export->id);
$env = $this->option('env');
if ($env == 'production'){
$localdomain = '*******';
}else{
$env = 'development';
$localdomain = '*******';
}
$sftp_server = '*******';
$sftp_user_name = '*******';
$sftp_user_pass = '*******';
// Open the SFTP connection
$connection = @ssh2_connect($sftp_server);
if (!$connection)
{
throw new Exception("Could not connect to $sftp_server.");
}
// Login to the SFTP server
if (! @ssh2_auth_password($connection, $sftp_user_name, $sftp_user_pass))
{
throw new Exception("Could not authenticate with username $sftp_user_name " .
"and password $sftp_user_pass.");
}
$sftp = @ssh2_sftp($connection);
if (!$sftp)
{
throw new Exception("Could not initialize SFTP subsystem.");
}
// Prepare the files
$source = '/home/forge/site/files/product-exports/' . $last_run_export->file_name;
/////////////////////////////////////
//The bug is here
// update site to site.com
/////////////////////////////////////
$destination = '/Site/inbound/products/product' . $last_run_export->file_name;
$this->info('Source: ' . $source);
$this->info('Destination: ' . $destination);
if (!file_exists('/Site/inbound/products/')) {
ssh2_sftp_mkdir($sftp, '/Site/inbound/products/', 0775, true);
}
dd(file_exists($source));
if (file_exists($source)) {
chmod($source, 0775);
}else{
$this->info('$source NOT exist !');
}
// Upload the file
$stream = @fopen("ssh2.sftp://$sftp$destination", 'w');
if (!$stream)
{
throw new Exception("Could not open file: $destination");
}
$data_to_send = @file_get_contents($source);
if ($data_to_send === false)
{
throw new Exception("Could not open local file: $source.");
}
if (@fwrite($stream, $data_to_send) === false)
{
throw new Exception("Could not send data from file: $source.");
}
@fclose($stream);
// Delete the export when finished
if (file_exists(base_path() . ProductExport::path . $last_run_export->file_name))
{
unlink(base_path() . ProductExport::path . $last_run_export->file_name);
}
$last_run_export->delete();
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array();
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array();
}
}