Example #1
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage Unable to retrieve deployment version of static files from the file system
  */
 public function testLoadExceptionWrapping()
 {
     $filesystemException = new \Magento\Framework\Filesystem\FilesystemException('File does not exist');
     $this->directory->expects($this->once())->method('readFile')->with('fixture_file.txt')->will($this->throwException($filesystemException));
     try {
         $this->object->load();
     } catch (\Exception $e) {
         $this->assertSame($filesystemException, $e->getPrevious(), 'Wrapping of original exception is expected');
         throw $e;
     }
 }
Example #2
0
 public static function get($key, $group = 'default')
 {
     $full_file = self::$dir . '/' . serialize($group . $key);
     if ($file = File::load($full_file)) {
         if (Date::dateDiff(Date::now(), $file->getModifiedDate(), 's') > self::$cacheTime) {
             File::remove($full_file);
             return false;
         }
         return unserialize($file->content());
     }
     return false;
 }
Example #3
0
 public function download()
 {
     // Grab attachment
     $attachment = new TicketAttachment();
     $attachment->load($this->_data['id']);
     // Load file
     $file = new File();
     $file->load($attachment->file_id);
     // Upload to browser
     $file->SendToBrowser();
     // Prevent standard smarty output from occuring. FIXME: Is this the best way of achieving this?
     exit(0);
 }
Example #4
0
 public function load($constraint)
 {
     $res = parent::load($constraint);
     $path = DATA_ROOT . 'tmp/';
     $file = new File($path);
     $image = $this->image;
     if (!empty($image)) {
         $file->load($this->image);
         if ($file === false) {
             throw new Exception('Failed to load file for ' . get_class($this) . ' with id ' . $this->image);
         }
         $a = $file->Pull($this->image_width, $this->image_height);
         $this->image_filename = '/data/tmp/' . $a['filename'];
     }
     return $res;
 }
Example #5
0
 /**
  * Check and returns asset content if exists (and stop script)
  * 
  * @return void
  */
 private function _loadAsset()
 {
     $segments = explode('/', ltrim(str_replace('..', '', $_SERVER['REQUEST_URI']), '/'));
     $uri = join('/', $segments);
     $mUri = join('/', array_slice($segments, 1));
     $paths = array(FW_DIR . DS . 'assets' . DS . $uri, WEBAPP_MODULES_DIR . DS . $segments[0] . DS . 'assets' . DS . $mUri, MODULES_DIR . DS . $segments[0] . DS . 'assets' . DS . $mUri);
     foreach ($paths as $f) {
         if ($file = File::load($f)) {
             Log::info('{Controller->_loadAsset()} ' . $f);
             $file->output();
         }
     }
 }
Example #6
0
 /**
  * Check if a user is the last uploader
  *
  * @param User $user
  * @param File $img
  * @return bool
  */
 public static function userCanReUpload(User $user, File $img)
 {
     if ($user->isAllowed('reupload')) {
         return true;
         // non-conditional
     } elseif (!$user->isAllowed('reupload-own')) {
         return false;
     }
     if (!$img instanceof LocalFile) {
         return false;
     }
     $img->load();
     return $user->getId() == $img->getUser('id');
 }
Example #7
0
 public function cp($destination, $ow = false)
 {
     if ($this->_data['path'] != $destination) {
         if (self::parsePath($destination, $file, $ow)) {
             $destination .= empty($file) ? '/' . $this->_data['file'] : "/{$file}";
             $this->cmd('cp', array('-f', $this->_data['path'], $destination));
             return File::load($destination);
         }
     }
     return false;
 }
<?php
include('../app/Mage.php');
Mage::App('default'); //might be "default"

require_once 'includes/File.php';
require_once 'includes/Order.php';
require_once 'includes/Customer.php';




$filename = "ecodes_data_history_2.csv";

$file = new File();

$file->load($filename);

$file->process();
echo "done processing\n";
//$order = $file->getNextOrder();
//exit;

