Source of file ExportToTradeMeTask.php
Size: 2,069 Bytes - Last Modified: 2021-12-23T10:41:27+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/ExportToTradeMeTask.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | <?php namespace Sunnysideup\EcommerceTrademe\Tasks; use SilverStripe\Assets\Filesystem; use SilverStripe\Control\Director; use SilverStripe\Dev\BuildTask; /** * Sends listings to trademe. */ class ExportToTradeMeTask extends BuildTask { protected $title = 'FTP Product CSV to trademe'; protected $description = 'Takes CSV and images and sends them to trademe for listing'; /** * @var string */ private static $ftp_location = ''; /** * @var string */ private static $username = ''; /** * @var string */ private static $password = ''; /** * @var string */ private static $folder_to_upload_to = 'In'; /** * Run. * * @param mixed $request */ public function run($request) { $connection = ftp_connect($this->Config()->get('ftp_location')); if ($connection) { $login = ftp_login( $connection, $this->Config()->get('username'), $this->Config()->get('password') ); ftp_pasv($connection, true); if ($login) { $upload = ftp_put($connection, 'In/products.csv', self::file_location(), FTP_BINARY); if (! $upload) { user_error('FTP upload failed!'); } else { echo 'OK!'; } } else { user_error('Login attempt failed!'); } ftp_close($connection); } else { user_error('We could not connect to FTP'); } } public static function file_location(): string { $path = Director::baseFolder() . '/' . PUBLIC_DIR . '/trademedata'; Filesystem::makeFolder($path); return $path . '/' . 'products.csv'; } public static function url_location() { return str_replace( Director::baseFolder() . '/' . PUBLIC_DIR . '/', Director::absoluteURL('/'), self::file_location() ); } } |