Skip to content
This repository
Browse code

MINOR: add some comments to UploadField

  • Loading branch information...
commit 5d7f6a0d69fd8ee947f077a4346edba4a29e9064 1 parent a2c9c40
Mateusz U authored April 18, 2012

Showing 1 changed file with 9 additions and 0 deletions. Show diff stats Hide diff stats

  1. 9  forms/UploadField.php
9  forms/UploadField.php
@@ -442,14 +442,20 @@ public function upload(SS_HTTPRequest $request) {
442 442
 				'error' => $tmpfile['error']
443 443
 			);
444 444
 		}
  445
+
  446
+		// Check for constraints on the record to which the file will be attached.
445 447
 		if (!$return['error'] && $record && $record->exists()) {
446 448
 			$tooManyFiles = false;
  449
+			// Some relationships allow many files to be attached.
447 450
 			if ($this->getConfig('allowedMaxFileNumber') && ($record->has_many($name) || $record->many_many($name))) {
448 451
 				if(!$record->isInDB()) $record->write();
449 452
 				$tooManyFiles = $record->{$name}()->count() >= $this->getConfig('allowedMaxFileNumber');
  453
+			// has_one only allows one file at any given time.
450 454
 			} elseif($record->has_one($name)) {
451 455
 				$tooManyFiles = $record->{$name}() && $record->{$name}()->exists();
452 456
 			}
  457
+
  458
+			// Report the constraint violation.
453 459
 			if ($tooManyFiles) {
454 460
 				if(!$this->getConfig('allowedMaxFileNumber')) $this->setConfig('allowedMaxFileNumber', 1);
455 461
 				$return['error'] = sprintf(_t(
@@ -469,9 +475,12 @@ public function upload(SS_HTTPRequest $request) {
469 475
 				if ($this->upload->isError()) {
470 476
 					$return['error'] = implode(' '.PHP_EOL, $this->upload->getErrors());
471 477
 				} else {
  478
+					// The file has been uploaded successfully, attach it to the related record.
472 479
 					$file = $this->upload->getFile();
473 480
 					$file->write();
474 481
 					$this->attachFile($file);
  482
+
  483
+					// Collect all output data.
475 484
 					$file =  $this->customiseFile($file);
476 485
 					$return = array_merge($return, array(
477 486
 						'id' => $file->ID,

0 notes on commit 5d7f6a0

Please sign in to comment.
Something went wrong with that request. Please try again.