/**
  * @param string $filepath
  * @param boolean $preview
  *
  * @return null|BulkLoader_Result
  */
 protected function processAll($filepath, $preview = false)
 {
     $filepath = Director::getAbsFile($filepath);
     $files = $this->splitFile($filepath);
     $result = null;
     $last = null;
     try {
         foreach ($files as $file) {
             $last = $file;
             $next = $this->processChunk($file, false);
             if ($result instanceof BulkLoader_Result) {
                 $result->merge($next);
             } else {
                 $result = $next;
             }
             @unlink($file);
         }
     } catch (Exception $e) {
         print "Failed to parse {$last}\n";
     }
     return $result;
 }
 /**
  * Returns true if the given file exists. Filename should be relative to the site root.
  *
  * @param $file
  *
  * @return bool
  */
 public static function fileExists($file)
 {
     // replace any appended query-strings, e.g. /path/to/foo.php?bar=1 to /path/to/foo.php
     $file = preg_replace('/([^\\?]*)?.*/', '$1', $file);
     return file_exists(Director::getAbsFile($file));
 }
 /**
  * Open a CSV file for parsing.
  *
  * You can use the object returned in a foreach loop to extract the data.
  *
  * @param string $filename The name of the file.  If relative, it will be relative to the site's base dir
  * @param string $delimiter The character for seperating columns
  * @param string $enclosure The character for quoting or enclosing columns
  */
 public function __construct($filename, $delimiter = ",", $enclosure = '"')
 {
     $filename = Director::getAbsFile($filename);
     $this->filename = $filename;
     $this->delimiter = $delimiter;
     $this->enclosure = $enclosure;
     parent::__construct();
 }
 /**
  * Returns all classes contained in a certain folder.
  *
  * @todo Doesn't return additional classes that only begin
  *  with the filename, and have additional naming separated through underscores.
  *
  * @param string $folderPath Relative or absolute folder path
  * @return array Array of class names
  */
 public static function classes_for_folder($folderPath)
 {
     $absFolderPath = Director::getAbsFile($folderPath);
     $matchedClasses = array();
     $manifest = ClassLoader::instance()->getManifest()->getClasses();
     foreach ($manifest as $class => $compareFilePath) {
         if (stripos($compareFilePath, $absFolderPath) === 0) {
             $matchedClasses[] = $class;
         }
     }
     return $matchedClasses;
 }
 /**
  * Attach the specified file to this email message.
  *
  * @param string $filename Relative or full path to file you wish to attach to this email message.
  * @param string|null $attachedFilename Name of the file that should appear once it's sent as a separate attachment.
  * @param string|null $mimeType MIME type to use when attaching file. If not provided, will attempt to infer via HTTP::get_mime_type().
  * @return $this
  */
 public function attachFile($filename, $attachedFilename = null, $mimeType = null)
 {
     if (!$attachedFilename) {
         $attachedFilename = basename($filename);
     }
     $absoluteFileName = Director::getAbsFile($filename);
     if (file_exists($absoluteFileName)) {
         $this->attachFileFromString(file_get_contents($absoluteFileName), $attachedFilename, $mimeType);
     } else {
         user_error("Could not attach '{$absoluteFileName}' to email. File does not exist.", E_USER_NOTICE);
     }
     return $this;
 }