Move a cell object from one address to another

@param    string        $fromAddress    Current address of the cell to move
@param    string        $toAddress        Destination address of the cell to move
@return    boolean
189310
public function moveCell($fromAddress, $toAddress)
    {
        if ($fromAddress === $this->currentObjectID) {
            $this->currentObjectID = $toAddress;
        }

        $query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
        $result = $this->DBHandle->exec($query);
        if ($result === false) {
            throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
        }

        $query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
        $result = $this->DBHandle->exec($query);
        if ($result === false) {
            throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
        }

        return true;
    }
610568
public function move(Node\NodeInterface $node, $pos, $levelDiff, $undoMove = false)
	{
		if ( ! $this->locked) {
			//\Log::info('Should lock before changes');
		}

		$tableName = $this->tableName;
		$arrayHelper = $this->arrayHelper;
		$self = $this;
		
		// Calculate the old position to rollback to in case of some issue
		$oldPosition = $node->getLeftValue();
		
		if ($pos < $oldPosition) {
			$oldPosition = $node->getRightValue() + 1;
		}
		
		if ( ! $node instanceof Node\DoctrineNode) {
			throw new Exception\WrongInstance($node, 'Node\DoctrineNode');
		}
		
		// Transactional because need to rollback in case of trigger failure
		$this->entityManager->transactional(function(EntityManager $entityManager) use ($node, $pos, $levelDiff, $tableName, $arrayHelper, $self) {
			$left = $node->getLeftValue();
			$right = $node->getRightValue();
			$spaceUsed = $right - $left + 1;
			$moveA = null;
			$moveB = null;
			$a = null;
			$b = null;
			$min = null;
			$max = null;

			if ($pos > $left) {
				$a = $right + 1;
				$b = $pos - 1;
				$moveA = $pos - $left - $spaceUsed;
				$moveB = - $spaceUsed;
				$min = $left;
				$max = $pos - 1;
			} else {
				$a = $pos;
				$b = $left - 1;
				$moveA = $pos - $left;
				$moveB = $spaceUsed;
				$min = $pos;
				$max = $right;
			}

//			// NB! It's important to set "level" before "left" for MySQL!
//			$dql = "UPDATE {$className} e
//					SET e.level = e.level + IF(e.left BETWEEN {$left} AND {$right}, {$levelDiff}, 0),
//						e.left = e.left + IF(e.left BETWEEN {$left} AND {$right}, {$moveA}, IF(e.left BETWEEN {$a} AND {$b}, {$moveB}, 0)),
//						e.right = e.right + IF(e.right BETWEEN {$left} AND {$right}, {$moveA}, IF(e.right BETWEEN {$a} AND {$b}, {$moveB}, 0))
//					WHERE (e.left BETWEEN {$min} AND {$max}
//						OR e.right BETWEEN {$min} AND {$max})";
//
//			$dql .= $self->getAdditionalCondition('AND');
//
//			$query = $entityManager->createQuery($dql);
//			$query->execute();

			$sql = "UPDATE {$tableName}
					SET lvl = lvl + IF(lft BETWEEN {$left} AND {$right}, {$levelDiff}, 0),
						lft = lft + IF(lft BETWEEN {$left} AND {$right}, {$moveA}, IF(lft BETWEEN {$a} AND {$b}, {$moveB}, 0)),
						rgt = rgt + IF(rgt BETWEEN {$left} AND {$right}, {$moveA}, IF(rgt BETWEEN {$a} AND {$b}, {$moveB}, 0))
					WHERE (lft BETWEEN {$min} AND {$max}
						OR rgt BETWEEN {$min} AND {$max})";

			$sql .= $self->getAdditionalConditionSql('AND');

			$entityManager->getConnection()
					->exec($sql);
			
			// Change node parameters locally as well
			// TODO: how to rollback these changes if nested set post move trigger fails?
			$arrayHelper->move($node, $pos, $levelDiff);
		});
		
		// Trigger post move event. Only after transaction is commited because
		// public schema must update it's stuff as well
		try {
			$masterNode = $node->getMasterNode();
			$eventArgs = new Event\NestedSetEventArgs($masterNode, $this->entityManager);
			$this->entityManager->getEventManager()
					->dispatchEvent(Event\NestedSetEvents::nestedSetPostMove, $eventArgs);
		} catch (\Exception $e) {
			
			//TODO: new pages should be removed
			
			// Should not happen
			if ($undoMove) {
				throw $e;
			}
			
			// Undo move
			$this->move($node, $oldPosition, - $levelDiff, true);
			
			throw $e;
		}
	}
