Author: sevein
Date: Thu Dec 8 02:10:09 2011
New Revision: 10374
Log:
Make possible to create QubitAssets without passing contents but the file path
Modified:
trunk/lib/QubitAsset.class.php
trunk/lib/model/QubitDigitalObject.php
Modified: trunk/lib/QubitAsset.class.php
==============================================================================
--- trunk/lib/QubitAsset.class.php Wed Dec 7 17:37:59 2011 (r10373)
+++ trunk/lib/QubitAsset.class.php Thu Dec 8 02:10:09 2011 (r10374)
@@ -31,13 +31,29 @@
$name,
$contents,
$checksum,
- $checksumAlgorithm;
+ $checksumAlgorithm,
+ $path;
- public function __construct($assetName, $assetContents, $options = array())
+ public function __construct()
{
- $this->name = $assetName;
- $this->contents = $assetContents;
- $this->generateChecksum('sha256');
+ $args = func_get_args();
+
+ // File path passed
+ if (1 == func_num_args())
+ {
+ $path_parts = pathinfo($args[0]);
+
+ $this->name = $path_parts['basename'];
+ $this->path = $args[0];
+ $this->generateChecksum('sha256');
+ }
+ // File name and contents passed
+ else if (2 == func_num_args())
+ {
+ $this->name = $args[0];
+ $this->contents = $$args[1];
+ $this->generateChecksum('sha256');
+ }
}
public function setName($value)
@@ -52,6 +68,11 @@
return $this->name;
}
+ public function getPath()
+ {
+ return $this->path;
+ }
+
public function setContents($value)
{
$this->contents = $value;
@@ -105,9 +126,17 @@
throw new Exception('Invalid checksum algorithm');
}
- $this->checksum = hash($algorithm, $this->contents);
$this->checksumAlgorithm = $algorithm;
+ if (isset($this->contents))
+ {
+ $this->checksum = hash($algorithm, $this->contents);
+ }
+ else if (isset($this->path))
+ {
+ $this->checksum = hash_file($algorithm, $this->path);
+ }
+
return $this->checksum;
}
}
Modified: trunk/lib/model/QubitDigitalObject.php
==============================================================================
--- trunk/lib/model/QubitDigitalObject.php Wed Dec 7 17:37:59 2011
(r10373)
+++ trunk/lib/model/QubitDigitalObject.php Thu Dec 8 02:10:09 2011
(r10374)
@@ -453,19 +453,34 @@
}
// Write file
- if (false === file_put_contents($filePathName, $asset->getContents()))
+ // If the asset contents are not included but referred, move or copy
+ if (null !== $assetPath = $asset->getPath())
+ {
+ if (false === @rename($assetPath, $filePathName))
+ {
+ if (false === @copy($assetPath, $filePathName))
+ {
+ throw new sfException('File write to '.$filePathName.' failed. See
setting directory and file permissions documentation.');
+ }
+ }
+ }
+ // If the asset contents are included (HTTP upload)
+ else if (false === file_put_contents($filePathName, $asset->getContents()))
{
throw new sfException('File write to '.$filePathName.' failed. See
setting directory and file permissions documentation.');
}
- // Test asset checksum against generated checksum from file
- $this->generateChecksumFromFile($filePathName);
- if ($this->getChecksum() != $asset->getChecksum())
+ if (null === $assetPath)
{
- unlink($filePathName);
- rmdir($infoObjectPath);
+ // Test asset checksum against generated checksum from file
+ $this->generateChecksumFromFile($filePathName);
+ if ($this->getChecksum() != $asset->getChecksum())
+ {
+ unlink($filePathName);
+ rmdir($infoObjectPath);
- throw new sfException('Checksum values did not validate.');
+ throw new sfException('Checksum values did not validate.');
+ }
}
// set file permissions
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.