src/services/RedirectsService.php
public function save ($uri, $to, $type, $siteId = null, $id = null)
	{
		if ($siteId === 'null')
			$siteId = null;

		if ($id)
		{
			$record = RedirectRecord::findOne(compact('id'));

			if (!$record)
				return 'Unable to find redirect with ID: ' . $id;
		}
		else
		{
			$existing = RedirectRecord::findOne(compact('uri', 'siteId'));

			if ($existing)
				return 'A redirect with that URI already exists!';

			$record = new RedirectRecord();
		}

		$record->uri    = $uri;
		$record->to     = $to;
		$record->type   = $type;
		if ($siteId !== false)
			$record->siteId = $siteId;

		if (!$record->save())
			return $record->getErrors();

		return $record->id;
	}
public function save ($uri, $to, $type, $siteId = null, $id = null)
	{
		if ($siteId === 'null')
			$siteId = null;

		if ($id)
		{
			$record = RedirectRecord::findOne(compact('id'));

			if (!$record)
				return 'Unable to find redirect with ID: ' . $id;
		}
		else
		{
			$existing = RedirectRecord::findOne(compact('uri', 'siteId'));

			if ($existing)
				return 'A redirect with that URI already exists!';

			$record = new RedirectRecord();
		}

		$record->uri    = $uri;
		$record->to     = $to;
		$record->type   = $type;
		if ($siteId !== false)
			$record->siteId = $siteId;

		if (!$record->save())
			return $record->getErrors();

		return $record->id;
	}
public function save ( $ uri , $ to , $ type , $ siteId = null , $ id = null ) { if ( $ siteId === 'null' ) $ siteId = null ; if ( $ id ) { $ record = RedirectRecord :: findOne ( compact ( 'id' ) ) ; if ( ! $ record ) return 'Unable to find redirect with ID: ' . $ id ; } else { $ existing = RedirectRecord :: findOne ( compact ( 'uri' , 'siteId' ) ) ; if ( $ existing ) return 'A redirect with that URI already exists!' ; $ record = new RedirectRecord ( ) ; } $ record -> uri = $ uri ; $ record -> to = $ to ; $ record -> type = $ type ; if ( $ siteId !== false ) $ record -> siteId = $ siteId ; if ( ! $ record -> save ( ) ) return $ record -> getErrors ( ) ; return $ record -> id ; }
Saves the redirect

@param string   $uri
@param string   $to
@param string   $type
@param null     $siteId
@param int|null $id

@return array|int|string
Saves the redirect