680197
public function moveDataFile($from, $to)
    {
        if (str_contains($from, '*.')) {
            $this->moveFilesWildcard($from, $to);

            return;
        }

        if (file_exists($from = $this->dataDir($from))) {
            $this->mkDir(dirname($to = $this->dataDir($to)));

            rename($from, $to);
        }
    }
1324552
private function diffMissing(array $toTranslations, array $fromTranslations, $locale)
    {
        $diff = array_diff_key($toTranslations, $fromTranslations);

        if (count($diff) === 0)
            return;

        foreach ($diff as $transKey => $transValue) {
            $this->addMissing($locale, $transKey);
        }
    }
796177
public function SetAddressAsShippingAddress($sAddressId)
    {
        $oOldShippingAddress = clone $this->GetShippingAddress();
        $oOldBillingAddress = clone $this->GetBillingAddress();

        $oNewShippingAddress = parent::SetAddressAsShippingAddress($sAddressId);

        if (false === $oNewShippingAddress->hasSameDataInSqlData($oOldShippingAddress)) {
            $this->hookChangedShippingAddress($oOldShippingAddress, $oNewShippingAddress);
        }

        $oNewBillingAddress = $this->GetBillingAddress();
        if (false === $oNewBillingAddress->hasSameDataInSqlData($oOldBillingAddress)) {
            $this->hookChangedBillingAddress($oOldBillingAddress, $oNewBillingAddress);
        }

        return $oNewShippingAddress;
    }
1207030
public function removeAddressRelation($contact, $contactAddress)
    {
        if (!$contact || !$contactAddress) {
            throw new \Exception('Contact and ContactAddress cannot be null');
        }

        // reload address to get all data (including relational data)
        /** @var Address $address */
        $address = $contactAddress->getAddress();
        $address = $this->em->getRepository(
            'SuluContactBundle:Address'
        )->findById($address->getId());

        $isMain = $contactAddress->getMain();

        // remove relation
        $contact->removeContactAddress($contactAddress);
        $address->removeContactAddress($contactAddress);

        // if was main, set a new one
        if ($isMain) {
            $this->setMainForCollection($contact->getContactAddresses());
        }

        // delete address if it has no more relations
        if (!$address->hasRelations()) {
            $this->em->remove($address);
        }

        $this->em->remove($contactAddress);
    }
992026
public function move($from, $to)
    {
        return $this->filesystem->move(
            $this->path($from),
            $this->path($to)
        );
    }
536129
public function moveFilesWildcard($from, $to)
    {
        coollect(glob($this->dataDir($from)))->each(function ($from) use ($to) {
            $this->mkDir($dir = $this->dataDir($to));

            rename($from, $dir.'/'.basename($from));
        });
    }