while($customerData = $file->getNextCustomer())
{
	$c = new Customer();
	$customer = $c->setData($customerData);

	
	if($customer)
	{
		//print_r($customer->getCustomer()->debug());
Example #9
0
 /**
  * Add an attachment file to the mail.
  *
  * @param string $file          A file from the server to join to the mail
  * @param string $fileName      [optional] Name of the added file in the mail, default is null. If null take the given file name
  * @param string $mimeType      [optional] Forced mimetype, default is null. If null take the given file mime type
  * @return Email                Return current instance of Email
  */
 public function addAttachment($file, $fileName = null, $mimeType = null)
 {
     if ($file = File::load($file)) {
         $mimeType = $mimeType === null ? $file->getMimeType() : $mimeType;
         $fileName = $fileName === null ? $file->getFileName() : $fileName;
         $this->addStringAttachment($file->getContents(), $fileName, $mimeType);
     }
     return $this;
 }
Example #10
0
 /**
  * Rotate image
  * @param string $filePath
  * @param string $fileType - jpeg | gif | png
  * @param string|null $newFilePath - null: owerwrite $filePath
  * @param int $degrees - clockwise
  * @return bool
  */
 public static function rotate($filePath, $fileType, $degrees, $newFilePath = null)
 {
     if (empty($degrees)) {
         return true;
     } else {
         if (intval($degrees) && !empty($filePath) && file_exists($filePath) && !is_dir($filePath)) {
             $srcImage = call_user_func('imagecreatefrom' . $fileType, $filePath);
             $resultImage = imagerotate($srcImage, $degrees * -1, 0);
             imagedestroy($srcImage);
             if ($resultImage) {
                 if (empty($newFilePath)) {
                     $newFilePath = $filePath;
                 }
                 call_user_func("image" . $fileType, $resultImage, $newFilePath, $fileType == 'png' ? 8 : 70);
                 File::load($newFilePath)->chmod(0666);
                 imagedestroy($resultImage);
             }
             return !!$resultImage;
         }
     }
     return false;
 }
Example #11
0
 /**
  * Return unserialized file content.
  * 
  * @param string $file
  * @return string 
  */
 public static function unserialize($file)
 {
     return unserialize(File::load($file));
 }
 /**
  * Load configuration from file.
  *
  * @return map
  */
 public function __construct($file)
 {
     $this->conf = lib\conf2kv(File::load($file));
     $this->file = $file;
 }
 /**
  * Scan either $json or decode $this->path_absolute.'.json'.
  * Set all properties with same name as json key.
  *
  * @param JSON $json (default = null)
  */
 protected function scanJSON($json = null)
 {
     if (is_null($json)) {
         $json = JSON::decode(File::load($this->path_absolute . '.json'));
     }
     foreach ($json as $key => $value) {
         if (property_exists($this, $key)) {
             $this->{$key} = $value;
         }
     }
 }
 /**
  * Run tokenizer tests t1.txt ... t$num.txt.
  * Requires t1.ok.txt ... t$num.ok.txt
  *
  * @param any $num (5 = run t1.txt ... t5.txt, 'a.txt' run only this test)
  * @param vector $plugin_list
  */
 public function runTokenizer($num, $plugin_list)
 {
     list($tdir, $rel_tdir) = $this->_test_dir();
     $this->load('Tokenizer.class.php');
     $tok = new Tokenizer(Tokenizer::TOK_DEBUG);
     for ($i = 0; $i < count($plugin_list); $i++) {
         $plugin = 'rkphplib\\' . $plugin_list[$i];
         $this->load($plugin_list[$i] . '.class.php');
         $tok->register(new $plugin());
     }
     $test_files = array();
     if (is_string($num)) {
         $this->_log("runTokenizer: {$rel_tdir}/{$num}", 11);
         array_push($test_files, $tdir . '/' . $num);
     } else {
         if ($num > 1) {
             $this->_log("runTokenizer: {$rel_tdir}/t1.txt ... {$rel_tdir}/t{$num}.txt", 11);
         } else {
             $this->_log("runTokenizer: {$rel_tdir}/t{$num}.txt", 11);
         }
         for ($i = 1; $i <= $num; $i++) {
             array_push($test_files, $tdir . '/t' . $i . '.txt');
         }
     }
     $i = 0;
     foreach ($test_files as $f_txt) {
         $f_out = str_replace('.txt', '.out.txt', $f_txt);
         $f_ok = str_replace('.txt', '.ok.txt', $f_txt);
         $i++;
         $tok->setText(File::load($f_txt));
         $ok = File::load($f_ok);
         $out = $tok->toString();
         $this->_tc['num']++;
         $this->_log("Test {$i} ... ", 0);
         if ($out != $ok) {
             if (mb_strlen($out) > 40 || strpos($out, "\n") !== false) {
                 $this->_log("ERROR! (see {$f_out})");
                 File::save($f_out, $out);
             } else {
                 $this->_log("{$out} != {$ok} - ERROR!");
             }
             $this->_tc['error']++;
         } else {
             $this->_tc['ok']++;
             $this->_log("ok");
         }
     }
 }