935150
public function send($toAddress) {
		if( empty($toAddress) || (!self::is_email($toAddress) && !is_array($toAddress)) ) {
			throw new \Exception('InvalidEmailAddress');
		}
		
		if( $this->isMultiContent() ) {
			$boundary = $this->getBoundary();
			$this->setHeader('MIME-Version', '1.0');
			$this->setHeader('Content-Type', "multipart/alternative; boundary=\"{$boundary}\"");
			$body = '';
			$ContentsArr = array();
			if( $this->isAlternative() ) {
				$ContentsArr[] = array(
					'headers' => array(
						'Content-Type' => 'multipart/alternative',
					),
					'body' => ( mb_detect_encoding($this->altBody, 'UTF-8') === 'UTF-8' ) ? utf8_decode($this->altBody) : $this->altBody,
				);
			}
			
			if( $this->isTEXT() ) {
				$ContentsArr[] = array(
					'headers' => array(
						'Content-Type' => 'text/plain; charset="UTF-8"',
						'Content-Transfer-Encoding' => 'quoted-printable',
					),
					'body' => $this->textBody,
				);
			}
			
			if( $this->isHTML() ) {
				$ContentsArr[] = array(
					'headers' => array(
						'Content-Type' => 'text/html; charset="UTF-8"',
						'Content-Transfer-Encoding' => 'quoted-printable',
					),
					'body' => $this->htmlBody,
				);
			}
			
			if( $this->containsFiles() ) {
				$this->setHeader('Content-Type', "multipart/mixed; boundary=\"{$boundary}\"");
				
				//With files, mail content is overloaded, also we make a blocklist under a bloc with own boundary.
				$subContentsArr = $ContentsArr;
				if( !empty($subContentsArr) ) {
					$ContentsArr = array();
					$subBoundary = $this->getBoundary(1);
					$subBody = '';
					
					foreach($subContentsArr as $Content) {
						$subHeaders = '';
						$Content['headers']['Content-Type'] .= '; format=flowed';
						foreach( $Content['headers'] as $headerName => $headerValue ) {
							$subHeaders .= "{$headerName}: {$headerValue}\r\n";
						}
						$subBody .= <<<BODY
--{$subBoundary}\r\n{$subHeaders}\r\n{$Content['body']}\r\n\r\n
BODY;
					}
					$subBody .= <<<BODY
--{$subBoundary}--
BODY;
					$ContentsArr[] = array(
						'headers' => array(
							'Content-Type' => "multipart/alternative; boundary=\"{$subBoundary}\"",
						),
						'body' => $subBody,
					);
					
				}
				
				foreach( $this->attachedFiles as $fileName ) {
					if( !is_readable($fileName) ) {
						continue;
					}
					$ContentsArr[] = array(
						'headers' => array(
							'Content-Type' => self::getMimeType($fileName).'; name="'.pathinfo($fileName, PATHINFO_BASENAME).'"',
							'Content-Transfer-Encoding' => 'base64',
							'Content-Disposition' => 'attachment; filename="'.pathinfo($fileName, PATHINFO_BASENAME).'"',
						),
						'body' => chunk_split(base64_encode(file_get_contents($fileName))),
					);
				}
			}
			if( !empty($ContentsArr) ) {
				$body = '';
				
				foreach($ContentsArr as $Content) {
					$ContentHeaders = '';
					
					if( empty($Content['headers']) ) {
						throw new \Exception('ContentRequireHeaders');
					}
					if( empty($Content['body']) ) {
						throw new \Exception('ContentRequireBody');
					}
					foreach( $Content['headers'] as $headerName => $headerValue ) {
						$ContentHeaders .= "{$headerName}: {$headerValue}\r\n";
					}
					$body .= <<<BODY
--{$boundary}\r\n{$ContentHeaders}\r\n{$Content['body']}\r\n\r\n
BODY;
				}
				$body .= <<<BODY
--{$boundary}--
BODY;
			}
			
		} else {
			if( $this->isHTML() ) {
				$this->setHeader('MIME-Version', '1.0');
				$this->setHeader('Content-Type', 'text/html; charset="UTF-8"');
				$this->setHeader('Content-Transfer-Encoding', 'quoted-printable');
				$body = $this->htmlBody;
			
			} else if( $this->isTEXT() ) {
				$this->setHeader('MIME-Version', '');
				$this->setHeader('Content-Type', 'text/plain; charset="UTF-8"');
				$this->setHeader('Content-Transfer-Encoding', 'quoted-printable');
				$body = $this->textBody;
			}
		}
		if( empty($body) ) {
			throw new \Exception('emptyMailBody');
		}
		
		$headers = '';
		foreach( $this->headers as $headerName => $headerValue ) {
			if( !empty($headerValue) ) {
				$headers .= "{$headerName}: {$headerValue}\r\n";
			}
		}
		$headers .= "\r\n";
		if( !is_array($toAddress) ) {
			if( !mail($toAddress, $this->subject, $body, $headers) ) {
				throw new \Exception("issueSendingEmail");
			}
		} else {
			foreach(array_unique($toAddress) as $MailToData) {
				$MailToEmail = '';
				if( self::is_email($MailToData) ) {
					$MailToEmail = $MailToData;
					
				//More compatibilities with array of data.
				} else if( is_array($MailToData) ) {
					if( !empty($MailToData['mail']) && self::is_email($MailToData['mail']) ) {
						$MailToEmail = $MailToData['mail'];
					} elseif( !empty($MailToData['email']) && self::is_email($MailToData['email']) ) {
						$MailToEmail = $MailToData['email'];
					}
				}
				if( empty($MailToEmail) ) { continue; }
// 					throw new \Exception("EmptyEmailAddress");

				if( !mail($MailToEmail, $this->subject, $body, $headers)) {
					throw new \Exception('issueSendingEmail');
				}
			}
		}
		return true;
	}
352757
public function from($from = NULL) {
		if ($from !== NULL) {
			$from = intval($from);
		}

		$this->from = intval($from);
		return $this;
	}
427145
public function move($dest)
    { 
		$tree = new CDBTree('dir_structure');
        $prntid = self::getDbConnection()->fetchColumn('select id from dir_structure where data_id=?', array($dest));
        $strid = self::getDbConnection()->fetchColumn('select id from dir_structure where data_id=?', array($this->id));
		$tree->moveAll($strid, $prntid); 
		
        $this->_url = false;
        $this->_fullUrl = false;
        $this->_treePath = false;
        $this->_path = false;
         
        $this->updateCache();
    }
567662
public function setFrom($from = [])
    {
        $this->from = $from;
        $this->debug->debug(__FUNCTION__, 'setFrom: ', $this->from);
    }
660517
private function setEmailAddress(?string $emailAddress): self
    {
        $this->updatePropertyValue(
            EmailAddressFieldInterface::PROP_EMAIL_ADDRESS,
            $emailAddress
        );

        return $this;
    }
912893
public function from($from, $from_name = '')
    {
        $this->from      = $from;
        $this->from_name = $from_name;
        return $this;
    }
679027
private long move(long fromBaseAddress, long capacity, MemoryAllocator fromMalloc, MemoryAllocator toMalloc) {
        final long allocatedSize = HEADER_SIZE + capacity * slotLength;
        final long toBaseAddress = toMalloc.allocate(allocatedSize) + HEADER_SIZE;
        mem.copyMemory(fromBaseAddress - HEADER_SIZE, toBaseAddress - HEADER_SIZE, allocatedSize);
        fromMalloc.free(fromBaseAddress - HEADER_SIZE, allocatedSize);
        return toBaseAddress;
    }
1171548
public function setFromAddress($emailAddress)
    {
        if (filter_var($emailAddress, FILTER_VALIDATE_EMAIL) !== $emailAddress) {
            throw new \InvalidArgumentException('Invalid email address: '.$emailAddress);
        }
        $this->fromAddress = $emailAddress;
    }
166628
public function ipInRange($ip, $from, $to)
    {
        $ip = $this->getIpNumberFromAddress($ip);
        $from = $this->getIpNumberFromAddress($from);
        $to = $this->getIpNumberFromAddress($to);

        return (!$ip || !$from || !$to) ? false : ($ip <= $to && $from <= $ip);
    }