repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
cartalyst/sentry | src/Cartalyst/Sentry/Facades/Native/Sentry.php | Sentry.guessIpAddress | public static function guessIpAddress()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
{
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ipAddress)
{
$ipAddress = trim($ipAddress);
if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
{
return $ipAddress;
}
}
}
}
} | php | public static function guessIpAddress()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
{
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ipAddress)
{
$ipAddress = trim($ipAddress);
if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
{
return $ipAddress;
}
}
}
}
} | [
"public",
"static",
"function",
"guessIpAddress",
"(",
")",
"{",
"foreach",
"(",
"array",
"(",
"'HTTP_CLIENT_IP'",
",",
"'HTTP_X_FORWARDED_FOR'",
",",
"'HTTP_X_FORWARDED'",
",",
"'HTTP_X_CLUSTER_CLIENT_IP'",
",",
"'HTTP_FORWARDED_FOR'",
",",
"'HTTP_FORWARDED'",
",",
"'REMOTE_ADDR'",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"_SERVER",
")",
"===",
"true",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"_SERVER",
"[",
"$",
"key",
"]",
")",
"as",
"$",
"ipAddress",
")",
"{",
"$",
"ipAddress",
"=",
"trim",
"(",
"$",
"ipAddress",
")",
";",
"if",
"(",
"filter_var",
"(",
"$",
"ipAddress",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_NO_PRIV_RANGE",
"|",
"FILTER_FLAG_NO_RES_RANGE",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"ipAddress",
";",
"}",
"}",
"}",
"}",
"}"
] | Looks through various server properties in an attempt
to guess the client's IP address.
@return string $ipAddress | [
"Looks",
"through",
"various",
"server",
"properties",
"in",
"an",
"attempt",
"to",
"guess",
"the",
"client",
"s",
"IP",
"address",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Facades/Native/Sentry.php#L100-L117 |
cartalyst/sentry | src/Cartalyst/Sentry/Cookies/NativeCookie.php | NativeCookie.setCookie | public function setCookie($value, $lifetime, $path = null, $domain = null, $secure = null, $httpOnly = null)
{
// Default parameters
if ( ! isset($path)) $path = $this->defaults['path'];
if ( ! isset($domain)) $domain = $this->defaults['domain'];
if ( ! isset($secure)) $secure = $this->defaults['secure'];
if ( ! isset($httpOnly)) $httpOnly = $this->defaults['http_only'];
setcookie($this->getKey(), json_encode($value), $lifetime, $path, $domain, $secure, $httpOnly);
} | php | public function setCookie($value, $lifetime, $path = null, $domain = null, $secure = null, $httpOnly = null)
{
// Default parameters
if ( ! isset($path)) $path = $this->defaults['path'];
if ( ! isset($domain)) $domain = $this->defaults['domain'];
if ( ! isset($secure)) $secure = $this->defaults['secure'];
if ( ! isset($httpOnly)) $httpOnly = $this->defaults['http_only'];
setcookie($this->getKey(), json_encode($value), $lifetime, $path, $domain, $secure, $httpOnly);
} | [
"public",
"function",
"setCookie",
"(",
"$",
"value",
",",
"$",
"lifetime",
",",
"$",
"path",
"=",
"null",
",",
"$",
"domain",
"=",
"null",
",",
"$",
"secure",
"=",
"null",
",",
"$",
"httpOnly",
"=",
"null",
")",
"{",
"// Default parameters",
"if",
"(",
"!",
"isset",
"(",
"$",
"path",
")",
")",
"$",
"path",
"=",
"$",
"this",
"->",
"defaults",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"domain",
")",
")",
"$",
"domain",
"=",
"$",
"this",
"->",
"defaults",
"[",
"'domain'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"secure",
")",
")",
"$",
"secure",
"=",
"$",
"this",
"->",
"defaults",
"[",
"'secure'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"httpOnly",
")",
")",
"$",
"httpOnly",
"=",
"$",
"this",
"->",
"defaults",
"[",
"'http_only'",
"]",
";",
"setcookie",
"(",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"json_encode",
"(",
"$",
"value",
")",
",",
"$",
"lifetime",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
",",
"$",
"httpOnly",
")",
";",
"}"
] | Actually sets the cookie.
@param mixed $value
@param int $lifetime
@param string $path
@param string $domain
@param bool $secure
@param bool $httpOnly
@return void | [
"Actually",
"sets",
"the",
"cookie",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Cookies/NativeCookie.php#L141-L150 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/Provider.php | Provider.findById | public function findById($id)
{
$model = $this->createModel();
if ( ! $user = $model->newQuery()->find($id))
{
throw new UserNotFoundException("A user could not be found with ID [$id].");
}
return $user;
} | php | public function findById($id)
{
$model = $this->createModel();
if ( ! $user = $model->newQuery()->find($id))
{
throw new UserNotFoundException("A user could not be found with ID [$id].");
}
return $user;
} | [
"public",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user could not be found with ID [$id].\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given user ID.
@param mixed $id
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"user",
"ID",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/Provider.php#L71-L81 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/Provider.php | Provider.findByLogin | public function findByLogin($login)
{
$model = $this->createModel();
if ( ! $user = $model->newQuery()->where($model->getLoginName(), '=', $login)->first())
{
throw new UserNotFoundException("A user could not be found with a login value of [$login].");
}
return $user;
} | php | public function findByLogin($login)
{
$model = $this->createModel();
if ( ! $user = $model->newQuery()->where($model->getLoginName(), '=', $login)->first())
{
throw new UserNotFoundException("A user could not be found with a login value of [$login].");
}
return $user;
} | [
"public",
"function",
"findByLogin",
"(",
"$",
"login",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"where",
"(",
"$",
"model",
"->",
"getLoginName",
"(",
")",
",",
"'='",
",",
"$",
"login",
")",
"->",
"first",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user could not be found with a login value of [$login].\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the login value.
@param string $login
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"login",
"value",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/Provider.php#L90-L100 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/Provider.php | Provider.findByCredentials | public function findByCredentials(array $credentials)
{
$model = $this->createModel();
$loginName = $model->getLoginName();
if ( ! array_key_exists($loginName, $credentials))
{
throw new \InvalidArgumentException("Login attribute [$loginName] was not provided.");
}
$passwordName = $model->getPasswordName();
$query = $model->newQuery();
$hashableAttributes = $model->getHashableAttributes();
$hashedCredentials = array();
// build query from given credentials
foreach ($credentials as $credential => $value)
{
// Remove hashed attributes to check later as we need to check these
// values after we retrieved them because of salts
if (in_array($credential, $hashableAttributes))
{
$hashedCredentials = array_merge($hashedCredentials, array($credential => $value));
}
else
{
$query = $query->where($credential, '=', $value);
}
}
if ( ! $user = $query->first())
{
throw new UserNotFoundException("A user was not found with the given credentials.");
}
// Now check the hashed credentials match ours
foreach ($hashedCredentials as $credential => $value)
{
if ( ! $this->hasher->checkhash($value, $user->{$credential}))
{
$message = "A user was found to match all plain text credentials however hashed credential [$credential] did not match.";
if ($credential == $passwordName)
{
throw new WrongPasswordException($message);
}
throw new UserNotFoundException($message);
}
else if ($credential == $passwordName)
{
if (method_exists($this->hasher, 'needsRehashed') &&
$this->hasher->needsRehashed($user->{$credential}))
{
// The algorithm used to create the hash is outdated and insecure.
// Rehash the password and save.
$user->{$credential} = $value;
$user->save();
}
}
}
return $user;
} | php | public function findByCredentials(array $credentials)
{
$model = $this->createModel();
$loginName = $model->getLoginName();
if ( ! array_key_exists($loginName, $credentials))
{
throw new \InvalidArgumentException("Login attribute [$loginName] was not provided.");
}
$passwordName = $model->getPasswordName();
$query = $model->newQuery();
$hashableAttributes = $model->getHashableAttributes();
$hashedCredentials = array();
// build query from given credentials
foreach ($credentials as $credential => $value)
{
// Remove hashed attributes to check later as we need to check these
// values after we retrieved them because of salts
if (in_array($credential, $hashableAttributes))
{
$hashedCredentials = array_merge($hashedCredentials, array($credential => $value));
}
else
{
$query = $query->where($credential, '=', $value);
}
}
if ( ! $user = $query->first())
{
throw new UserNotFoundException("A user was not found with the given credentials.");
}
// Now check the hashed credentials match ours
foreach ($hashedCredentials as $credential => $value)
{
if ( ! $this->hasher->checkhash($value, $user->{$credential}))
{
$message = "A user was found to match all plain text credentials however hashed credential [$credential] did not match.";
if ($credential == $passwordName)
{
throw new WrongPasswordException($message);
}
throw new UserNotFoundException($message);
}
else if ($credential == $passwordName)
{
if (method_exists($this->hasher, 'needsRehashed') &&
$this->hasher->needsRehashed($user->{$credential}))
{
// The algorithm used to create the hash is outdated and insecure.
// Rehash the password and save.
$user->{$credential} = $value;
$user->save();
}
}
}
return $user;
} | [
"public",
"function",
"findByCredentials",
"(",
"array",
"$",
"credentials",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"loginName",
"=",
"$",
"model",
"->",
"getLoginName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"loginName",
",",
"$",
"credentials",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Login attribute [$loginName] was not provided.\"",
")",
";",
"}",
"$",
"passwordName",
"=",
"$",
"model",
"->",
"getPasswordName",
"(",
")",
";",
"$",
"query",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
";",
"$",
"hashableAttributes",
"=",
"$",
"model",
"->",
"getHashableAttributes",
"(",
")",
";",
"$",
"hashedCredentials",
"=",
"array",
"(",
")",
";",
"// build query from given credentials",
"foreach",
"(",
"$",
"credentials",
"as",
"$",
"credential",
"=>",
"$",
"value",
")",
"{",
"// Remove hashed attributes to check later as we need to check these",
"// values after we retrieved them because of salts",
"if",
"(",
"in_array",
"(",
"$",
"credential",
",",
"$",
"hashableAttributes",
")",
")",
"{",
"$",
"hashedCredentials",
"=",
"array_merge",
"(",
"$",
"hashedCredentials",
",",
"array",
"(",
"$",
"credential",
"=>",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"where",
"(",
"$",
"credential",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"query",
"->",
"first",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user was not found with the given credentials.\"",
")",
";",
"}",
"// Now check the hashed credentials match ours",
"foreach",
"(",
"$",
"hashedCredentials",
"as",
"$",
"credential",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasher",
"->",
"checkhash",
"(",
"$",
"value",
",",
"$",
"user",
"->",
"{",
"$",
"credential",
"}",
")",
")",
"{",
"$",
"message",
"=",
"\"A user was found to match all plain text credentials however hashed credential [$credential] did not match.\"",
";",
"if",
"(",
"$",
"credential",
"==",
"$",
"passwordName",
")",
"{",
"throw",
"new",
"WrongPasswordException",
"(",
"$",
"message",
")",
";",
"}",
"throw",
"new",
"UserNotFoundException",
"(",
"$",
"message",
")",
";",
"}",
"else",
"if",
"(",
"$",
"credential",
"==",
"$",
"passwordName",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"hasher",
",",
"'needsRehashed'",
")",
"&&",
"$",
"this",
"->",
"hasher",
"->",
"needsRehashed",
"(",
"$",
"user",
"->",
"{",
"$",
"credential",
"}",
")",
")",
"{",
"// The algorithm used to create the hash is outdated and insecure.",
"// Rehash the password and save.",
"$",
"user",
"->",
"{",
"$",
"credential",
"}",
"=",
"$",
"value",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given credentials.
@param array $credentials
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"credentials",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/Provider.php#L109-L173 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/Provider.php | Provider.findByActivationCode | public function findByActivationCode($code)
{
if ( ! $code)
{
throw new \InvalidArgumentException("No activation code passed.");
}
$model = $this->createModel();
$result = $model->newQuery()->where('activation_code', '=', $code)->get();
if (($count = $result->count()) > 1)
{
throw new \RuntimeException("Found [$count] users with the same activation code.");
}
if ( ! $user = $result->first())
{
throw new UserNotFoundException("A user was not found with the given activation code.");
}
return $user;
} | php | public function findByActivationCode($code)
{
if ( ! $code)
{
throw new \InvalidArgumentException("No activation code passed.");
}
$model = $this->createModel();
$result = $model->newQuery()->where('activation_code', '=', $code)->get();
if (($count = $result->count()) > 1)
{
throw new \RuntimeException("Found [$count] users with the same activation code.");
}
if ( ! $user = $result->first())
{
throw new UserNotFoundException("A user was not found with the given activation code.");
}
return $user;
} | [
"public",
"function",
"findByActivationCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"$",
"code",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No activation code passed.\"",
")",
";",
"}",
"$",
"model",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"result",
"=",
"$",
"model",
"->",
"newQuery",
"(",
")",
"->",
"where",
"(",
"'activation_code'",
",",
"'='",
",",
"$",
"code",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"(",
"$",
"count",
"=",
"$",
"result",
"->",
"count",
"(",
")",
")",
">",
"1",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Found [$count] users with the same activation code.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"=",
"$",
"result",
"->",
"first",
"(",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"\"A user was not found with the given activation code.\"",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Finds a user by the given activation code.
@param string $code
@return \Cartalyst\Sentry\Users\UserInterface
@throws \Cartalyst\Sentry\Users\UserNotFoundException
@throws InvalidArgumentException
@throws RuntimeException | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"activation",
"code",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/Provider.php#L184-L206 |
cartalyst/sentry | src/Cartalyst/Sentry/Users/Eloquent/Provider.php | Provider.create | public function create(array $credentials)
{
$user = $this->createModel();
$user->fill($credentials);
$user->save();
return $user;
} | php | public function create(array $credentials)
{
$user = $this->createModel();
$user->fill($credentials);
$user->save();
return $user;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"credentials",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"createModel",
"(",
")",
";",
"$",
"user",
"->",
"fill",
"(",
"$",
"credentials",
")",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Creates a user.
@param array $credentials
@return \Cartalyst\Sentry\Users\UserInterface | [
"Creates",
"a",
"user",
"."
] | train | https://github.com/cartalyst/sentry/blob/c679730b8848686f59125cd821bf94946fb16a94/src/Cartalyst/Sentry/Users/Eloquent/Provider.php#L293-L300 |
kaliop-uk/ezmigrationbundle | Core/DefinitionParser/AbstractDefinitionParser.php | AbstractDefinitionParser.parseMigrationDefinitionData | protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml')
{
// basic validation
/// @todo move to using the Validator component...
$status = MigrationDefinition::STATUS_PARSED;
if (!is_array($data)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "$format migration file '{$definition->path}' must contain an array as top element";
} else {
foreach ($data as $i => $stepDef) {
if (!isset($stepDef['type']) || !is_string($stepDef['type'])) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i";
break;
}
}
}
if ($status != MigrationDefinition::STATUS_PARSED)
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
$status,
array(),
$message
);
}
$stepDefs = array();
foreach ($data as $stepDef) {
$type = $stepDef['type'];
unset($stepDef['type']);
$stepDefs[] = new MigrationStep($type, $stepDef, array('path' => $definition->path));
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
$stepDefs
);
} | php | protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml')
{
// basic validation
/// @todo move to using the Validator component...
$status = MigrationDefinition::STATUS_PARSED;
if (!is_array($data)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "$format migration file '{$definition->path}' must contain an array as top element";
} else {
foreach ($data as $i => $stepDef) {
if (!isset($stepDef['type']) || !is_string($stepDef['type'])) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i";
break;
}
}
}
if ($status != MigrationDefinition::STATUS_PARSED)
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
$status,
array(),
$message
);
}
$stepDefs = array();
foreach ($data as $stepDef) {
$type = $stepDef['type'];
unset($stepDef['type']);
$stepDefs[] = new MigrationStep($type, $stepDef, array('path' => $definition->path));
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
$stepDefs
);
} | [
"protected",
"function",
"parseMigrationDefinitionData",
"(",
"$",
"data",
",",
"MigrationDefinition",
"$",
"definition",
",",
"$",
"format",
"=",
"'Yaml'",
")",
"{",
"// basic validation",
"/// @todo move to using the Validator component...",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_PARSED",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"\"$format migration file '{$definition->path}' must contain an array as top element\"",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"i",
"=>",
"$",
"stepDef",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"stepDef",
"[",
"'type'",
"]",
")",
"||",
"!",
"is_string",
"(",
"$",
"stepDef",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"\"$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i\"",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"status",
"!=",
"MigrationDefinition",
"::",
"STATUS_PARSED",
")",
"{",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"$",
"status",
",",
"array",
"(",
")",
",",
"$",
"message",
")",
";",
"}",
"$",
"stepDefs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"stepDef",
")",
"{",
"$",
"type",
"=",
"$",
"stepDef",
"[",
"'type'",
"]",
";",
"unset",
"(",
"$",
"stepDef",
"[",
"'type'",
"]",
")",
";",
"$",
"stepDefs",
"[",
"]",
"=",
"new",
"MigrationStep",
"(",
"$",
"type",
",",
"$",
"stepDef",
",",
"array",
"(",
"'path'",
"=>",
"$",
"definition",
"->",
"path",
")",
")",
";",
"}",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_PARSED",
",",
"$",
"stepDefs",
")",
";",
"}"
] | Parses a migration definition in the form of an array of steps
@param array $data
@param MigrationDefinition $definition
@param string $format
@return MigrationDefinition | [
"Parses",
"a",
"migration",
"definition",
"in",
"the",
"form",
"of",
"an",
"array",
"of",
"steps"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/DefinitionParser/AbstractDefinitionParser.php#L18-L65 |
kaliop-uk/ezmigrationbundle | Core/Matcher/UserGroupMatcher.php | UserGroupMatcher.getConditionsFromKey | protected function getConditionsFromKey($key)
{
if (is_int($key) || ctype_digit($key)) {
return array(self::MATCH_USERGROUP_ID => $key);
}
return array(self::MATCH_CONTENT_REMOTE_ID => $key);
} | php | protected function getConditionsFromKey($key)
{
if (is_int($key) || ctype_digit($key)) {
return array(self::MATCH_USERGROUP_ID => $key);
}
return array(self::MATCH_CONTENT_REMOTE_ID => $key);
} | [
"protected",
"function",
"getConditionsFromKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
"||",
"ctype_digit",
"(",
"$",
"key",
")",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"MATCH_USERGROUP_ID",
"=>",
"$",
"key",
")",
";",
"}",
"return",
"array",
"(",
"self",
"::",
"MATCH_CONTENT_REMOTE_ID",
"=>",
"$",
"key",
")",
";",
"}"
] | When matching by key, we accept user group Id and it's remote Id only
@param int|string $key
@return array | [
"When",
"matching",
"by",
"key",
"we",
"accept",
"user",
"group",
"Id",
"and",
"it",
"s",
"remote",
"Id",
"only"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Matcher/UserGroupMatcher.php#L76-L82 |
kaliop-uk/ezmigrationbundle | Core/Executor/ObjectStateManager.php | ObjectStateManager.create | protected function create($step)
{
foreach (array('object_state_group', 'names', 'identifier') as $key) {
if (!isset($step->dsl[$key])) {
throw new \Exception("The '$key' key is missing in a object state creation definition");
}
}
if (!count($step->dsl['names'])) {
throw new \Exception('No object state names have been defined. Need to specify at least one to create the state.');
}
$objectStateService = $this->repository->getObjectStateService();
$objectStateGroupId = $step->dsl['object_state_group'];
$objectStateGroupId = $this->referenceResolver->resolveReference($objectStateGroupId);
$objectStateGroup = $this->objectStateGroupMatcher->matchOneByKey($objectStateGroupId);
$objectStateIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($objectStateIdentifier);
$objectStateCreateStruct->defaultLanguageCode = $this->getLanguageCode($step); // was: self::DEFAULT_LANGUAGE_CODE;
foreach ($step->dsl['names'] as $languageCode => $name) {
$objectStateCreateStruct->names[$languageCode] = $name;
}
if (isset($step->dsl['descriptions'])) {
foreach ($step->dsl['descriptions'] as $languageCode => $description) {
$objectStateCreateStruct->descriptions[$languageCode] = $description;
}
}
$objectState = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);
$this->setReferences($objectState, $step);
return $objectState;
} | php | protected function create($step)
{
foreach (array('object_state_group', 'names', 'identifier') as $key) {
if (!isset($step->dsl[$key])) {
throw new \Exception("The '$key' key is missing in a object state creation definition");
}
}
if (!count($step->dsl['names'])) {
throw new \Exception('No object state names have been defined. Need to specify at least one to create the state.');
}
$objectStateService = $this->repository->getObjectStateService();
$objectStateGroupId = $step->dsl['object_state_group'];
$objectStateGroupId = $this->referenceResolver->resolveReference($objectStateGroupId);
$objectStateGroup = $this->objectStateGroupMatcher->matchOneByKey($objectStateGroupId);
$objectStateIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($objectStateIdentifier);
$objectStateCreateStruct->defaultLanguageCode = $this->getLanguageCode($step); // was: self::DEFAULT_LANGUAGE_CODE;
foreach ($step->dsl['names'] as $languageCode => $name) {
$objectStateCreateStruct->names[$languageCode] = $name;
}
if (isset($step->dsl['descriptions'])) {
foreach ($step->dsl['descriptions'] as $languageCode => $description) {
$objectStateCreateStruct->descriptions[$languageCode] = $description;
}
}
$objectState = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);
$this->setReferences($objectState, $step);
return $objectState;
} | [
"protected",
"function",
"create",
"(",
"$",
"step",
")",
"{",
"foreach",
"(",
"array",
"(",
"'object_state_group'",
",",
"'names'",
",",
"'identifier'",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The '$key' key is missing in a object state creation definition\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"count",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'names'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'No object state names have been defined. Need to specify at least one to create the state.'",
")",
";",
"}",
"$",
"objectStateService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getObjectStateService",
"(",
")",
";",
"$",
"objectStateGroupId",
"=",
"$",
"step",
"->",
"dsl",
"[",
"'object_state_group'",
"]",
";",
"$",
"objectStateGroupId",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"objectStateGroupId",
")",
";",
"$",
"objectStateGroup",
"=",
"$",
"this",
"->",
"objectStateGroupMatcher",
"->",
"matchOneByKey",
"(",
"$",
"objectStateGroupId",
")",
";",
"$",
"objectStateIdentifier",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'identifier'",
"]",
")",
";",
"$",
"objectStateCreateStruct",
"=",
"$",
"objectStateService",
"->",
"newObjectStateCreateStruct",
"(",
"$",
"objectStateIdentifier",
")",
";",
"$",
"objectStateCreateStruct",
"->",
"defaultLanguageCode",
"=",
"$",
"this",
"->",
"getLanguageCode",
"(",
"$",
"step",
")",
";",
"// was: self::DEFAULT_LANGUAGE_CODE;",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'names'",
"]",
"as",
"$",
"languageCode",
"=>",
"$",
"name",
")",
"{",
"$",
"objectStateCreateStruct",
"->",
"names",
"[",
"$",
"languageCode",
"]",
"=",
"$",
"name",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'descriptions'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'descriptions'",
"]",
"as",
"$",
"languageCode",
"=>",
"$",
"description",
")",
"{",
"$",
"objectStateCreateStruct",
"->",
"descriptions",
"[",
"$",
"languageCode",
"]",
"=",
"$",
"description",
";",
"}",
"}",
"$",
"objectState",
"=",
"$",
"objectStateService",
"->",
"createObjectState",
"(",
"$",
"objectStateGroup",
",",
"$",
"objectStateCreateStruct",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"objectState",
",",
"$",
"step",
")",
";",
"return",
"$",
"objectState",
";",
"}"
] | Handles the create step of object state migrations.
@throws \Exception | [
"Handles",
"the",
"create",
"step",
"of",
"object",
"state",
"migrations",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/ObjectStateManager.php#L48-L84 |
kaliop-uk/ezmigrationbundle | Core/Executor/ObjectStateManager.php | ObjectStateManager.update | protected function update($step)
{
$stateCollection = $this->matchObjectStates('update', $step);
if (count($stateCollection) > 1 && array_key_exists('references', $step->dsl)) {
throw new \Exception("Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches");
}
if (count($stateCollection) > 1 && isset($step->dsl['identifier'])) {
throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.");
}
$objectStateService = $this->repository->getObjectStateService();
foreach ($stateCollection as $state) {
$objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct();
if (isset($step->dsl['identifier'])) {
$objectStateUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
}
if (isset($step->dsl['names'])) {
foreach ($step->dsl['names'] as $name) {
$objectStateUpdateStruct->names[$name['languageCode']] = $name['name'];
}
}
if (isset($step->dsl['descriptions'])) {
foreach ($step->dsl['descriptions'] as $languageCode => $description) {
$objectStateUpdateStruct->descriptions[$languageCode] = $description;
}
}
$state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct);
$this->setReferences($state, $step);
}
return $stateCollection;
} | php | protected function update($step)
{
$stateCollection = $this->matchObjectStates('update', $step);
if (count($stateCollection) > 1 && array_key_exists('references', $step->dsl)) {
throw new \Exception("Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches");
}
if (count($stateCollection) > 1 && isset($step->dsl['identifier'])) {
throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.");
}
$objectStateService = $this->repository->getObjectStateService();
foreach ($stateCollection as $state) {
$objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct();
if (isset($step->dsl['identifier'])) {
$objectStateUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
}
if (isset($step->dsl['names'])) {
foreach ($step->dsl['names'] as $name) {
$objectStateUpdateStruct->names[$name['languageCode']] = $name['name'];
}
}
if (isset($step->dsl['descriptions'])) {
foreach ($step->dsl['descriptions'] as $languageCode => $description) {
$objectStateUpdateStruct->descriptions[$languageCode] = $description;
}
}
$state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct);
$this->setReferences($state, $step);
}
return $stateCollection;
} | [
"protected",
"function",
"update",
"(",
"$",
"step",
")",
"{",
"$",
"stateCollection",
"=",
"$",
"this",
"->",
"matchObjectStates",
"(",
"'update'",
",",
"$",
"step",
")",
";",
"if",
"(",
"count",
"(",
"$",
"stateCollection",
")",
">",
"1",
"&&",
"array_key_exists",
"(",
"'references'",
",",
"$",
"step",
"->",
"dsl",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches\"",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"stateCollection",
")",
">",
"1",
"&&",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'identifier'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.\"",
")",
";",
"}",
"$",
"objectStateService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getObjectStateService",
"(",
")",
";",
"foreach",
"(",
"$",
"stateCollection",
"as",
"$",
"state",
")",
"{",
"$",
"objectStateUpdateStruct",
"=",
"$",
"objectStateService",
"->",
"newObjectStateUpdateStruct",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'identifier'",
"]",
")",
")",
"{",
"$",
"objectStateUpdateStruct",
"->",
"identifier",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'identifier'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'names'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'names'",
"]",
"as",
"$",
"name",
")",
"{",
"$",
"objectStateUpdateStruct",
"->",
"names",
"[",
"$",
"name",
"[",
"'languageCode'",
"]",
"]",
"=",
"$",
"name",
"[",
"'name'",
"]",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'descriptions'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'descriptions'",
"]",
"as",
"$",
"languageCode",
"=>",
"$",
"description",
")",
"{",
"$",
"objectStateUpdateStruct",
"->",
"descriptions",
"[",
"$",
"languageCode",
"]",
"=",
"$",
"description",
";",
"}",
"}",
"$",
"state",
"=",
"$",
"objectStateService",
"->",
"updateObjectState",
"(",
"$",
"state",
",",
"$",
"objectStateUpdateStruct",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"state",
",",
"$",
"step",
")",
";",
"}",
"return",
"$",
"stateCollection",
";",
"}"
] | Handles the update step of object state migrations.
@throws \Exception | [
"Handles",
"the",
"update",
"step",
"of",
"object",
"state",
"migrations",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/ObjectStateManager.php#L100-L136 |
kaliop-uk/ezmigrationbundle | Core/Executor/ObjectStateManager.php | ObjectStateManager.delete | protected function delete($step)
{
$stateCollection = $this->matchObjectStates('delete', $step);
$this->setReferences($stateCollection, $step);
$objectStateService = $this->repository->getObjectStateService();
foreach ($stateCollection as $state) {
$objectStateService->deleteObjectState($state);
}
return $stateCollection;
} | php | protected function delete($step)
{
$stateCollection = $this->matchObjectStates('delete', $step);
$this->setReferences($stateCollection, $step);
$objectStateService = $this->repository->getObjectStateService();
foreach ($stateCollection as $state) {
$objectStateService->deleteObjectState($state);
}
return $stateCollection;
} | [
"protected",
"function",
"delete",
"(",
"$",
"step",
")",
"{",
"$",
"stateCollection",
"=",
"$",
"this",
"->",
"matchObjectStates",
"(",
"'delete'",
",",
"$",
"step",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"stateCollection",
",",
"$",
"step",
")",
";",
"$",
"objectStateService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getObjectStateService",
"(",
")",
";",
"foreach",
"(",
"$",
"stateCollection",
"as",
"$",
"state",
")",
"{",
"$",
"objectStateService",
"->",
"deleteObjectState",
"(",
"$",
"state",
")",
";",
"}",
"return",
"$",
"stateCollection",
";",
"}"
] | Handles the deletion step of object state migrations. | [
"Handles",
"the",
"deletion",
"step",
"of",
"object",
"state",
"migrations",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/ObjectStateManager.php#L141-L154 |
kaliop-uk/ezmigrationbundle | Core/Executor/TrashManager.php | TrashManager.recover | protected function recover($step)
{
$itemsCollection = $this->matchItems('restore', $step);
if (count($itemsCollection) > 1 && array_key_exists('references', $step->dsl)) {
throw new \Exception("Can not execute Trash restore because multiple items match, and a references section is specified in the dsl. References can be set when only 1 item matches");
}
$locations = array();
$trashService = $this->repository->getTrashService();
foreach ($itemsCollection as $key => $item) {
$locations[] = $trashService->recover($item);
}
$this->setReferences(new LocationCollection($locations), $step);
return $itemsCollection;
} | php | protected function recover($step)
{
$itemsCollection = $this->matchItems('restore', $step);
if (count($itemsCollection) > 1 && array_key_exists('references', $step->dsl)) {
throw new \Exception("Can not execute Trash restore because multiple items match, and a references section is specified in the dsl. References can be set when only 1 item matches");
}
$locations = array();
$trashService = $this->repository->getTrashService();
foreach ($itemsCollection as $key => $item) {
$locations[] = $trashService->recover($item);
}
$this->setReferences(new LocationCollection($locations), $step);
return $itemsCollection;
} | [
"protected",
"function",
"recover",
"(",
"$",
"step",
")",
"{",
"$",
"itemsCollection",
"=",
"$",
"this",
"->",
"matchItems",
"(",
"'restore'",
",",
"$",
"step",
")",
";",
"if",
"(",
"count",
"(",
"$",
"itemsCollection",
")",
">",
"1",
"&&",
"array_key_exists",
"(",
"'references'",
",",
"$",
"step",
"->",
"dsl",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute Trash restore because multiple items match, and a references section is specified in the dsl. References can be set when only 1 item matches\"",
")",
";",
"}",
"$",
"locations",
"=",
"array",
"(",
")",
";",
"$",
"trashService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getTrashService",
"(",
")",
";",
"foreach",
"(",
"$",
"itemsCollection",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"locations",
"[",
"]",
"=",
"$",
"trashService",
"->",
"recover",
"(",
"$",
"item",
")",
";",
"}",
"$",
"this",
"->",
"setReferences",
"(",
"new",
"LocationCollection",
"(",
"$",
"locations",
")",
",",
"$",
"step",
")",
";",
"return",
"$",
"itemsCollection",
";",
"}"
] | Handles the trash-restore migration action
@todo support handling of restoration to custom locations | [
"Handles",
"the",
"trash",
"-",
"restore",
"migration",
"action"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/TrashManager.php#L49-L66 |
kaliop-uk/ezmigrationbundle | Core/Executor/TrashManager.php | TrashManager.delete | protected function delete($step)
{
$itemsCollection = $this->matchItems('delete', $step);
$this->setReferences($itemsCollection, $step);
$trashService = $this->repository->getTrashService();
foreach ($itemsCollection as $key => $item) {
$trashService->deleteTrashItem($item);
}
$this->setReferences($itemsCollection, $step);
return $itemsCollection;
} | php | protected function delete($step)
{
$itemsCollection = $this->matchItems('delete', $step);
$this->setReferences($itemsCollection, $step);
$trashService = $this->repository->getTrashService();
foreach ($itemsCollection as $key => $item) {
$trashService->deleteTrashItem($item);
}
$this->setReferences($itemsCollection, $step);
return $itemsCollection;
} | [
"protected",
"function",
"delete",
"(",
"$",
"step",
")",
"{",
"$",
"itemsCollection",
"=",
"$",
"this",
"->",
"matchItems",
"(",
"'delete'",
",",
"$",
"step",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"itemsCollection",
",",
"$",
"step",
")",
";",
"$",
"trashService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getTrashService",
"(",
")",
";",
"foreach",
"(",
"$",
"itemsCollection",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"trashService",
"->",
"deleteTrashItem",
"(",
"$",
"item",
")",
";",
"}",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"itemsCollection",
",",
"$",
"step",
")",
";",
"return",
"$",
"itemsCollection",
";",
"}"
] | Handles the trash-delete migration action | [
"Handles",
"the",
"trash",
"-",
"delete",
"migration",
"action"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/TrashManager.php#L71-L85 |
kaliop-uk/ezmigrationbundle | Core/Matcher/ReferenceMatcher.php | ReferenceMatcher.validateConditions | protected function validateConditions(array $conditions)
{
foreach ($conditions as $key => $val) {
if ($this->referenceResolver->isReference($key)) {
return true;
}
}
return parent::validateConditions($conditions);
} | php | protected function validateConditions(array $conditions)
{
foreach ($conditions as $key => $val) {
if ($this->referenceResolver->isReference($key)) {
return true;
}
}
return parent::validateConditions($conditions);
} | [
"protected",
"function",
"validateConditions",
"(",
"array",
"$",
"conditions",
")",
"{",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"referenceResolver",
"->",
"isReference",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"parent",
"::",
"validateConditions",
"(",
"$",
"conditions",
")",
";",
"}"
] | condition would be taken into account... | [
"condition",
"would",
"be",
"taken",
"into",
"account",
"..."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Matcher/ReferenceMatcher.php#L66-L75 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php | EmbeddedRegexpReferenceResolverTrait.resolveEmbeddedReferences | public function resolveEmbeddedReferences($string)
{
$regexp = $this->getEmbeddedRegexp();
$count = preg_match_all($regexp, $string, $matches);
// $matches[0][] will have the matched full string eg.: [reference:example_reference]
if ($count) {
foreach ($matches[0] as $referenceIdentifier) {
$reference = $this->getReferenceValue(substr($referenceIdentifier, 1, -1));
if (!is_array($reference)) {
$string = str_replace($referenceIdentifier, $reference, $string);
}
}
}
return $string;
} | php | public function resolveEmbeddedReferences($string)
{
$regexp = $this->getEmbeddedRegexp();
$count = preg_match_all($regexp, $string, $matches);
// $matches[0][] will have the matched full string eg.: [reference:example_reference]
if ($count) {
foreach ($matches[0] as $referenceIdentifier) {
$reference = $this->getReferenceValue(substr($referenceIdentifier, 1, -1));
if (!is_array($reference)) {
$string = str_replace($referenceIdentifier, $reference, $string);
}
}
}
return $string;
} | [
"public",
"function",
"resolveEmbeddedReferences",
"(",
"$",
"string",
")",
"{",
"$",
"regexp",
"=",
"$",
"this",
"->",
"getEmbeddedRegexp",
"(",
")",
";",
"$",
"count",
"=",
"preg_match_all",
"(",
"$",
"regexp",
",",
"$",
"string",
",",
"$",
"matches",
")",
";",
"// $matches[0][] will have the matched full string eg.: [reference:example_reference]",
"if",
"(",
"$",
"count",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"referenceIdentifier",
")",
"{",
"$",
"reference",
"=",
"$",
"this",
"->",
"getReferenceValue",
"(",
"substr",
"(",
"$",
"referenceIdentifier",
",",
"1",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"reference",
")",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"referenceIdentifier",
",",
"$",
"reference",
",",
"$",
"string",
")",
";",
"}",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Returns the $string with eventual refs resolved
@param string $string
@return string
@todo q: if reference is an array, should we recurse on it ? | [
"Returns",
"the",
"$string",
"with",
"eventual",
"refs",
"resolved"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php#L31-L46 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php | EmbeddedRegexpReferenceResolverTrait.getEmbeddedRegexp | protected function getEmbeddedRegexp()
{
// we need to alter the regexp we usr for std ref resolving, as it will be used to match parts of text, not the whole string
$regexp = substr($this->getRegexp(), 1, -1);
return '/' . preg_quote($this->beginToken). preg_replace(array('/^\^/'), array(''), $regexp) . '[^' . $this->endToken . ']+' . preg_quote($this->endToken) . '/';
} | php | protected function getEmbeddedRegexp()
{
// we need to alter the regexp we usr for std ref resolving, as it will be used to match parts of text, not the whole string
$regexp = substr($this->getRegexp(), 1, -1);
return '/' . preg_quote($this->beginToken). preg_replace(array('/^\^/'), array(''), $regexp) . '[^' . $this->endToken . ']+' . preg_quote($this->endToken) . '/';
} | [
"protected",
"function",
"getEmbeddedRegexp",
"(",
")",
"{",
"// we need to alter the regexp we usr for std ref resolving, as it will be used to match parts of text, not the whole string",
"$",
"regexp",
"=",
"substr",
"(",
"$",
"this",
"->",
"getRegexp",
"(",
")",
",",
"1",
",",
"-",
"1",
")",
";",
"return",
"'/'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"beginToken",
")",
".",
"preg_replace",
"(",
"array",
"(",
"'/^\\^/'",
")",
",",
"array",
"(",
"''",
")",
",",
"$",
"regexp",
")",
".",
"'[^'",
".",
"$",
"this",
"->",
"endToken",
".",
"']+'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"endToken",
")",
".",
"'/'",
";",
"}"
] | NB: here we assume that all regexp resolvers give us a regexp with a very specific format, notably using '/' as
delimiter......
@return string
@todo make the start and end tokens flexible (it probably wont work well if we use eg. '}}' as end token) | [
"NB",
":",
"here",
"we",
"assume",
"that",
"all",
"regexp",
"resolvers",
"give",
"us",
"a",
"regexp",
"with",
"a",
"very",
"specific",
"format",
"notably",
"using",
"/",
"as",
"delimiter",
"......"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php#L54-L59 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.create | protected function create($step)
{
$roleService = $this->repository->getRoleService();
$userService = $this->repository->getUserService();
$roleName = $this->referenceResolver->resolveReference($step->dsl['name']);
$roleCreateStruct = $roleService->newRoleCreateStruct($roleName);
// Publish new role
$role = $roleService->createRole($roleCreateStruct);
if (is_callable(array($roleService, 'publishRoleDraft'))) {
$roleService->publishRoleDraft($role);
}
if (isset($step->dsl['policies'])) {
foreach ($step->dsl['policies'] as $key => $ymlPolicy) {
$this->addPolicy($role, $roleService, $ymlPolicy);
}
}
if (isset($step->dsl['assign'])) {
$this->assignRole($role, $roleService, $userService, $step->dsl['assign']);
}
$this->setReferences($role, $step);
return $role;
} | php | protected function create($step)
{
$roleService = $this->repository->getRoleService();
$userService = $this->repository->getUserService();
$roleName = $this->referenceResolver->resolveReference($step->dsl['name']);
$roleCreateStruct = $roleService->newRoleCreateStruct($roleName);
// Publish new role
$role = $roleService->createRole($roleCreateStruct);
if (is_callable(array($roleService, 'publishRoleDraft'))) {
$roleService->publishRoleDraft($role);
}
if (isset($step->dsl['policies'])) {
foreach ($step->dsl['policies'] as $key => $ymlPolicy) {
$this->addPolicy($role, $roleService, $ymlPolicy);
}
}
if (isset($step->dsl['assign'])) {
$this->assignRole($role, $roleService, $userService, $step->dsl['assign']);
}
$this->setReferences($role, $step);
return $role;
} | [
"protected",
"function",
"create",
"(",
"$",
"step",
")",
"{",
"$",
"roleService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getRoleService",
"(",
")",
";",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"$",
"roleName",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'name'",
"]",
")",
";",
"$",
"roleCreateStruct",
"=",
"$",
"roleService",
"->",
"newRoleCreateStruct",
"(",
"$",
"roleName",
")",
";",
"// Publish new role",
"$",
"role",
"=",
"$",
"roleService",
"->",
"createRole",
"(",
"$",
"roleCreateStruct",
")",
";",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"roleService",
",",
"'publishRoleDraft'",
")",
")",
")",
"{",
"$",
"roleService",
"->",
"publishRoleDraft",
"(",
"$",
"role",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'policies'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'policies'",
"]",
"as",
"$",
"key",
"=>",
"$",
"ymlPolicy",
")",
"{",
"$",
"this",
"->",
"addPolicy",
"(",
"$",
"role",
",",
"$",
"roleService",
",",
"$",
"ymlPolicy",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'assign'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"assignRole",
"(",
"$",
"role",
",",
"$",
"roleService",
",",
"$",
"userService",
",",
"$",
"step",
"->",
"dsl",
"[",
"'assign'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"role",
",",
"$",
"step",
")",
";",
"return",
"$",
"role",
";",
"}"
] | Method to handle the create operation of the migration instructions | [
"Method",
"to",
"handle",
"the",
"create",
"operation",
"of",
"the",
"migration",
"instructions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L35-L62 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.update | protected function update($step)
{
$roleCollection = $this->matchRoles('update', $step);
if (count($roleCollection) > 1 && isset($step->dsl['references'])) {
throw new \Exception("Can not execute Role update because multiple roles match, and a references section is specified in the dsl. References can be set when only 1 role matches");
}
if (count($roleCollection) > 1 && isset($step->dsl['new_name'])) {
throw new \Exception("Can not execute Role update because multiple roles match, and a new_name is specified in the dsl.");
}
$roleService = $this->repository->getRoleService();
$userService = $this->repository->getUserService();
/** @var \eZ\Publish\API\Repository\Values\User\Role $role */
foreach ($roleCollection as $key => $role) {
// Updating role name
if (isset($step->dsl['new_name'])) {
$update = $roleService->newRoleUpdateStruct();
$newRoleName = $this->referenceResolver->resolveReference($step->dsl['new_name']);
$update->identifier = $this->referenceResolver->resolveReference($newRoleName);
$role = $roleService->updateRole($role, $update);
}
if (isset($step->dsl['policies'])) {
$ymlPolicies = $step->dsl['policies'];
// Removing all policies so we can add them back.
// TODO: Check and update policies instead of remove and add.
$policies = $role->getPolicies();
foreach ($policies as $policy) {
$roleService->deletePolicy($policy);
}
foreach ($ymlPolicies as $ymlPolicy) {
$this->addPolicy($role, $roleService, $ymlPolicy);
}
}
if (isset($step->dsl['assign'])) {
$this->assignRole($role, $roleService, $userService, $step->dsl['assign']);
}
$roleCollection[$key] = $role;
}
$this->setReferences($roleCollection, $step);
return $roleCollection;
} | php | protected function update($step)
{
$roleCollection = $this->matchRoles('update', $step);
if (count($roleCollection) > 1 && isset($step->dsl['references'])) {
throw new \Exception("Can not execute Role update because multiple roles match, and a references section is specified in the dsl. References can be set when only 1 role matches");
}
if (count($roleCollection) > 1 && isset($step->dsl['new_name'])) {
throw new \Exception("Can not execute Role update because multiple roles match, and a new_name is specified in the dsl.");
}
$roleService = $this->repository->getRoleService();
$userService = $this->repository->getUserService();
/** @var \eZ\Publish\API\Repository\Values\User\Role $role */
foreach ($roleCollection as $key => $role) {
// Updating role name
if (isset($step->dsl['new_name'])) {
$update = $roleService->newRoleUpdateStruct();
$newRoleName = $this->referenceResolver->resolveReference($step->dsl['new_name']);
$update->identifier = $this->referenceResolver->resolveReference($newRoleName);
$role = $roleService->updateRole($role, $update);
}
if (isset($step->dsl['policies'])) {
$ymlPolicies = $step->dsl['policies'];
// Removing all policies so we can add them back.
// TODO: Check and update policies instead of remove and add.
$policies = $role->getPolicies();
foreach ($policies as $policy) {
$roleService->deletePolicy($policy);
}
foreach ($ymlPolicies as $ymlPolicy) {
$this->addPolicy($role, $roleService, $ymlPolicy);
}
}
if (isset($step->dsl['assign'])) {
$this->assignRole($role, $roleService, $userService, $step->dsl['assign']);
}
$roleCollection[$key] = $role;
}
$this->setReferences($roleCollection, $step);
return $roleCollection;
} | [
"protected",
"function",
"update",
"(",
"$",
"step",
")",
"{",
"$",
"roleCollection",
"=",
"$",
"this",
"->",
"matchRoles",
"(",
"'update'",
",",
"$",
"step",
")",
";",
"if",
"(",
"count",
"(",
"$",
"roleCollection",
")",
">",
"1",
"&&",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'references'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute Role update because multiple roles match, and a references section is specified in the dsl. References can be set when only 1 role matches\"",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"roleCollection",
")",
">",
"1",
"&&",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'new_name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute Role update because multiple roles match, and a new_name is specified in the dsl.\"",
")",
";",
"}",
"$",
"roleService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getRoleService",
"(",
")",
";",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"/** @var \\eZ\\Publish\\API\\Repository\\Values\\User\\Role $role */",
"foreach",
"(",
"$",
"roleCollection",
"as",
"$",
"key",
"=>",
"$",
"role",
")",
"{",
"// Updating role name",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'new_name'",
"]",
")",
")",
"{",
"$",
"update",
"=",
"$",
"roleService",
"->",
"newRoleUpdateStruct",
"(",
")",
";",
"$",
"newRoleName",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'new_name'",
"]",
")",
";",
"$",
"update",
"->",
"identifier",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"newRoleName",
")",
";",
"$",
"role",
"=",
"$",
"roleService",
"->",
"updateRole",
"(",
"$",
"role",
",",
"$",
"update",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'policies'",
"]",
")",
")",
"{",
"$",
"ymlPolicies",
"=",
"$",
"step",
"->",
"dsl",
"[",
"'policies'",
"]",
";",
"// Removing all policies so we can add them back.",
"// TODO: Check and update policies instead of remove and add.",
"$",
"policies",
"=",
"$",
"role",
"->",
"getPolicies",
"(",
")",
";",
"foreach",
"(",
"$",
"policies",
"as",
"$",
"policy",
")",
"{",
"$",
"roleService",
"->",
"deletePolicy",
"(",
"$",
"policy",
")",
";",
"}",
"foreach",
"(",
"$",
"ymlPolicies",
"as",
"$",
"ymlPolicy",
")",
"{",
"$",
"this",
"->",
"addPolicy",
"(",
"$",
"role",
",",
"$",
"roleService",
",",
"$",
"ymlPolicy",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'assign'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"assignRole",
"(",
"$",
"role",
",",
"$",
"roleService",
",",
"$",
"userService",
",",
"$",
"step",
"->",
"dsl",
"[",
"'assign'",
"]",
")",
";",
"}",
"$",
"roleCollection",
"[",
"$",
"key",
"]",
"=",
"$",
"role",
";",
"}",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"roleCollection",
",",
"$",
"step",
")",
";",
"return",
"$",
"roleCollection",
";",
"}"
] | Method to handle the update operation of the migration instructions | [
"Method",
"to",
"handle",
"the",
"update",
"operation",
"of",
"the",
"migration",
"instructions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L76-L127 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.delete | protected function delete($step)
{
$roleCollection = $this->matchRoles('delete', $step);
$this->setReferences($roleCollection, $step);
$roleService = $this->repository->getRoleService();
foreach ($roleCollection as $role) {
$roleService->deleteRole($role);
}
return $roleCollection;
} | php | protected function delete($step)
{
$roleCollection = $this->matchRoles('delete', $step);
$this->setReferences($roleCollection, $step);
$roleService = $this->repository->getRoleService();
foreach ($roleCollection as $role) {
$roleService->deleteRole($role);
}
return $roleCollection;
} | [
"protected",
"function",
"delete",
"(",
"$",
"step",
")",
"{",
"$",
"roleCollection",
"=",
"$",
"this",
"->",
"matchRoles",
"(",
"'delete'",
",",
"$",
"step",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"roleCollection",
",",
"$",
"step",
")",
";",
"$",
"roleService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getRoleService",
"(",
")",
";",
"foreach",
"(",
"$",
"roleCollection",
"as",
"$",
"role",
")",
"{",
"$",
"roleService",
"->",
"deleteRole",
"(",
"$",
"role",
")",
";",
"}",
"return",
"$",
"roleCollection",
";",
"}"
] | Method to handle the delete operation of the migration instructions | [
"Method",
"to",
"handle",
"the",
"delete",
"operation",
"of",
"the",
"migration",
"instructions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L132-L145 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.createLimitation | protected function createLimitation(RoleService $roleService, array $limitation)
{
$limitationType = $roleService->getLimitationType($limitation['identifier']);
$limitationValue = is_array($limitation['values']) ? $limitation['values'] : array($limitation['values']);
foreach ($limitationValue as $id => $value) {
$limitationValue[$id] = $this->referenceResolver->resolveReference($value);
}
$limitationValue = $this->limitationConverter->resolveLimitationValue($limitation['identifier'], $limitationValue);
return $limitationType->buildValue($limitationValue);
} | php | protected function createLimitation(RoleService $roleService, array $limitation)
{
$limitationType = $roleService->getLimitationType($limitation['identifier']);
$limitationValue = is_array($limitation['values']) ? $limitation['values'] : array($limitation['values']);
foreach ($limitationValue as $id => $value) {
$limitationValue[$id] = $this->referenceResolver->resolveReference($value);
}
$limitationValue = $this->limitationConverter->resolveLimitationValue($limitation['identifier'], $limitationValue);
return $limitationType->buildValue($limitationValue);
} | [
"protected",
"function",
"createLimitation",
"(",
"RoleService",
"$",
"roleService",
",",
"array",
"$",
"limitation",
")",
"{",
"$",
"limitationType",
"=",
"$",
"roleService",
"->",
"getLimitationType",
"(",
"$",
"limitation",
"[",
"'identifier'",
"]",
")",
";",
"$",
"limitationValue",
"=",
"is_array",
"(",
"$",
"limitation",
"[",
"'values'",
"]",
")",
"?",
"$",
"limitation",
"[",
"'values'",
"]",
":",
"array",
"(",
"$",
"limitation",
"[",
"'values'",
"]",
")",
";",
"foreach",
"(",
"$",
"limitationValue",
"as",
"$",
"id",
"=>",
"$",
"value",
")",
"{",
"$",
"limitationValue",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"value",
")",
";",
"}",
"$",
"limitationValue",
"=",
"$",
"this",
"->",
"limitationConverter",
"->",
"resolveLimitationValue",
"(",
"$",
"limitation",
"[",
"'identifier'",
"]",
",",
"$",
"limitationValue",
")",
";",
"return",
"$",
"limitationType",
"->",
"buildValue",
"(",
"$",
"limitationValue",
")",
";",
"}"
] | Create a new Limitation object based on the type and value in the $limitation array.
<pre>
$limitation = array(
'identifier' => Type of the limitation
'values' => array(Values to base the limitation on)
)
</pre>
@param \eZ\Publish\API\Repository\RoleService $roleService
@param array $limitation
@return Limitation | [
"Create",
"a",
"new",
"Limitation",
"object",
"based",
"on",
"the",
"type",
"and",
"value",
"in",
"the",
"$limitation",
"array",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L301-L312 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.assignRole | protected function assignRole(Role $role, RoleService $roleService, UserService $userService, array $assignments)
{
foreach ($assignments as $assign) {
switch ($assign['type']) {
case 'user':
foreach ($assign['ids'] as $userId) {
$userId = $this->referenceResolver->resolveReference($userId);
$user = $userService->loadUser($userId);
if (!isset($assign['limitations'])) {
$roleService->assignRoleToUser($role, $user);
} else {
foreach ($assign['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
$roleService->assignRoleToUser($role, $user, $limitationObject);
}
}
}
break;
case 'group':
foreach ($assign['ids'] as $groupId) {
$groupId = $this->referenceResolver->resolveReference($groupId);
$group = $userService->loadUserGroup($groupId);
if (!isset($assign['limitations'])) {
// q: why are we swallowing exceptions here ?
//try {
$roleService->assignRoleToUserGroup($role, $group);
//} catch (InvalidArgumentException $e) {}
} else {
foreach ($assign['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
// q: why are we swallowing exceptions here ?
//try {
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
//} catch (InvalidArgumentException $e) {}
}
}
}
break;
}
}
} | php | protected function assignRole(Role $role, RoleService $roleService, UserService $userService, array $assignments)
{
foreach ($assignments as $assign) {
switch ($assign['type']) {
case 'user':
foreach ($assign['ids'] as $userId) {
$userId = $this->referenceResolver->resolveReference($userId);
$user = $userService->loadUser($userId);
if (!isset($assign['limitations'])) {
$roleService->assignRoleToUser($role, $user);
} else {
foreach ($assign['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
$roleService->assignRoleToUser($role, $user, $limitationObject);
}
}
}
break;
case 'group':
foreach ($assign['ids'] as $groupId) {
$groupId = $this->referenceResolver->resolveReference($groupId);
$group = $userService->loadUserGroup($groupId);
if (!isset($assign['limitations'])) {
// q: why are we swallowing exceptions here ?
//try {
$roleService->assignRoleToUserGroup($role, $group);
//} catch (InvalidArgumentException $e) {}
} else {
foreach ($assign['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
// q: why are we swallowing exceptions here ?
//try {
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
//} catch (InvalidArgumentException $e) {}
}
}
}
break;
}
}
} | [
"protected",
"function",
"assignRole",
"(",
"Role",
"$",
"role",
",",
"RoleService",
"$",
"roleService",
",",
"UserService",
"$",
"userService",
",",
"array",
"$",
"assignments",
")",
"{",
"foreach",
"(",
"$",
"assignments",
"as",
"$",
"assign",
")",
"{",
"switch",
"(",
"$",
"assign",
"[",
"'type'",
"]",
")",
"{",
"case",
"'user'",
":",
"foreach",
"(",
"$",
"assign",
"[",
"'ids'",
"]",
"as",
"$",
"userId",
")",
"{",
"$",
"userId",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"userId",
")",
";",
"$",
"user",
"=",
"$",
"userService",
"->",
"loadUser",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"assign",
"[",
"'limitations'",
"]",
")",
")",
"{",
"$",
"roleService",
"->",
"assignRoleToUser",
"(",
"$",
"role",
",",
"$",
"user",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"assign",
"[",
"'limitations'",
"]",
"as",
"$",
"limitation",
")",
"{",
"$",
"limitationObject",
"=",
"$",
"this",
"->",
"createLimitation",
"(",
"$",
"roleService",
",",
"$",
"limitation",
")",
";",
"$",
"roleService",
"->",
"assignRoleToUser",
"(",
"$",
"role",
",",
"$",
"user",
",",
"$",
"limitationObject",
")",
";",
"}",
"}",
"}",
"break",
";",
"case",
"'group'",
":",
"foreach",
"(",
"$",
"assign",
"[",
"'ids'",
"]",
"as",
"$",
"groupId",
")",
"{",
"$",
"groupId",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"groupId",
")",
";",
"$",
"group",
"=",
"$",
"userService",
"->",
"loadUserGroup",
"(",
"$",
"groupId",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"assign",
"[",
"'limitations'",
"]",
")",
")",
"{",
"// q: why are we swallowing exceptions here ?",
"//try {",
"$",
"roleService",
"->",
"assignRoleToUserGroup",
"(",
"$",
"role",
",",
"$",
"group",
")",
";",
"//} catch (InvalidArgumentException $e) {}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"assign",
"[",
"'limitations'",
"]",
"as",
"$",
"limitation",
")",
"{",
"$",
"limitationObject",
"=",
"$",
"this",
"->",
"createLimitation",
"(",
"$",
"roleService",
",",
"$",
"limitation",
")",
";",
"// q: why are we swallowing exceptions here ?",
"//try {",
"$",
"roleService",
"->",
"assignRoleToUserGroup",
"(",
"$",
"role",
",",
"$",
"group",
",",
"$",
"limitationObject",
")",
";",
"//} catch (InvalidArgumentException $e) {}",
"}",
"}",
"}",
"break",
";",
"}",
"}",
"}"
] | Assign a role to users and groups in the assignment array.
<pre>
$assignments = array(
array(
'type' => 'user',
'ids' => array(user ids),
'limitation' => array(limitations)
)
)
</pre>
@param \eZ\Publish\API\Repository\Values\User\Role $role
@param \eZ\Publish\API\Repository\RoleService $roleService
@param \eZ\Publish\API\Repository\UserService $userService
@param array $assignments | [
"Assign",
"a",
"role",
"to",
"users",
"and",
"groups",
"in",
"the",
"assignment",
"array",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L332-L376 |
kaliop-uk/ezmigrationbundle | Core/Executor/RoleManager.php | RoleManager.addPolicy | protected function addPolicy(Role $role, RoleService $roleService, array $policy)
{
$policyCreateStruct = $roleService->newPolicyCreateStruct($policy['module'], $policy['function']);
if (array_key_exists('limitations', $policy)) {
foreach ($policy['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
$policyCreateStruct->addLimitation($limitationObject);
}
}
$roleService->addPolicy($role, $policyCreateStruct);
} | php | protected function addPolicy(Role $role, RoleService $roleService, array $policy)
{
$policyCreateStruct = $roleService->newPolicyCreateStruct($policy['module'], $policy['function']);
if (array_key_exists('limitations', $policy)) {
foreach ($policy['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
$policyCreateStruct->addLimitation($limitationObject);
}
}
$roleService->addPolicy($role, $policyCreateStruct);
} | [
"protected",
"function",
"addPolicy",
"(",
"Role",
"$",
"role",
",",
"RoleService",
"$",
"roleService",
",",
"array",
"$",
"policy",
")",
"{",
"$",
"policyCreateStruct",
"=",
"$",
"roleService",
"->",
"newPolicyCreateStruct",
"(",
"$",
"policy",
"[",
"'module'",
"]",
",",
"$",
"policy",
"[",
"'function'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'limitations'",
",",
"$",
"policy",
")",
")",
"{",
"foreach",
"(",
"$",
"policy",
"[",
"'limitations'",
"]",
"as",
"$",
"limitation",
")",
"{",
"$",
"limitationObject",
"=",
"$",
"this",
"->",
"createLimitation",
"(",
"$",
"roleService",
",",
"$",
"limitation",
")",
";",
"$",
"policyCreateStruct",
"->",
"addLimitation",
"(",
"$",
"limitationObject",
")",
";",
"}",
"}",
"$",
"roleService",
"->",
"addPolicy",
"(",
"$",
"role",
",",
"$",
"policyCreateStruct",
")",
";",
"}"
] | Add new policies to the $role Role.
@param \eZ\Publish\API\Repository\Values\User\Role $role
@param \eZ\Publish\API\Repository\RoleService $roleService
@param array $policy | [
"Add",
"new",
"policies",
"to",
"the",
"$role",
"Role",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/RoleManager.php#L385-L397 |
kaliop-uk/ezmigrationbundle | Command/AbstractCommand.php | AbstractCommand.writeln | protected function writeln($message, $verbosity = OutputInterface::VERBOSITY_NORMAL, $type = OutputInterface::OUTPUT_NORMAL)
{
if ($this->verbosity >= $verbosity) {
$this->output->writeln($message, $type);
}
} | php | protected function writeln($message, $verbosity = OutputInterface::VERBOSITY_NORMAL, $type = OutputInterface::OUTPUT_NORMAL)
{
if ($this->verbosity >= $verbosity) {
$this->output->writeln($message, $type);
}
} | [
"protected",
"function",
"writeln",
"(",
"$",
"message",
",",
"$",
"verbosity",
"=",
"OutputInterface",
"::",
"VERBOSITY_NORMAL",
",",
"$",
"type",
"=",
"OutputInterface",
"::",
"OUTPUT_NORMAL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"verbosity",
">=",
"$",
"verbosity",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"message",
",",
"$",
"type",
")",
";",
"}",
"}"
] | Small trick to allow us to:
- lower verbosity between NORMAL and QUIET
- have a decent writeln API, even with old SF versions
@param string|array $message The message as an array of lines or a single string
@param int $verbosity
@param int $type | [
"Small",
"trick",
"to",
"allow",
"us",
"to",
":",
"-",
"lower",
"verbosity",
"between",
"NORMAL",
"and",
"QUIET",
"-",
"have",
"a",
"decent",
"writeln",
"API",
"even",
"with",
"old",
"SF",
"versions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Command/AbstractCommand.php#L57-L62 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzImage.php | EzImage.hashToFieldValue | public function hashToFieldValue($fieldValue, array $context = array())
{
$altText = '';
$fileName = '';
if ($fieldValue === null) {
return new ImageValue();
} else if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
$filePath = $fieldValue['path'];
if (isset($fieldValue['alt_text'])) {
$altText = $fieldValue['alt_text'];
}
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
}
// default format: path is relative to the 'images' dir
$realFilePath = dirname($context['path']) . '/images/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new ImageValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'alternativeText' => $altText
)
);
} | php | public function hashToFieldValue($fieldValue, array $context = array())
{
$altText = '';
$fileName = '';
if ($fieldValue === null) {
return new ImageValue();
} else if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
$filePath = $fieldValue['path'];
if (isset($fieldValue['alt_text'])) {
$altText = $fieldValue['alt_text'];
}
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
}
// default format: path is relative to the 'images' dir
$realFilePath = dirname($context['path']) . '/images/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new ImageValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'alternativeText' => $altText
)
);
} | [
"public",
"function",
"hashToFieldValue",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"altText",
"=",
"''",
";",
"$",
"fileName",
"=",
"''",
";",
"if",
"(",
"$",
"fieldValue",
"===",
"null",
")",
"{",
"return",
"new",
"ImageValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"fieldValue",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
";",
"}",
"else",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
"[",
"'path'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'alt_text'",
"]",
")",
")",
"{",
"$",
"altText",
"=",
"$",
"fieldValue",
"[",
"'alt_text'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'filename'",
"]",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"fieldValue",
"[",
"'filename'",
"]",
";",
"}",
"}",
"// default format: path is relative to the 'images' dir",
"$",
"realFilePath",
"=",
"dirname",
"(",
"$",
"context",
"[",
"'path'",
"]",
")",
".",
"'/images/'",
".",
"$",
"filePath",
";",
"// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well",
"if",
"(",
"!",
"is_file",
"(",
"$",
"realFilePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"realFilePath",
"=",
"$",
"filePath",
";",
"}",
"return",
"new",
"ImageValue",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"realFilePath",
",",
"'fileSize'",
"=>",
"filesize",
"(",
"$",
"realFilePath",
")",
",",
"'fileName'",
"=>",
"$",
"fileName",
"!=",
"''",
"?",
"$",
"fileName",
":",
"basename",
"(",
"$",
"realFilePath",
")",
",",
"'alternativeText'",
"=>",
"$",
"altText",
")",
")",
";",
"}"
] | Creates a value object to use as the field value when setting an image field type.
@param array|string $fieldValue The path to the file or an array with 'path' and 'alt_text' keys
@param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
@return ImageValue
@todo resolve refs more | [
"Creates",
"a",
"value",
"object",
"to",
"use",
"as",
"the",
"field",
"value",
"when",
"setting",
"an",
"image",
"field",
"type",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzImage.php#L19-L54 |
kaliop-uk/ezmigrationbundle | Core/Matcher/LocationMatcher.php | LocationMatcher.getConditionsFromKey | protected function getConditionsFromKey($key)
{
if (is_int($key) || ctype_digit($key)) {
return array(self::MATCH_LOCATION_ID => $key);
}
return array(self::MATCH_LOCATION_REMOTE_ID => $key);
} | php | protected function getConditionsFromKey($key)
{
if (is_int($key) || ctype_digit($key)) {
return array(self::MATCH_LOCATION_ID => $key);
}
return array(self::MATCH_LOCATION_REMOTE_ID => $key);
} | [
"protected",
"function",
"getConditionsFromKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
"||",
"ctype_digit",
"(",
"$",
"key",
")",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"MATCH_LOCATION_ID",
"=>",
"$",
"key",
")",
";",
"}",
"return",
"array",
"(",
"self",
"::",
"MATCH_LOCATION_REMOTE_ID",
"=>",
"$",
"key",
")",
";",
"}"
] | When matching by key, we accept location Id and remote Id only
@param int|string $key
@return array | [
"When",
"matching",
"by",
"key",
"we",
"accept",
"location",
"Id",
"and",
"remote",
"Id",
"only"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Matcher/LocationMatcher.php#L108-L114 |
kaliop-uk/ezmigrationbundle | Core/Matcher/LocationMatcher.php | LocationMatcher.findLocationsByContentIds | protected function findLocationsByContentIds(array $contentIds)
{
$locations = [];
foreach ($contentIds as $contentId) {
$content = $this->repository->getContentService()->loadContent($contentId);
foreach($this->repository->getLocationService()->loadLocations($content->contentInfo) as $location) {
$locations[$location->id] = $location;
}
}
return $locations;
} | php | protected function findLocationsByContentIds(array $contentIds)
{
$locations = [];
foreach ($contentIds as $contentId) {
$content = $this->repository->getContentService()->loadContent($contentId);
foreach($this->repository->getLocationService()->loadLocations($content->contentInfo) as $location) {
$locations[$location->id] = $location;
}
}
return $locations;
} | [
"protected",
"function",
"findLocationsByContentIds",
"(",
"array",
"$",
"contentIds",
")",
"{",
"$",
"locations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contentIds",
"as",
"$",
"contentId",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"repository",
"->",
"getContentService",
"(",
")",
"->",
"loadContent",
"(",
"$",
"contentId",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"->",
"getLocationService",
"(",
")",
"->",
"loadLocations",
"(",
"$",
"content",
"->",
"contentInfo",
")",
"as",
"$",
"location",
")",
"{",
"$",
"locations",
"[",
"$",
"location",
"->",
"id",
"]",
"=",
"$",
"location",
";",
"}",
"}",
"return",
"$",
"locations",
";",
"}"
] | Returns all locations of a set of objects
@param int[] $contentIds
@return Location[]
@deprecated | [
"Returns",
"all",
"locations",
"of",
"a",
"set",
"of",
"objects"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Matcher/LocationMatcher.php#L160-L172 |
kaliop-uk/ezmigrationbundle | Core/Matcher/LocationMatcher.php | LocationMatcher.findLocationsByContentRemoteIds | protected function findLocationsByContentRemoteIds(array $remoteContentIds)
{
$locations = [];
foreach ($remoteContentIds as $remoteContentId) {
$content = $this->repository->getContentService()->loadContentByRemoteId($remoteContentId);
foreach($this->repository->getLocationService()->loadLocations($content->contentInfo) as $location) {
$locations[$location->id] = $location;
}
}
return $locations;
} | php | protected function findLocationsByContentRemoteIds(array $remoteContentIds)
{
$locations = [];
foreach ($remoteContentIds as $remoteContentId) {
$content = $this->repository->getContentService()->loadContentByRemoteId($remoteContentId);
foreach($this->repository->getLocationService()->loadLocations($content->contentInfo) as $location) {
$locations[$location->id] = $location;
}
}
return $locations;
} | [
"protected",
"function",
"findLocationsByContentRemoteIds",
"(",
"array",
"$",
"remoteContentIds",
")",
"{",
"$",
"locations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"remoteContentIds",
"as",
"$",
"remoteContentId",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"repository",
"->",
"getContentService",
"(",
")",
"->",
"loadContentByRemoteId",
"(",
"$",
"remoteContentId",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"->",
"getLocationService",
"(",
")",
"->",
"loadLocations",
"(",
"$",
"content",
"->",
"contentInfo",
")",
"as",
"$",
"location",
")",
"{",
"$",
"locations",
"[",
"$",
"location",
"->",
"id",
"]",
"=",
"$",
"location",
";",
"}",
"}",
"return",
"$",
"locations",
";",
"}"
] | Returns all locations of a set of objects
@param int[] $remoteContentIds
@return Location[]
@deprecated | [
"Returns",
"all",
"locations",
"of",
"a",
"set",
"of",
"objects"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Matcher/LocationMatcher.php#L181-L193 |
kaliop-uk/ezmigrationbundle | Core/DefinitionParser/PHPDefinitionParser.php | PHPDefinitionParser.parseMigrationDefinition | public function parseMigrationDefinition(MigrationDefinition $definition)
{
$status = MigrationDefinition::STATUS_PARSED;
/// validate that php file is ok, contains a class with good interface
$className = $this->getClassNameFromFile($definition->path);
if ($className == '') {
$status = MigrationDefinition::STATUS_INVALID;
$message = 'The migration definition file should contain a valid class name. The class name is the part of the filename after the 1st underscore';
} else {
// we use smart parsing instead before plain file inclusion, by usage of nikic/php-parser
// this should help with broken php migrations
$pf = new ParserFactory();
$parser = $pf->create(ParserFactory::PREFER_PHP7);
try {
$parser->parse(file_get_contents($definition->path));
include_once($definition->path);
if (!class_exists($className)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition file should contain a valid class '$className'";
} else {
$interfaces = class_implements($className);
if (!in_array($this->mandatoryInterface, $interfaces)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition class '$className' should implement the interface '{$this->mandatoryInterface}'";
}
}
} catch (Error $e) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition file '{$definition->path}' is not valid php'";
}
}
if ($status != MigrationDefinition::STATUS_PARSED)
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
$status,
array(),
$message
);
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
array(
new MigrationStep('php', array('class' => $className), array('path' => $definition->path))
)
);
} | php | public function parseMigrationDefinition(MigrationDefinition $definition)
{
$status = MigrationDefinition::STATUS_PARSED;
/// validate that php file is ok, contains a class with good interface
$className = $this->getClassNameFromFile($definition->path);
if ($className == '') {
$status = MigrationDefinition::STATUS_INVALID;
$message = 'The migration definition file should contain a valid class name. The class name is the part of the filename after the 1st underscore';
} else {
// we use smart parsing instead before plain file inclusion, by usage of nikic/php-parser
// this should help with broken php migrations
$pf = new ParserFactory();
$parser = $pf->create(ParserFactory::PREFER_PHP7);
try {
$parser->parse(file_get_contents($definition->path));
include_once($definition->path);
if (!class_exists($className)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition file should contain a valid class '$className'";
} else {
$interfaces = class_implements($className);
if (!in_array($this->mandatoryInterface, $interfaces)) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition class '$className' should implement the interface '{$this->mandatoryInterface}'";
}
}
} catch (Error $e) {
$status = MigrationDefinition::STATUS_INVALID;
$message = "The migration definition file '{$definition->path}' is not valid php'";
}
}
if ($status != MigrationDefinition::STATUS_PARSED)
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
$status,
array(),
$message
);
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
array(
new MigrationStep('php', array('class' => $className), array('path' => $definition->path))
)
);
} | [
"public",
"function",
"parseMigrationDefinition",
"(",
"MigrationDefinition",
"$",
"definition",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_PARSED",
";",
"/// validate that php file is ok, contains a class with good interface",
"$",
"className",
"=",
"$",
"this",
"->",
"getClassNameFromFile",
"(",
"$",
"definition",
"->",
"path",
")",
";",
"if",
"(",
"$",
"className",
"==",
"''",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"'The migration definition file should contain a valid class name. The class name is the part of the filename after the 1st underscore'",
";",
"}",
"else",
"{",
"// we use smart parsing instead before plain file inclusion, by usage of nikic/php-parser",
"// this should help with broken php migrations",
"$",
"pf",
"=",
"new",
"ParserFactory",
"(",
")",
";",
"$",
"parser",
"=",
"$",
"pf",
"->",
"create",
"(",
"ParserFactory",
"::",
"PREFER_PHP7",
")",
";",
"try",
"{",
"$",
"parser",
"->",
"parse",
"(",
"file_get_contents",
"(",
"$",
"definition",
"->",
"path",
")",
")",
";",
"include_once",
"(",
"$",
"definition",
"->",
"path",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"\"The migration definition file should contain a valid class '$className'\"",
";",
"}",
"else",
"{",
"$",
"interfaces",
"=",
"class_implements",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"mandatoryInterface",
",",
"$",
"interfaces",
")",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"\"The migration definition class '$className' should implement the interface '{$this->mandatoryInterface}'\"",
";",
"}",
"}",
"}",
"catch",
"(",
"Error",
"$",
"e",
")",
"{",
"$",
"status",
"=",
"MigrationDefinition",
"::",
"STATUS_INVALID",
";",
"$",
"message",
"=",
"\"The migration definition file '{$definition->path}' is not valid php'\"",
";",
"}",
"}",
"if",
"(",
"$",
"status",
"!=",
"MigrationDefinition",
"::",
"STATUS_PARSED",
")",
"{",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"$",
"status",
",",
"array",
"(",
")",
",",
"$",
"message",
")",
";",
"}",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_PARSED",
",",
"array",
"(",
"new",
"MigrationStep",
"(",
"'php'",
",",
"array",
"(",
"'class'",
"=>",
"$",
"className",
")",
",",
"array",
"(",
"'path'",
"=>",
"$",
"definition",
"->",
"path",
")",
")",
")",
")",
";",
"}"
] | Parses a migration definition file, and returns the list of actions to take
@param MigrationDefinition $definition
@return MigrationDefinition | [
"Parses",
"a",
"migration",
"definition",
"file",
"and",
"returns",
"the",
"list",
"of",
"actions",
"to",
"take"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/DefinitionParser/PHPDefinitionParser.php#L32-L91 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/PrefixBasedResolver.php | PrefixBasedResolver.getReferenceIdentifierByPrefix | protected function getReferenceIdentifierByPrefix($stringIdentifier)
{
foreach ($this->referencePrefixes as $prefix) {
$regexp = '/^' . preg_quote($prefix, '/') . '/';
if (preg_match($regexp, $stringIdentifier)) {
return array('prefix' => $prefix, 'identifier' => preg_replace($regexp, '', $stringIdentifier));
}
}
throw new \Exception("Can not match reference with identifier '$stringIdentifier'");
} | php | protected function getReferenceIdentifierByPrefix($stringIdentifier)
{
foreach ($this->referencePrefixes as $prefix) {
$regexp = '/^' . preg_quote($prefix, '/') . '/';
if (preg_match($regexp, $stringIdentifier)) {
return array('prefix' => $prefix, 'identifier' => preg_replace($regexp, '', $stringIdentifier));
}
}
throw new \Exception("Can not match reference with identifier '$stringIdentifier'");
} | [
"protected",
"function",
"getReferenceIdentifierByPrefix",
"(",
"$",
"stringIdentifier",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"referencePrefixes",
"as",
"$",
"prefix",
")",
"{",
"$",
"regexp",
"=",
"'/^'",
".",
"preg_quote",
"(",
"$",
"prefix",
",",
"'/'",
")",
".",
"'/'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"stringIdentifier",
")",
")",
"{",
"return",
"array",
"(",
"'prefix'",
"=>",
"$",
"prefix",
",",
"'identifier'",
"=>",
"preg_replace",
"(",
"$",
"regexp",
",",
"''",
",",
"$",
"stringIdentifier",
")",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not match reference with identifier '$stringIdentifier'\"",
")",
";",
"}"
] | Useful for subclasses with many $referencePrefixes
@param string $stringIdentifier
@return array with 2 keys, 'prefix' and 'identifier'
@throws \Exception | [
"Useful",
"for",
"subclasses",
"with",
"many",
"$referencePrefixes"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/PrefixBasedResolver.php#L78-L87 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/CustomReferenceResolver.php | CustomReferenceResolver.getReferenceValue | public function getReferenceValue($identifier)
{
$identifier = $this->getReferenceIdentifier($identifier);
if (!array_key_exists($identifier, $this->references)) {
throw new \Exception("No reference set with identifier '$identifier'");
}
return $this->references[$identifier];
} | php | public function getReferenceValue($identifier)
{
$identifier = $this->getReferenceIdentifier($identifier);
if (!array_key_exists($identifier, $this->references)) {
throw new \Exception("No reference set with identifier '$identifier'");
}
return $this->references[$identifier];
} | [
"public",
"function",
"getReferenceValue",
"(",
"$",
"identifier",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getReferenceIdentifier",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"identifier",
",",
"$",
"this",
"->",
"references",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No reference set with identifier '$identifier'\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"references",
"[",
"$",
"identifier",
"]",
";",
"}"
] | Get a stored reference
@param string $identifier format: reference:<some_custom_identifier>
@return mixed
@throws \Exception When trying to retrieve an unset reference | [
"Get",
"a",
"stored",
"reference"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/CustomReferenceResolver.php#L34-L42 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/CustomReferenceResolver.php | CustomReferenceResolver.addReference | public function addReference($identifier, $value, $overwrite = false)
{
if (array_key_exists($identifier, $this->references) && !$overwrite) {
throw new \Exception("A reference with identifier '$identifier' already exists");
}
$this->references[$identifier] = $value;
return true;
} | php | public function addReference($identifier, $value, $overwrite = false)
{
if (array_key_exists($identifier, $this->references) && !$overwrite) {
throw new \Exception("A reference with identifier '$identifier' already exists");
}
$this->references[$identifier] = $value;
return true;
} | [
"public",
"function",
"addReference",
"(",
"$",
"identifier",
",",
"$",
"value",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"identifier",
",",
"$",
"this",
"->",
"references",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"A reference with identifier '$identifier' already exists\"",
")",
";",
"}",
"$",
"this",
"->",
"references",
"[",
"$",
"identifier",
"]",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}"
] | Add a reference to be retrieved later.
@param string $identifier The identifier of the reference
@param mixed $value The value of the reference
@param bool $overwrite do overwrite the existing ref if it exist without raising an exception
@return bool true if the reference is accepted by this resolver, otherwise false
@throws \Exception When there is a reference with the specified $identifier already. | [
"Add",
"a",
"reference",
"to",
"be",
"retrieved",
"later",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/CustomReferenceResolver.php#L53-L62 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.getMigrationsDefinitions | public function getMigrationsDefinitions(array $paths = array())
{
// we try to be flexible in file types we support, and the same time avoid loading all files in a directory
$handledDefinitions = array();
foreach ($this->loader->listAvailableDefinitions($paths) as $migrationName => $definitionPath) {
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationName)) {
$handledDefinitions[] = $definitionPath;
}
}
}
// we can not call loadDefinitions with an empty array using the Filesystem loader, or it will start looking in bundles...
if (empty($handledDefinitions) && !empty($paths)) {
return new MigrationDefinitionCollection();
}
return $this->loader->loadDefinitions($handledDefinitions);
} | php | public function getMigrationsDefinitions(array $paths = array())
{
// we try to be flexible in file types we support, and the same time avoid loading all files in a directory
$handledDefinitions = array();
foreach ($this->loader->listAvailableDefinitions($paths) as $migrationName => $definitionPath) {
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationName)) {
$handledDefinitions[] = $definitionPath;
}
}
}
// we can not call loadDefinitions with an empty array using the Filesystem loader, or it will start looking in bundles...
if (empty($handledDefinitions) && !empty($paths)) {
return new MigrationDefinitionCollection();
}
return $this->loader->loadDefinitions($handledDefinitions);
} | [
"public",
"function",
"getMigrationsDefinitions",
"(",
"array",
"$",
"paths",
"=",
"array",
"(",
")",
")",
"{",
"// we try to be flexible in file types we support, and the same time avoid loading all files in a directory",
"$",
"handledDefinitions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"loader",
"->",
"listAvailableDefinitions",
"(",
"$",
"paths",
")",
"as",
"$",
"migrationName",
"=>",
"$",
"definitionPath",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"DefinitionParsers",
"as",
"$",
"definitionParser",
")",
"{",
"if",
"(",
"$",
"definitionParser",
"->",
"supports",
"(",
"$",
"migrationName",
")",
")",
"{",
"$",
"handledDefinitions",
"[",
"]",
"=",
"$",
"definitionPath",
";",
"}",
"}",
"}",
"// we can not call loadDefinitions with an empty array using the Filesystem loader, or it will start looking in bundles...",
"if",
"(",
"empty",
"(",
"$",
"handledDefinitions",
")",
"&&",
"!",
"empty",
"(",
"$",
"paths",
")",
")",
"{",
"return",
"new",
"MigrationDefinitionCollection",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loader",
"->",
"loadDefinitions",
"(",
"$",
"handledDefinitions",
")",
";",
"}"
] | NB: returns UNPARSED definitions
@param string[] $paths
@return MigrationDefinitionCollection key: migration name, value: migration definition as binary string | [
"NB",
":",
"returns",
"UNPARSED",
"definitions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L120-L138 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.getMigrations | public function getMigrations($limit = null, $offset = null)
{
return $this->storageHandler->loadMigrations($limit, $offset);
} | php | public function getMigrations($limit = null, $offset = null)
{
return $this->storageHandler->loadMigrations($limit, $offset);
} | [
"public",
"function",
"getMigrations",
"(",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"storageHandler",
"->",
"loadMigrations",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"}"
] | Returns the list of all the migrations which where executed or attempted so far
@param int $limit 0 or below will be treated as 'no limit'
@param int $offset
@return \Kaliop\eZMigrationBundle\API\Collection\MigrationCollection | [
"Returns",
"the",
"list",
"of",
"all",
"the",
"migrations",
"which",
"where",
"executed",
"or",
"attempted",
"so",
"far"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L147-L150 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.getMigrationsByStatus | public function getMigrationsByStatus($status, $limit = null, $offset = null)
{
return $this->storageHandler->loadMigrationsByStatus($status, $limit, $offset);
} | php | public function getMigrationsByStatus($status, $limit = null, $offset = null)
{
return $this->storageHandler->loadMigrationsByStatus($status, $limit, $offset);
} | [
"public",
"function",
"getMigrationsByStatus",
"(",
"$",
"status",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"storageHandler",
"->",
"loadMigrationsByStatus",
"(",
"$",
"status",
",",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"}"
] | Returns the list of all the migrations in a given status which where executed or attempted so far
@param int $status
@param int $limit 0 or below will be treated as 'no limit'
@param int $offset
@return \Kaliop\eZMigrationBundle\API\Collection\MigrationCollection | [
"Returns",
"the",
"list",
"of",
"all",
"the",
"migrations",
"in",
"a",
"given",
"status",
"which",
"where",
"executed",
"or",
"attempted",
"so",
"far"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L160-L163 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.parseMigrationDefinition | public function parseMigrationDefinition(MigrationDefinition $migrationDefinition)
{
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationDefinition->name)) {
// parse the source file
$migrationDefinition = $definitionParser->parseMigrationDefinition($migrationDefinition);
// and make sure we know how to handle all steps
foreach ($migrationDefinition->steps as $step) {
if (!isset($this->executors[$step->type])) {
return new MigrationDefinition(
$migrationDefinition->name,
$migrationDefinition->path,
$migrationDefinition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Can not handle migration step of type '{$step->type}'"
);
}
}
return $migrationDefinition;
}
}
throw new \Exception("No parser available to parse migration definition '{$migrationDefinition->name}'");
} | php | public function parseMigrationDefinition(MigrationDefinition $migrationDefinition)
{
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationDefinition->name)) {
// parse the source file
$migrationDefinition = $definitionParser->parseMigrationDefinition($migrationDefinition);
// and make sure we know how to handle all steps
foreach ($migrationDefinition->steps as $step) {
if (!isset($this->executors[$step->type])) {
return new MigrationDefinition(
$migrationDefinition->name,
$migrationDefinition->path,
$migrationDefinition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Can not handle migration step of type '{$step->type}'"
);
}
}
return $migrationDefinition;
}
}
throw new \Exception("No parser available to parse migration definition '{$migrationDefinition->name}'");
} | [
"public",
"function",
"parseMigrationDefinition",
"(",
"MigrationDefinition",
"$",
"migrationDefinition",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"DefinitionParsers",
"as",
"$",
"definitionParser",
")",
"{",
"if",
"(",
"$",
"definitionParser",
"->",
"supports",
"(",
"$",
"migrationDefinition",
"->",
"name",
")",
")",
"{",
"// parse the source file",
"$",
"migrationDefinition",
"=",
"$",
"definitionParser",
"->",
"parseMigrationDefinition",
"(",
"$",
"migrationDefinition",
")",
";",
"// and make sure we know how to handle all steps",
"foreach",
"(",
"$",
"migrationDefinition",
"->",
"steps",
"as",
"$",
"step",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"executors",
"[",
"$",
"step",
"->",
"type",
"]",
")",
")",
"{",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"migrationDefinition",
"->",
"name",
",",
"$",
"migrationDefinition",
"->",
"path",
",",
"$",
"migrationDefinition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_INVALID",
",",
"array",
"(",
")",
",",
"\"Can not handle migration step of type '{$step->type}'\"",
")",
";",
"}",
"}",
"return",
"$",
"migrationDefinition",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No parser available to parse migration definition '{$migrationDefinition->name}'\"",
")",
";",
"}"
] | Parses a migration definition, return a parsed definition.
If there is a parsing error, the definition status will be updated accordingly
@param MigrationDefinition $migrationDefinition
@return MigrationDefinition
@throws \Exception if the migrationDefinition has no suitable parser for its source format | [
"Parses",
"a",
"migration",
"definition",
"return",
"a",
"parsed",
"definition",
".",
"If",
"there",
"is",
"a",
"parsing",
"error",
"the",
"definition",
"status",
"will",
"be",
"updated",
"accordingly"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L218-L244 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.executeMigration | public function executeMigration(MigrationDefinition $migrationDefinition, $useTransaction = true,
$defaultLanguageCode = null, $adminLogin = null, $force = false, $forceSigchildEnabled = null)
{
if ($migrationDefinition->status == MigrationDefinition::STATUS_TO_PARSE) {
$migrationDefinition = $this->parseMigrationDefinition($migrationDefinition);
}
if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
throw new \Exception("Can not execute " . $this->getEntityName($migrationDefinition). " '{$migrationDefinition->name}': {$migrationDefinition->parsingError}");
}
/// @todo add support for setting in $migrationContext a userContentType ?
$migrationContext = $this->migrationContextFromParameters($defaultLanguageCode, $adminLogin, $forceSigchildEnabled);
// set migration as begun - has to be in own db transaction
$migration = $this->storageHandler->startMigration($migrationDefinition, $force);
$this->executeMigrationInner($migration, $migrationDefinition, $migrationContext, 0, $useTransaction, $adminLogin);
} | php | public function executeMigration(MigrationDefinition $migrationDefinition, $useTransaction = true,
$defaultLanguageCode = null, $adminLogin = null, $force = false, $forceSigchildEnabled = null)
{
if ($migrationDefinition->status == MigrationDefinition::STATUS_TO_PARSE) {
$migrationDefinition = $this->parseMigrationDefinition($migrationDefinition);
}
if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
throw new \Exception("Can not execute " . $this->getEntityName($migrationDefinition). " '{$migrationDefinition->name}': {$migrationDefinition->parsingError}");
}
/// @todo add support for setting in $migrationContext a userContentType ?
$migrationContext = $this->migrationContextFromParameters($defaultLanguageCode, $adminLogin, $forceSigchildEnabled);
// set migration as begun - has to be in own db transaction
$migration = $this->storageHandler->startMigration($migrationDefinition, $force);
$this->executeMigrationInner($migration, $migrationDefinition, $migrationContext, 0, $useTransaction, $adminLogin);
} | [
"public",
"function",
"executeMigration",
"(",
"MigrationDefinition",
"$",
"migrationDefinition",
",",
"$",
"useTransaction",
"=",
"true",
",",
"$",
"defaultLanguageCode",
"=",
"null",
",",
"$",
"adminLogin",
"=",
"null",
",",
"$",
"force",
"=",
"false",
",",
"$",
"forceSigchildEnabled",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"migrationDefinition",
"->",
"status",
"==",
"MigrationDefinition",
"::",
"STATUS_TO_PARSE",
")",
"{",
"$",
"migrationDefinition",
"=",
"$",
"this",
"->",
"parseMigrationDefinition",
"(",
"$",
"migrationDefinition",
")",
";",
"}",
"if",
"(",
"$",
"migrationDefinition",
"->",
"status",
"==",
"MigrationDefinition",
"::",
"STATUS_INVALID",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migrationDefinition",
")",
".",
"\" '{$migrationDefinition->name}': {$migrationDefinition->parsingError}\"",
")",
";",
"}",
"/// @todo add support for setting in $migrationContext a userContentType ?",
"$",
"migrationContext",
"=",
"$",
"this",
"->",
"migrationContextFromParameters",
"(",
"$",
"defaultLanguageCode",
",",
"$",
"adminLogin",
",",
"$",
"forceSigchildEnabled",
")",
";",
"// set migration as begun - has to be in own db transaction",
"$",
"migration",
"=",
"$",
"this",
"->",
"storageHandler",
"->",
"startMigration",
"(",
"$",
"migrationDefinition",
",",
"$",
"force",
")",
";",
"$",
"this",
"->",
"executeMigrationInner",
"(",
"$",
"migration",
",",
"$",
"migrationDefinition",
",",
"$",
"migrationContext",
",",
"0",
",",
"$",
"useTransaction",
",",
"$",
"adminLogin",
")",
";",
"}"
] | @param MigrationDefinition $migrationDefinition
@param bool $useTransaction when set to false, no repo transaction will be used to wrap the migration
@param string $defaultLanguageCode
@param string|int|false|null $adminLogin when false, current user is used; when null, hardcoded admin account
@param bool $force when true, execute a migration if it was already in status DONE or SKIPPED (would throw by default)
@param bool|null forceSigchildEnabled
@throws \Exception
@todo treating a null and false $adminLogin values differently is prone to hard-to-track errors.
Shall we use instead -1 to indicate the desire to not-login-as-admin-user-at-all ?
@todo refactor there start to be too many parameters here. Move to an single parameter: array of options or value-object | [
"@param",
"MigrationDefinition",
"$migrationDefinition",
"@param",
"bool",
"$useTransaction",
"when",
"set",
"to",
"false",
"no",
"repo",
"transaction",
"will",
"be",
"used",
"to",
"wrap",
"the",
"migration",
"@param",
"string",
"$defaultLanguageCode",
"@param",
"string|int|false|null",
"$adminLogin",
"when",
"false",
"current",
"user",
"is",
"used",
";",
"when",
"null",
"hardcoded",
"admin",
"account",
"@param",
"bool",
"$force",
"when",
"true",
"execute",
"a",
"migration",
"if",
"it",
"was",
"already",
"in",
"status",
"DONE",
"or",
"SKIPPED",
"(",
"would",
"throw",
"by",
"default",
")",
"@param",
"bool|null",
"forceSigchildEnabled",
"@throws",
"\\",
"Exception"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L259-L277 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.resumeMigration | public function resumeMigration(Migration $migration, $useTransaction = true)
{
if ($migration->status != Migration::STATUS_SUSPENDED) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': it is not in suspended status");
}
$migrationDefinitions = $this->getMigrationsDefinitions(array($migration->path));
if (!count($migrationDefinitions)) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': its definition is missing");
}
$defs = $migrationDefinitions->getArrayCopy();
$migrationDefinition = reset($defs);
$migrationDefinition = $this->parseMigrationDefinition($migrationDefinition);
if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': {$migrationDefinition->parsingError}");
}
// restore context
$this->contextHandler->restoreCurrentContext($migration->name);
if (!isset($this->migrationContext[$migration->name])) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is missing");
}
$restoredContext = $this->migrationContext[$migration->name];
if (!is_array($restoredContext) || !isset($restoredContext['context']) || !isset($restoredContext['step'] )) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is invalid");
}
// update migration status
$migration = $this->storageHandler->resumeMigration($migration);
// clean up restored context - ideally it should be in the same db transaction as the line above
$this->contextHandler->deleteContext($migration->name);
// and go
// note: we store the current step counting starting at 1, but use offset starting at 0, hence the -1 here
$this->executeMigrationInner($migration, $migrationDefinition, $restoredContext['context'],
$restoredContext['step'] - 1, $useTransaction);
} | php | public function resumeMigration(Migration $migration, $useTransaction = true)
{
if ($migration->status != Migration::STATUS_SUSPENDED) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': it is not in suspended status");
}
$migrationDefinitions = $this->getMigrationsDefinitions(array($migration->path));
if (!count($migrationDefinitions)) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': its definition is missing");
}
$defs = $migrationDefinitions->getArrayCopy();
$migrationDefinition = reset($defs);
$migrationDefinition = $this->parseMigrationDefinition($migrationDefinition);
if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': {$migrationDefinition->parsingError}");
}
// restore context
$this->contextHandler->restoreCurrentContext($migration->name);
if (!isset($this->migrationContext[$migration->name])) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is missing");
}
$restoredContext = $this->migrationContext[$migration->name];
if (!is_array($restoredContext) || !isset($restoredContext['context']) || !isset($restoredContext['step'] )) {
throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is invalid");
}
// update migration status
$migration = $this->storageHandler->resumeMigration($migration);
// clean up restored context - ideally it should be in the same db transaction as the line above
$this->contextHandler->deleteContext($migration->name);
// and go
// note: we store the current step counting starting at 1, but use offset starting at 0, hence the -1 here
$this->executeMigrationInner($migration, $migrationDefinition, $restoredContext['context'],
$restoredContext['step'] - 1, $useTransaction);
} | [
"public",
"function",
"resumeMigration",
"(",
"Migration",
"$",
"migration",
",",
"$",
"useTransaction",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"migration",
"->",
"status",
"!=",
"Migration",
"::",
"STATUS_SUSPENDED",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not resume \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migration",
")",
".",
"\" '{$migration->name}': it is not in suspended status\"",
")",
";",
"}",
"$",
"migrationDefinitions",
"=",
"$",
"this",
"->",
"getMigrationsDefinitions",
"(",
"array",
"(",
"$",
"migration",
"->",
"path",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"migrationDefinitions",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not resume \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migration",
")",
".",
"\" '{$migration->name}': its definition is missing\"",
")",
";",
"}",
"$",
"defs",
"=",
"$",
"migrationDefinitions",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"migrationDefinition",
"=",
"reset",
"(",
"$",
"defs",
")",
";",
"$",
"migrationDefinition",
"=",
"$",
"this",
"->",
"parseMigrationDefinition",
"(",
"$",
"migrationDefinition",
")",
";",
"if",
"(",
"$",
"migrationDefinition",
"->",
"status",
"==",
"MigrationDefinition",
"::",
"STATUS_INVALID",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not resume \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migration",
")",
".",
"\" '{$migration->name}': {$migrationDefinition->parsingError}\"",
")",
";",
"}",
"// restore context",
"$",
"this",
"->",
"contextHandler",
"->",
"restoreCurrentContext",
"(",
"$",
"migration",
"->",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"migrationContext",
"[",
"$",
"migration",
"->",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not resume \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migration",
")",
".",
"\" '{$migration->name}': the stored context is missing\"",
")",
";",
"}",
"$",
"restoredContext",
"=",
"$",
"this",
"->",
"migrationContext",
"[",
"$",
"migration",
"->",
"name",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"restoredContext",
")",
"||",
"!",
"isset",
"(",
"$",
"restoredContext",
"[",
"'context'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"restoredContext",
"[",
"'step'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not resume \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
"$",
"migration",
")",
".",
"\" '{$migration->name}': the stored context is invalid\"",
")",
";",
"}",
"// update migration status",
"$",
"migration",
"=",
"$",
"this",
"->",
"storageHandler",
"->",
"resumeMigration",
"(",
"$",
"migration",
")",
";",
"// clean up restored context - ideally it should be in the same db transaction as the line above",
"$",
"this",
"->",
"contextHandler",
"->",
"deleteContext",
"(",
"$",
"migration",
"->",
"name",
")",
";",
"// and go",
"// note: we store the current step counting starting at 1, but use offset starting at 0, hence the -1 here",
"$",
"this",
"->",
"executeMigrationInner",
"(",
"$",
"migration",
",",
"$",
"migrationDefinition",
",",
"$",
"restoredContext",
"[",
"'context'",
"]",
",",
"$",
"restoredContext",
"[",
"'step'",
"]",
"-",
"1",
",",
"$",
"useTransaction",
")",
";",
"}"
] | @param Migration $migration
@param bool $useTransaction
@throws \Exception
@todo add support for adminLogin ? | [
"@param",
"Migration",
"$migration",
"@param",
"bool",
"$useTransaction",
"@throws",
"\\",
"Exception"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L433-L473 |
kaliop-uk/ezmigrationbundle | Core/MigrationService.php | MigrationService.getFullExceptionMessage | protected function getFullExceptionMessage(\Exception $e)
{
$message = $e->getMessage();
if (is_a($e, '\eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException') ||
is_a($e, '\eZ\Publish\API\Repository\Exceptions\LimitationValidationException') ||
is_a($e, '\eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException')
) {
if (is_a($e, '\eZ\Publish\API\Repository\Exceptions\LimitationValidationException')) {
$errorsArray = $e->getLimitationErrors();
if ($errorsArray == null) {
return $message;
}
} else if (is_a($e, '\eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException')) {
$errorsArray = array();
foreach ($e->getFieldErrors() as $limitationError) {
// we get the 1st language
$errorsArray[] = reset($limitationError);
}
} else {
$errorsArray = $e->getFieldErrors();
}
foreach ($errorsArray as $errors) {
// sometimes error arrays are 2-level deep, sometimes 1...
if (!is_array($errors)) {
$errors = array($errors);
}
foreach ($errors as $error) {
/// @todo find out what is the proper eZ way of getting a translated message for these errors
$translatableMessage = $error->getTranslatableMessage();
if (is_a($translatableMessage, '\eZ\Publish\API\Repository\Values\Translation\Plural')) {
$msgText = $translatableMessage->plural;
} else {
$msgText = $translatableMessage->message;
}
$message .= "\n" . $msgText . " - " . var_export($translatableMessage->values, true);
}
}
}
while (($e = $e->getPrevious()) != null) {
$message .= "\n" . $e->getMessage();
}
return $message;
} | php | protected function getFullExceptionMessage(\Exception $e)
{
$message = $e->getMessage();
if (is_a($e, '\eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException') ||
is_a($e, '\eZ\Publish\API\Repository\Exceptions\LimitationValidationException') ||
is_a($e, '\eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException')
) {
if (is_a($e, '\eZ\Publish\API\Repository\Exceptions\LimitationValidationException')) {
$errorsArray = $e->getLimitationErrors();
if ($errorsArray == null) {
return $message;
}
} else if (is_a($e, '\eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException')) {
$errorsArray = array();
foreach ($e->getFieldErrors() as $limitationError) {
// we get the 1st language
$errorsArray[] = reset($limitationError);
}
} else {
$errorsArray = $e->getFieldErrors();
}
foreach ($errorsArray as $errors) {
// sometimes error arrays are 2-level deep, sometimes 1...
if (!is_array($errors)) {
$errors = array($errors);
}
foreach ($errors as $error) {
/// @todo find out what is the proper eZ way of getting a translated message for these errors
$translatableMessage = $error->getTranslatableMessage();
if (is_a($translatableMessage, '\eZ\Publish\API\Repository\Values\Translation\Plural')) {
$msgText = $translatableMessage->plural;
} else {
$msgText = $translatableMessage->message;
}
$message .= "\n" . $msgText . " - " . var_export($translatableMessage->values, true);
}
}
}
while (($e = $e->getPrevious()) != null) {
$message .= "\n" . $e->getMessage();
}
return $message;
} | [
"protected",
"function",
"getFullExceptionMessage",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"e",
",",
"'\\eZ\\Publish\\API\\Repository\\Exceptions\\ContentTypeFieldDefinitionValidationException'",
")",
"||",
"is_a",
"(",
"$",
"e",
",",
"'\\eZ\\Publish\\API\\Repository\\Exceptions\\LimitationValidationException'",
")",
"||",
"is_a",
"(",
"$",
"e",
",",
"'\\eZ\\Publish\\Core\\Base\\Exceptions\\ContentFieldValidationException'",
")",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"e",
",",
"'\\eZ\\Publish\\API\\Repository\\Exceptions\\LimitationValidationException'",
")",
")",
"{",
"$",
"errorsArray",
"=",
"$",
"e",
"->",
"getLimitationErrors",
"(",
")",
";",
"if",
"(",
"$",
"errorsArray",
"==",
"null",
")",
"{",
"return",
"$",
"message",
";",
"}",
"}",
"else",
"if",
"(",
"is_a",
"(",
"$",
"e",
",",
"'\\eZ\\Publish\\Core\\Base\\Exceptions\\ContentFieldValidationException'",
")",
")",
"{",
"$",
"errorsArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"e",
"->",
"getFieldErrors",
"(",
")",
"as",
"$",
"limitationError",
")",
"{",
"// we get the 1st language",
"$",
"errorsArray",
"[",
"]",
"=",
"reset",
"(",
"$",
"limitationError",
")",
";",
"}",
"}",
"else",
"{",
"$",
"errorsArray",
"=",
"$",
"e",
"->",
"getFieldErrors",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"errorsArray",
"as",
"$",
"errors",
")",
"{",
"// sometimes error arrays are 2-level deep, sometimes 1...",
"if",
"(",
"!",
"is_array",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
"$",
"errors",
")",
";",
"}",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"/// @todo find out what is the proper eZ way of getting a translated message for these errors",
"$",
"translatableMessage",
"=",
"$",
"error",
"->",
"getTranslatableMessage",
"(",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"translatableMessage",
",",
"'\\eZ\\Publish\\API\\Repository\\Values\\Translation\\Plural'",
")",
")",
"{",
"$",
"msgText",
"=",
"$",
"translatableMessage",
"->",
"plural",
";",
"}",
"else",
"{",
"$",
"msgText",
"=",
"$",
"translatableMessage",
"->",
"message",
";",
"}",
"$",
"message",
".=",
"\"\\n\"",
".",
"$",
"msgText",
".",
"\" - \"",
".",
"var_export",
"(",
"$",
"translatableMessage",
"->",
"values",
",",
"true",
")",
";",
"}",
"}",
"}",
"while",
"(",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
"!=",
"null",
")",
"{",
"$",
"message",
".=",
"\"\\n\"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Turns eZPublish cryptic exceptions into something more palatable for random devs
@todo should this be moved to a lower layer ?
@param \Exception $e
@return string | [
"Turns",
"eZPublish",
"cryptic",
"exceptions",
"into",
"something",
"more",
"palatable",
"for",
"random",
"devs",
"@todo",
"should",
"this",
"be",
"moved",
"to",
"a",
"lower",
"layer",
"?"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/MigrationService.php#L529-L575 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzBinaryFile.php | EzBinaryFile.hashToFieldValue | public function hashToFieldValue($fieldValue, array $context = array())
{
$mimeType = '';
$fileName = '';
if ($fieldValue === null) {
return new BinaryFileValue();
} if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
$filePath = $fieldValue['path'];
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
if (isset($fieldValue['mime_type'])) {
$mimeType = $fieldValue['mime_type'];
}
}
// default format: path is relative to the 'files' dir
$realFilePath = dirname($context['path']) . '/files/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new BinaryFileValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath)
)
);
} | php | public function hashToFieldValue($fieldValue, array $context = array())
{
$mimeType = '';
$fileName = '';
if ($fieldValue === null) {
return new BinaryFileValue();
} if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
$filePath = $fieldValue['path'];
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
if (isset($fieldValue['mime_type'])) {
$mimeType = $fieldValue['mime_type'];
}
}
// default format: path is relative to the 'files' dir
$realFilePath = dirname($context['path']) . '/files/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new BinaryFileValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath)
)
);
} | [
"public",
"function",
"hashToFieldValue",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"mimeType",
"=",
"''",
";",
"$",
"fileName",
"=",
"''",
";",
"if",
"(",
"$",
"fieldValue",
"===",
"null",
")",
"{",
"return",
"new",
"BinaryFileValue",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"fieldValue",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
";",
"}",
"else",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
"[",
"'path'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'filename'",
"]",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"fieldValue",
"[",
"'filename'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'mime_type'",
"]",
")",
")",
"{",
"$",
"mimeType",
"=",
"$",
"fieldValue",
"[",
"'mime_type'",
"]",
";",
"}",
"}",
"// default format: path is relative to the 'files' dir",
"$",
"realFilePath",
"=",
"dirname",
"(",
"$",
"context",
"[",
"'path'",
"]",
")",
".",
"'/files/'",
".",
"$",
"filePath",
";",
"// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well",
"if",
"(",
"!",
"is_file",
"(",
"$",
"realFilePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"realFilePath",
"=",
"$",
"filePath",
";",
"}",
"return",
"new",
"BinaryFileValue",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"realFilePath",
",",
"'fileSize'",
"=>",
"filesize",
"(",
"$",
"realFilePath",
")",
",",
"'fileName'",
"=>",
"$",
"fileName",
"!=",
"''",
"?",
"$",
"fileName",
":",
"basename",
"(",
"$",
"realFilePath",
")",
",",
"'mimeType'",
"=>",
"$",
"mimeType",
"!=",
"''",
"?",
"$",
"mimeType",
":",
"mime_content_type",
"(",
"$",
"realFilePath",
")",
")",
")",
";",
"}"
] | @param array|string $fieldValue The path to the file or an array with 'path' key
@param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
@return BinaryFileValue
@todo resolve refs more | [
"@param",
"array|string",
"$fieldValue",
"The",
"path",
"to",
"the",
"file",
"or",
"an",
"array",
"with",
"path",
"key",
"@param",
"array",
"$context",
"The",
"context",
"for",
"execution",
"of",
"the",
"current",
"migrations",
".",
"Contains",
"f",
".",
"e",
".",
"the",
"path",
"to",
"the",
"migration",
"@return",
"BinaryFileValue"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzBinaryFile.php#L17-L52 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzBinaryFile.php | EzBinaryFile.fieldValueToHash | public function fieldValueToHash($fieldValue, array $context = array())
{
if ($fieldValue->uri == null) {
return null;
}
return array(
'path' => realpath($this->ioRootDir) . '/' . ($this->ioDecorator ? $this->ioDecorator->undecorate($fieldValue->uri) : $fieldValue->uri),
'filename'=> $fieldValue->fileName,
'mimeType' => $fieldValue->mimeType
);
} | php | public function fieldValueToHash($fieldValue, array $context = array())
{
if ($fieldValue->uri == null) {
return null;
}
return array(
'path' => realpath($this->ioRootDir) . '/' . ($this->ioDecorator ? $this->ioDecorator->undecorate($fieldValue->uri) : $fieldValue->uri),
'filename'=> $fieldValue->fileName,
'mimeType' => $fieldValue->mimeType
);
} | [
"public",
"function",
"fieldValueToHash",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"fieldValue",
"->",
"uri",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"array",
"(",
"'path'",
"=>",
"realpath",
"(",
"$",
"this",
"->",
"ioRootDir",
")",
".",
"'/'",
".",
"(",
"$",
"this",
"->",
"ioDecorator",
"?",
"$",
"this",
"->",
"ioDecorator",
"->",
"undecorate",
"(",
"$",
"fieldValue",
"->",
"uri",
")",
":",
"$",
"fieldValue",
"->",
"uri",
")",
",",
"'filename'",
"=>",
"$",
"fieldValue",
"->",
"fileName",
",",
"'mimeType'",
"=>",
"$",
"fieldValue",
"->",
"mimeType",
")",
";",
"}"
] | @param \eZ\Publish\Core\FieldType\BinaryFile\Value $fieldValue
@param array $context
@return array
@todo check if this works in ezplatform | [
"@param",
"\\",
"eZ",
"\\",
"Publish",
"\\",
"Core",
"\\",
"FieldType",
"\\",
"BinaryFile",
"\\",
"Value",
"$fieldValue",
"@param",
"array",
"$context",
"@return",
"array"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzBinaryFile.php#L61-L72 |
kaliop-uk/ezmigrationbundle | MigrationVersions/20100101000200_MigrateV1ToV2.php | MigrateV1ToV2.getLegacyMigrationDefinition | private function getLegacyMigrationDefinition($version, $bundle)
{
if (!isset($this->activeBundles[$bundle])) {
return false;
}
$versionsDir = $this->activeBundles[$bundle] . '/' . $this->legacyMigrationsDir;
$versionDefinitions = glob($versionsDir . "/$version*");
if (!is_array($versionDefinitions)) {
return false;
}
foreach ($versionDefinitions as $key => $versionDefinition) {
if (!in_array(pathinfo($versionDefinition, PATHINFO_EXTENSION), array('php', 'yml', 'sql'))) {
unset($versionDefinitions[$key]);
}
}
if (empty($versionDefinitions)) {
return false;
}
return $versionDefinitions[0];
} | php | private function getLegacyMigrationDefinition($version, $bundle)
{
if (!isset($this->activeBundles[$bundle])) {
return false;
}
$versionsDir = $this->activeBundles[$bundle] . '/' . $this->legacyMigrationsDir;
$versionDefinitions = glob($versionsDir . "/$version*");
if (!is_array($versionDefinitions)) {
return false;
}
foreach ($versionDefinitions as $key => $versionDefinition) {
if (!in_array(pathinfo($versionDefinition, PATHINFO_EXTENSION), array('php', 'yml', 'sql'))) {
unset($versionDefinitions[$key]);
}
}
if (empty($versionDefinitions)) {
return false;
}
return $versionDefinitions[0];
} | [
"private",
"function",
"getLegacyMigrationDefinition",
"(",
"$",
"version",
",",
"$",
"bundle",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"activeBundles",
"[",
"$",
"bundle",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"versionsDir",
"=",
"$",
"this",
"->",
"activeBundles",
"[",
"$",
"bundle",
"]",
".",
"'/'",
".",
"$",
"this",
"->",
"legacyMigrationsDir",
";",
"$",
"versionDefinitions",
"=",
"glob",
"(",
"$",
"versionsDir",
".",
"\"/$version*\"",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"versionDefinitions",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"versionDefinitions",
"as",
"$",
"key",
"=>",
"$",
"versionDefinition",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"pathinfo",
"(",
"$",
"versionDefinition",
",",
"PATHINFO_EXTENSION",
")",
",",
"array",
"(",
"'php'",
",",
"'yml'",
",",
"'sql'",
")",
")",
")",
"{",
"unset",
"(",
"$",
"versionDefinitions",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"versionDefinitions",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"versionDefinitions",
"[",
"0",
"]",
";",
"}"
] | Attempts to find the migration definition file. If more than one matches, the 1st found is returned
@param string $version
@param string $bundle
@return string|false | [
"Attempts",
"to",
"find",
"the",
"migration",
"definition",
"file",
".",
"If",
"more",
"than",
"one",
"matches",
"the",
"1st",
"found",
"is",
"returned"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/MigrationVersions/20100101000200_MigrateV1ToV2.php#L140-L164 |
kaliop-uk/ezmigrationbundle | Core/DefinitionParser/SQLDefinitionParser.php | SQLDefinitionParser.parseMigrationDefinition | public function parseMigrationDefinition(MigrationDefinition $definition)
{
$dbType = $this->getDBFromFile($definition->name);
if (!in_array($dbType, $this->supportedDatabases))
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Unsupported or missing database: '$dbType'. The database name is the part of the filename after the 1st underscore"
);
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
array(
new MigrationStep('sql', array($dbType => $definition->rawDefinition), array('path' => $definition->path))
)
);
} | php | public function parseMigrationDefinition(MigrationDefinition $definition)
{
$dbType = $this->getDBFromFile($definition->name);
if (!in_array($dbType, $this->supportedDatabases))
{
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Unsupported or missing database: '$dbType'. The database name is the part of the filename after the 1st underscore"
);
}
return new MigrationDefinition(
$definition->name,
$definition->path,
$definition->rawDefinition,
MigrationDefinition::STATUS_PARSED,
array(
new MigrationStep('sql', array($dbType => $definition->rawDefinition), array('path' => $definition->path))
)
);
} | [
"public",
"function",
"parseMigrationDefinition",
"(",
"MigrationDefinition",
"$",
"definition",
")",
"{",
"$",
"dbType",
"=",
"$",
"this",
"->",
"getDBFromFile",
"(",
"$",
"definition",
"->",
"name",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"dbType",
",",
"$",
"this",
"->",
"supportedDatabases",
")",
")",
"{",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_INVALID",
",",
"array",
"(",
")",
",",
"\"Unsupported or missing database: '$dbType'. The database name is the part of the filename after the 1st underscore\"",
")",
";",
"}",
"return",
"new",
"MigrationDefinition",
"(",
"$",
"definition",
"->",
"name",
",",
"$",
"definition",
"->",
"path",
",",
"$",
"definition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_PARSED",
",",
"array",
"(",
"new",
"MigrationStep",
"(",
"'sql'",
",",
"array",
"(",
"$",
"dbType",
"=>",
"$",
"definition",
"->",
"rawDefinition",
")",
",",
"array",
"(",
"'path'",
"=>",
"$",
"definition",
"->",
"path",
")",
")",
")",
")",
";",
"}"
] | Parses a migration definition file, and returns the list of actions to take
@param MigrationDefinition $definition
@return MigrationDefinition | [
"Parses",
"a",
"migration",
"definition",
"file",
"and",
"returns",
"the",
"list",
"of",
"actions",
"to",
"take"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/DefinitionParser/SQLDefinitionParser.php#L39-L64 |
kaliop-uk/ezmigrationbundle | Core/DefinitionParser/SQLDefinitionParser.php | SQLDefinitionParser.getDBFromFile | protected function getDBFromFile($fileName)
{
$parts = explode('_', preg_replace('/\.sql$/', '', $fileName));
return isset($parts[1]) ? $parts[1] : null;
} | php | protected function getDBFromFile($fileName)
{
$parts = explode('_', preg_replace('/\.sql$/', '', $fileName));
return isset($parts[1]) ? $parts[1] : null;
} | [
"protected",
"function",
"getDBFromFile",
"(",
"$",
"fileName",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'_'",
",",
"preg_replace",
"(",
"'/\\.sql$/'",
",",
"''",
",",
"$",
"fileName",
")",
")",
";",
"return",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"parts",
"[",
"1",
"]",
":",
"null",
";",
"}"
] | allow both aaaa_mysql_etc.sql and aaaa_mysql.sql | [
"allow",
"both",
"aaaa_mysql_etc",
".",
"sql",
"and",
"aaaa_mysql",
".",
"sql"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/DefinitionParser/SQLDefinitionParser.php#L67-L71 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzXmlText.php | EzXmlText.hashToFieldValue | public function hashToFieldValue($fieldValue, array $context = array())
{
if (is_string($fieldValue)) {
$xmlText = $fieldValue;
} else if (is_array($fieldValue) && isset($fieldValue['xml'])) {
// native export format from eZ
$xmlText = $fieldValue['xml'];
} else {
$xmlText = $fieldValue['content'];
}
// Check if there are any references in the xml text and replace them. Please phpstorm.
$resolver = $this->referenceResolver;
/** @var EmbeddedReferenceResolverInterface $resolver */
return $resolver->resolveEmbeddedReferences($xmlText);
} | php | public function hashToFieldValue($fieldValue, array $context = array())
{
if (is_string($fieldValue)) {
$xmlText = $fieldValue;
} else if (is_array($fieldValue) && isset($fieldValue['xml'])) {
// native export format from eZ
$xmlText = $fieldValue['xml'];
} else {
$xmlText = $fieldValue['content'];
}
// Check if there are any references in the xml text and replace them. Please phpstorm.
$resolver = $this->referenceResolver;
/** @var EmbeddedReferenceResolverInterface $resolver */
return $resolver->resolveEmbeddedReferences($xmlText);
} | [
"public",
"function",
"hashToFieldValue",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"fieldValue",
")",
")",
"{",
"$",
"xmlText",
"=",
"$",
"fieldValue",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"fieldValue",
")",
"&&",
"isset",
"(",
"$",
"fieldValue",
"[",
"'xml'",
"]",
")",
")",
"{",
"// native export format from eZ",
"$",
"xmlText",
"=",
"$",
"fieldValue",
"[",
"'xml'",
"]",
";",
"}",
"else",
"{",
"$",
"xmlText",
"=",
"$",
"fieldValue",
"[",
"'content'",
"]",
";",
"}",
"// Check if there are any references in the xml text and replace them. Please phpstorm.",
"$",
"resolver",
"=",
"$",
"this",
"->",
"referenceResolver",
";",
"/** @var EmbeddedReferenceResolverInterface $resolver */",
"return",
"$",
"resolver",
"->",
"resolveEmbeddedReferences",
"(",
"$",
"xmlText",
")",
";",
"}"
] | Replaces any references in an xml string to be used as the input data for an ezxmltext field.
@param string|array $fieldValue The definition of teh field value, structured in the yml file. Either a string, or an array with key 'content'
@param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
@return string
@todo replace objects and location refs in eznode and ezobject links | [
"Replaces",
"any",
"references",
"in",
"an",
"xml",
"string",
"to",
"be",
"used",
"as",
"the",
"input",
"data",
"for",
"an",
"ezxmltext",
"field",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzXmlText.php#L29-L44 |
kaliop-uk/ezmigrationbundle | Command/MigrationCommand.php | MigrationCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setOutput($output);
$this->setVerbosity($output->getVerbosity());
if (!$input->getOption('add') && !$input->getOption('delete') && !$input->getOption('skip') && !$input->getOption('info')) {
throw new \InvalidArgumentException('You must specify whether you want to --add, --delete, --skip or --info the specified migration.');
}
$migrationService = $this->getMigrationService();
$migrationNameOrPath = $input->getArgument('migration');
if ($input->getOption('info')) {
$output->writeln('');
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration == null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does not exist in the migrations table.', $migrationNameOrPath));
}
switch ($migration->status) {
case Migration::STATUS_DONE:
$status = '<info>executed</info>';
break;
case Migration::STATUS_STARTED:
$status = '<comment>execution started</comment>';
break;
case Migration::STATUS_TODO:
// bold to-migrate!
$status = '<error>not executed</error>';
break;
case Migration::STATUS_SKIPPED:
$status = '<comment>skipped</comment>';
break;
case Migration::STATUS_PARTIALLY_DONE:
$status = '<comment>partially executed</comment>';
break;
case Migration::STATUS_SUSPENDED:
$status = '<comment>suspended</comment>';
break;
case Migration::STATUS_FAILED:
$status = '<error>failed</error>';
break;
}
$output->writeln('<info>Migration: ' . $migration->name . '</info>');
$output->writeln('Status: ' . $status);
$output->writeln('Executed on: <info>' . ($migration->executionDate != null ? date("Y-m-d H:i:s", $migration->executionDate) : '--'). '</info>');
$output->writeln('Execution notes: <info>' . $migration->executionError . '</info>');
if ($migration->status == Migration::STATUS_SUSPENDED) {
/// @todo decode the suspension context: date, step, ...
}
$output->writeln('Definition path: <info>' . $migration->path . '</info>');
$output->writeln('Definition md5: <info>' . $migration->md5 . '</info>');
if ($migration->path != '') {
// q: what if we have a loader which does not work with is_file? We could probably remove this check...
if (is_file($migration->path)) {
try {
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migration->path));
if (count($migrationDefinitionCollection)) {
$migrationDefinition = reset($migrationDefinitionCollection);
$migrationDefinition = $migrationService->parseMigrationDefinition($migrationDefinition);
if ($migrationDefinition->status != MigrationDefinition::STATUS_PARSED) {
$output->writeln('Definition error: <error>' . $migrationDefinition->parsingError . '</error>');
}
if (md5($migrationDefinition->rawDefinition) != $migration->md5) {
$output->writeln('Notes: <comment>The migration definition file has now a different checksum</comment>');
}
} else {
$output->writeln('Definition error: <error>The migration definition file can not be loaded</error>');
}
} catch (\Exception $e) {
/// @todo one day we should be able to limit the kind of exceptions we have to catch here...
$output->writeln('Definition parsing error: <error>' . $e->getMessage() . '</error>');
}
} else {
$output->writeln('Definition error: <error>The migration definition file can not be found any more</error>');
}
}
$output->writeln('');
return 0;
}
// ask user for confirmation to make changes
if ($input->isInteractive() && !$input->getOption('no-interaction')) {
$dialog = $this->getHelperSet()->get('question');
if (!$dialog->ask(
$input,
$output,
new ConfirmationQuestion('<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>', false)
)
) {
$output->writeln('<error>Migration change cancelled!</error>');
return 0;
}
}
if ($input->getOption('add')) {
// will throw if a file is passed and it is not found, but not if an empty dir is passed
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migrationNameOrPath));
if (!count($migrationDefinitionCollection))
{
throw new \InvalidArgumentException(sprintf('The path "%s" does not correspond to any migration definition.', $migrationNameOrPath));
}
foreach ($migrationDefinitionCollection as $migrationDefinition) {
$migrationName = basename($migrationDefinition->path);
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration != null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does already exist in the migrations table.', $migrationName));
}
$migrationService->addMigration($migrationDefinition);
$output->writeln('<info>Added migration' . $migrationDefinition->path . '</info>');
}
return 0;
}
if ($input->getOption('delete')) {
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration == null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does not exist in the migrations table.', $migrationNameOrPath));
}
$migrationService->deleteMigration($migration);
return 0;
}
if ($input->getOption('skip')) {
// will throw if a file is passed and it is not found, but not if an empty dir is passed
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migrationNameOrPath));
if (!count($migrationDefinitionCollection))
{
throw new \InvalidArgumentException(sprintf('The path "%s" does not correspond to any migration definition.', $migrationNameOrPath));
}
foreach ($migrationDefinitionCollection as $migrationDefinition) {
$migrationService->skipMigration($migrationDefinition);
$output->writeln('<info>Migration' . $migrationDefinition->path . ' marked as skipped</info>');
}
return 0;
}
throw new \InvalidArgumentException("Please specify one action to be taken on the given migration");
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setOutput($output);
$this->setVerbosity($output->getVerbosity());
if (!$input->getOption('add') && !$input->getOption('delete') && !$input->getOption('skip') && !$input->getOption('info')) {
throw new \InvalidArgumentException('You must specify whether you want to --add, --delete, --skip or --info the specified migration.');
}
$migrationService = $this->getMigrationService();
$migrationNameOrPath = $input->getArgument('migration');
if ($input->getOption('info')) {
$output->writeln('');
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration == null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does not exist in the migrations table.', $migrationNameOrPath));
}
switch ($migration->status) {
case Migration::STATUS_DONE:
$status = '<info>executed</info>';
break;
case Migration::STATUS_STARTED:
$status = '<comment>execution started</comment>';
break;
case Migration::STATUS_TODO:
// bold to-migrate!
$status = '<error>not executed</error>';
break;
case Migration::STATUS_SKIPPED:
$status = '<comment>skipped</comment>';
break;
case Migration::STATUS_PARTIALLY_DONE:
$status = '<comment>partially executed</comment>';
break;
case Migration::STATUS_SUSPENDED:
$status = '<comment>suspended</comment>';
break;
case Migration::STATUS_FAILED:
$status = '<error>failed</error>';
break;
}
$output->writeln('<info>Migration: ' . $migration->name . '</info>');
$output->writeln('Status: ' . $status);
$output->writeln('Executed on: <info>' . ($migration->executionDate != null ? date("Y-m-d H:i:s", $migration->executionDate) : '--'). '</info>');
$output->writeln('Execution notes: <info>' . $migration->executionError . '</info>');
if ($migration->status == Migration::STATUS_SUSPENDED) {
/// @todo decode the suspension context: date, step, ...
}
$output->writeln('Definition path: <info>' . $migration->path . '</info>');
$output->writeln('Definition md5: <info>' . $migration->md5 . '</info>');
if ($migration->path != '') {
// q: what if we have a loader which does not work with is_file? We could probably remove this check...
if (is_file($migration->path)) {
try {
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migration->path));
if (count($migrationDefinitionCollection)) {
$migrationDefinition = reset($migrationDefinitionCollection);
$migrationDefinition = $migrationService->parseMigrationDefinition($migrationDefinition);
if ($migrationDefinition->status != MigrationDefinition::STATUS_PARSED) {
$output->writeln('Definition error: <error>' . $migrationDefinition->parsingError . '</error>');
}
if (md5($migrationDefinition->rawDefinition) != $migration->md5) {
$output->writeln('Notes: <comment>The migration definition file has now a different checksum</comment>');
}
} else {
$output->writeln('Definition error: <error>The migration definition file can not be loaded</error>');
}
} catch (\Exception $e) {
/// @todo one day we should be able to limit the kind of exceptions we have to catch here...
$output->writeln('Definition parsing error: <error>' . $e->getMessage() . '</error>');
}
} else {
$output->writeln('Definition error: <error>The migration definition file can not be found any more</error>');
}
}
$output->writeln('');
return 0;
}
// ask user for confirmation to make changes
if ($input->isInteractive() && !$input->getOption('no-interaction')) {
$dialog = $this->getHelperSet()->get('question');
if (!$dialog->ask(
$input,
$output,
new ConfirmationQuestion('<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>', false)
)
) {
$output->writeln('<error>Migration change cancelled!</error>');
return 0;
}
}
if ($input->getOption('add')) {
// will throw if a file is passed and it is not found, but not if an empty dir is passed
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migrationNameOrPath));
if (!count($migrationDefinitionCollection))
{
throw new \InvalidArgumentException(sprintf('The path "%s" does not correspond to any migration definition.', $migrationNameOrPath));
}
foreach ($migrationDefinitionCollection as $migrationDefinition) {
$migrationName = basename($migrationDefinition->path);
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration != null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does already exist in the migrations table.', $migrationName));
}
$migrationService->addMigration($migrationDefinition);
$output->writeln('<info>Added migration' . $migrationDefinition->path . '</info>');
}
return 0;
}
if ($input->getOption('delete')) {
$migration = $migrationService->getMigration($migrationNameOrPath);
if ($migration == null) {
throw new \InvalidArgumentException(sprintf('The migration "%s" does not exist in the migrations table.', $migrationNameOrPath));
}
$migrationService->deleteMigration($migration);
return 0;
}
if ($input->getOption('skip')) {
// will throw if a file is passed and it is not found, but not if an empty dir is passed
$migrationDefinitionCollection = $migrationService->getMigrationsDefinitions(array($migrationNameOrPath));
if (!count($migrationDefinitionCollection))
{
throw new \InvalidArgumentException(sprintf('The path "%s" does not correspond to any migration definition.', $migrationNameOrPath));
}
foreach ($migrationDefinitionCollection as $migrationDefinition) {
$migrationService->skipMigration($migrationDefinition);
$output->writeln('<info>Migration' . $migrationDefinition->path . ' marked as skipped</info>');
}
return 0;
}
throw new \InvalidArgumentException("Please specify one action to be taken on the given migration");
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"setOutput",
"(",
"$",
"output",
")",
";",
"$",
"this",
"->",
"setVerbosity",
"(",
"$",
"output",
"->",
"getVerbosity",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'add'",
")",
"&&",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'delete'",
")",
"&&",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'skip'",
")",
"&&",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'info'",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'You must specify whether you want to --add, --delete, --skip or --info the specified migration.'",
")",
";",
"}",
"$",
"migrationService",
"=",
"$",
"this",
"->",
"getMigrationService",
"(",
")",
";",
"$",
"migrationNameOrPath",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'migration'",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'info'",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"migration",
"=",
"$",
"migrationService",
"->",
"getMigration",
"(",
"$",
"migrationNameOrPath",
")",
";",
"if",
"(",
"$",
"migration",
"==",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The migration \"%s\" does not exist in the migrations table.'",
",",
"$",
"migrationNameOrPath",
")",
")",
";",
"}",
"switch",
"(",
"$",
"migration",
"->",
"status",
")",
"{",
"case",
"Migration",
"::",
"STATUS_DONE",
":",
"$",
"status",
"=",
"'<info>executed</info>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_STARTED",
":",
"$",
"status",
"=",
"'<comment>execution started</comment>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_TODO",
":",
"// bold to-migrate!",
"$",
"status",
"=",
"'<error>not executed</error>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_SKIPPED",
":",
"$",
"status",
"=",
"'<comment>skipped</comment>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_PARTIALLY_DONE",
":",
"$",
"status",
"=",
"'<comment>partially executed</comment>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_SUSPENDED",
":",
"$",
"status",
"=",
"'<comment>suspended</comment>'",
";",
"break",
";",
"case",
"Migration",
"::",
"STATUS_FAILED",
":",
"$",
"status",
"=",
"'<error>failed</error>'",
";",
"break",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Migration: '",
".",
"$",
"migration",
"->",
"name",
".",
"'</info>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Status: '",
".",
"$",
"status",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Executed on: <info>'",
".",
"(",
"$",
"migration",
"->",
"executionDate",
"!=",
"null",
"?",
"date",
"(",
"\"Y-m-d H:i:s\"",
",",
"$",
"migration",
"->",
"executionDate",
")",
":",
"'--'",
")",
".",
"'</info>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Execution notes: <info>'",
".",
"$",
"migration",
"->",
"executionError",
".",
"'</info>'",
")",
";",
"if",
"(",
"$",
"migration",
"->",
"status",
"==",
"Migration",
"::",
"STATUS_SUSPENDED",
")",
"{",
"/// @todo decode the suspension context: date, step, ...",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'Definition path: <info>'",
".",
"$",
"migration",
"->",
"path",
".",
"'</info>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'Definition md5: <info>'",
".",
"$",
"migration",
"->",
"md5",
".",
"'</info>'",
")",
";",
"if",
"(",
"$",
"migration",
"->",
"path",
"!=",
"''",
")",
"{",
"// q: what if we have a loader which does not work with is_file? We could probably remove this check...",
"if",
"(",
"is_file",
"(",
"$",
"migration",
"->",
"path",
")",
")",
"{",
"try",
"{",
"$",
"migrationDefinitionCollection",
"=",
"$",
"migrationService",
"->",
"getMigrationsDefinitions",
"(",
"array",
"(",
"$",
"migration",
"->",
"path",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"migrationDefinitionCollection",
")",
")",
"{",
"$",
"migrationDefinition",
"=",
"reset",
"(",
"$",
"migrationDefinitionCollection",
")",
";",
"$",
"migrationDefinition",
"=",
"$",
"migrationService",
"->",
"parseMigrationDefinition",
"(",
"$",
"migrationDefinition",
")",
";",
"if",
"(",
"$",
"migrationDefinition",
"->",
"status",
"!=",
"MigrationDefinition",
"::",
"STATUS_PARSED",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Definition error: <error>'",
".",
"$",
"migrationDefinition",
"->",
"parsingError",
".",
"'</error>'",
")",
";",
"}",
"if",
"(",
"md5",
"(",
"$",
"migrationDefinition",
"->",
"rawDefinition",
")",
"!=",
"$",
"migration",
"->",
"md5",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Notes: <comment>The migration definition file has now a different checksum</comment>'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Definition error: <error>The migration definition file can not be loaded</error>'",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"/// @todo one day we should be able to limit the kind of exceptions we have to catch here...",
"$",
"output",
"->",
"writeln",
"(",
"'Definition parsing error: <error>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</error>'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Definition error: <error>The migration definition file can not be found any more</error>'",
")",
";",
"}",
"}",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"return",
"0",
";",
"}",
"// ask user for confirmation to make changes",
"if",
"(",
"$",
"input",
"->",
"isInteractive",
"(",
")",
"&&",
"!",
"$",
"input",
"->",
"getOption",
"(",
"'no-interaction'",
")",
")",
"{",
"$",
"dialog",
"=",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'question'",
")",
";",
"if",
"(",
"!",
"$",
"dialog",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"new",
"ConfirmationQuestion",
"(",
"'<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>'",
",",
"false",
")",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<error>Migration change cancelled!</error>'",
")",
";",
"return",
"0",
";",
"}",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'add'",
")",
")",
"{",
"// will throw if a file is passed and it is not found, but not if an empty dir is passed",
"$",
"migrationDefinitionCollection",
"=",
"$",
"migrationService",
"->",
"getMigrationsDefinitions",
"(",
"array",
"(",
"$",
"migrationNameOrPath",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"migrationDefinitionCollection",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The path \"%s\" does not correspond to any migration definition.'",
",",
"$",
"migrationNameOrPath",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"migrationDefinitionCollection",
"as",
"$",
"migrationDefinition",
")",
"{",
"$",
"migrationName",
"=",
"basename",
"(",
"$",
"migrationDefinition",
"->",
"path",
")",
";",
"$",
"migration",
"=",
"$",
"migrationService",
"->",
"getMigration",
"(",
"$",
"migrationNameOrPath",
")",
";",
"if",
"(",
"$",
"migration",
"!=",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The migration \"%s\" does already exist in the migrations table.'",
",",
"$",
"migrationName",
")",
")",
";",
"}",
"$",
"migrationService",
"->",
"addMigration",
"(",
"$",
"migrationDefinition",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Added migration'",
".",
"$",
"migrationDefinition",
"->",
"path",
".",
"'</info>'",
")",
";",
"}",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'delete'",
")",
")",
"{",
"$",
"migration",
"=",
"$",
"migrationService",
"->",
"getMigration",
"(",
"$",
"migrationNameOrPath",
")",
";",
"if",
"(",
"$",
"migration",
"==",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The migration \"%s\" does not exist in the migrations table.'",
",",
"$",
"migrationNameOrPath",
")",
")",
";",
"}",
"$",
"migrationService",
"->",
"deleteMigration",
"(",
"$",
"migration",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'skip'",
")",
")",
"{",
"// will throw if a file is passed and it is not found, but not if an empty dir is passed",
"$",
"migrationDefinitionCollection",
"=",
"$",
"migrationService",
"->",
"getMigrationsDefinitions",
"(",
"array",
"(",
"$",
"migrationNameOrPath",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"migrationDefinitionCollection",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The path \"%s\" does not correspond to any migration definition.'",
",",
"$",
"migrationNameOrPath",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"migrationDefinitionCollection",
"as",
"$",
"migrationDefinition",
")",
"{",
"$",
"migrationService",
"->",
"skipMigration",
"(",
"$",
"migrationDefinition",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Migration'",
".",
"$",
"migrationDefinition",
"->",
"path",
".",
"' marked as skipped</info>'",
")",
";",
"}",
"return",
"0",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Please specify one action to be taken on the given migration\"",
")",
";",
"}"
] | Execute the command.
@param InputInterface $input
@param OutputInterface $output
@return null|int null or 0 if everything went fine, or an error code | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Command/MigrationCommand.php#L55-L211 |
kaliop-uk/ezmigrationbundle | Core/Executor/UserManager.php | UserManager.create | protected function create($step)
{
if (!isset($step->dsl['groups'])) {
throw new \Exception('No user groups set to create user in.');
}
if (!is_array($step->dsl['groups'])) {
$step->dsl['groups'] = array($step->dsl['groups']);
}
$userService = $this->repository->getUserService();
$contentTypeService = $this->repository->getContentTypeService();
$userGroups = array();
foreach ($step->dsl['groups'] as $groupId) {
$groupId = $this->referenceResolver->resolveReference($groupId);
$userGroup = $this->userGroupMatcher->matchOneByKey($groupId);
// q: in which case can we have no group? And should we throw an exception?
//if ($userGroup) {
$userGroups[] = $userGroup;
//}
}
$userContentType = $contentTypeService->loadContentTypeByIdentifier($this->getUserContentType($step));
$userCreateStruct = $userService->newUserCreateStruct(
$this->referenceResolver->resolveReference($step->dsl['username']),
$this->referenceResolver->resolveReference($step->dsl['email']),
$this->referenceResolver->resolveReference($step->dsl['password']),
$this->getLanguageCode($step),
$userContentType
);
$userCreateStruct->setField('first_name', $this->referenceResolver->resolveReference($step->dsl['first_name']));
$userCreateStruct->setField('last_name', $this->referenceResolver->resolveReference($step->dsl['last_name']));
// Create the user
$user = $userService->createUser($userCreateStruct, $userGroups);
$this->setReferences($user, $step);
return $user;
} | php | protected function create($step)
{
if (!isset($step->dsl['groups'])) {
throw new \Exception('No user groups set to create user in.');
}
if (!is_array($step->dsl['groups'])) {
$step->dsl['groups'] = array($step->dsl['groups']);
}
$userService = $this->repository->getUserService();
$contentTypeService = $this->repository->getContentTypeService();
$userGroups = array();
foreach ($step->dsl['groups'] as $groupId) {
$groupId = $this->referenceResolver->resolveReference($groupId);
$userGroup = $this->userGroupMatcher->matchOneByKey($groupId);
// q: in which case can we have no group? And should we throw an exception?
//if ($userGroup) {
$userGroups[] = $userGroup;
//}
}
$userContentType = $contentTypeService->loadContentTypeByIdentifier($this->getUserContentType($step));
$userCreateStruct = $userService->newUserCreateStruct(
$this->referenceResolver->resolveReference($step->dsl['username']),
$this->referenceResolver->resolveReference($step->dsl['email']),
$this->referenceResolver->resolveReference($step->dsl['password']),
$this->getLanguageCode($step),
$userContentType
);
$userCreateStruct->setField('first_name', $this->referenceResolver->resolveReference($step->dsl['first_name']));
$userCreateStruct->setField('last_name', $this->referenceResolver->resolveReference($step->dsl['last_name']));
// Create the user
$user = $userService->createUser($userCreateStruct, $userGroups);
$this->setReferences($user, $step);
return $user;
} | [
"protected",
"function",
"create",
"(",
"$",
"step",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'No user groups set to create user in.'",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
")",
")",
"{",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
"=",
"array",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
")",
";",
"}",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"$",
"contentTypeService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getContentTypeService",
"(",
")",
";",
"$",
"userGroups",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
"as",
"$",
"groupId",
")",
"{",
"$",
"groupId",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"groupId",
")",
";",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"userGroupMatcher",
"->",
"matchOneByKey",
"(",
"$",
"groupId",
")",
";",
"// q: in which case can we have no group? And should we throw an exception?",
"//if ($userGroup) {",
"$",
"userGroups",
"[",
"]",
"=",
"$",
"userGroup",
";",
"//}",
"}",
"$",
"userContentType",
"=",
"$",
"contentTypeService",
"->",
"loadContentTypeByIdentifier",
"(",
"$",
"this",
"->",
"getUserContentType",
"(",
"$",
"step",
")",
")",
";",
"$",
"userCreateStruct",
"=",
"$",
"userService",
"->",
"newUserCreateStruct",
"(",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'username'",
"]",
")",
",",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'email'",
"]",
")",
",",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'password'",
"]",
")",
",",
"$",
"this",
"->",
"getLanguageCode",
"(",
"$",
"step",
")",
",",
"$",
"userContentType",
")",
";",
"$",
"userCreateStruct",
"->",
"setField",
"(",
"'first_name'",
",",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'first_name'",
"]",
")",
")",
";",
"$",
"userCreateStruct",
"->",
"setField",
"(",
"'last_name'",
",",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'last_name'",
"]",
")",
")",
";",
"// Create the user",
"$",
"user",
"=",
"$",
"userService",
"->",
"createUser",
"(",
"$",
"userCreateStruct",
",",
"$",
"userGroups",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"user",
",",
"$",
"step",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Creates a user based on the DSL instructions.
@todo allow setting extra profile attributes! | [
"Creates",
"a",
"user",
"based",
"on",
"the",
"DSL",
"instructions",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/UserManager.php#L33-L75 |
kaliop-uk/ezmigrationbundle | Core/Executor/UserManager.php | UserManager.update | protected function update($step)
{
$userCollection = $this->matchUsers('user', $step);
if (count($userCollection) > 1 && isset($step->dsl['references'])) {
throw new \Exception("Can not execute User update because multiple users match, and a references section is specified in the dsl. References can be set when only 1 user matches");
}
if (count($userCollection) > 1 && isset($step->dsl['email'])) {
throw new \Exception("Can not execute User update because multiple users match, and an email section is specified in the dsl.");
}
$userService = $this->repository->getUserService();
foreach ($userCollection as $key => $user) {
$userUpdateStruct = $userService->newUserUpdateStruct();
if (isset($step->dsl['email'])) {
$userUpdateStruct->email = $this->referenceResolver->resolveReference($step->dsl['email']);
}
if (isset($step->dsl['password'])) {
$userUpdateStruct->password = (string)$this->referenceResolver->resolveReference($step->dsl['password']);
}
if (isset($step->dsl['enabled'])) {
$userUpdateStruct->enabled = $this->referenceResolver->resolveReference($step->dsl['enabled']);
}
$user = $userService->updateUser($user, $userUpdateStruct);
if (isset($step->dsl['groups'])) {
$groups = $step->dsl['groups'];
if (!is_array($groups)) {
$groups = array($groups);
}
$assignedGroups = $userService->loadUserGroupsOfUser($user);
$targetGroupIds = [];
// Assigning new groups to the user
foreach ($groups as $groupToAssignId) {
$groupId = $this->referenceResolver->resolveReference($groupToAssignId);
$groupToAssign = $this->userGroupMatcher->matchOneByKey($groupId);
$targetGroupIds[] = $groupToAssign->id;
$present = false;
foreach ($assignedGroups as $assignedGroup) {
// Make sure we assign the user only to groups he isn't already assigned to
if ($assignedGroup->id == $groupToAssign->id) {
$present = true;
break;
}
}
if (!$present) {
$userService->assignUserToUserGroup($user, $groupToAssign);
}
}
// Unassigning groups that are not in the list in the migration
foreach ($assignedGroups as $assignedGroup) {
if (!in_array($assignedGroup->id, $targetGroupIds)) {
$userService->unAssignUserFromUserGroup($user, $assignedGroup);
}
}
}
$userCollection[$key] = $user;
}
$this->setReferences($userCollection, $step);
return $userCollection;
} | php | protected function update($step)
{
$userCollection = $this->matchUsers('user', $step);
if (count($userCollection) > 1 && isset($step->dsl['references'])) {
throw new \Exception("Can not execute User update because multiple users match, and a references section is specified in the dsl. References can be set when only 1 user matches");
}
if (count($userCollection) > 1 && isset($step->dsl['email'])) {
throw new \Exception("Can not execute User update because multiple users match, and an email section is specified in the dsl.");
}
$userService = $this->repository->getUserService();
foreach ($userCollection as $key => $user) {
$userUpdateStruct = $userService->newUserUpdateStruct();
if (isset($step->dsl['email'])) {
$userUpdateStruct->email = $this->referenceResolver->resolveReference($step->dsl['email']);
}
if (isset($step->dsl['password'])) {
$userUpdateStruct->password = (string)$this->referenceResolver->resolveReference($step->dsl['password']);
}
if (isset($step->dsl['enabled'])) {
$userUpdateStruct->enabled = $this->referenceResolver->resolveReference($step->dsl['enabled']);
}
$user = $userService->updateUser($user, $userUpdateStruct);
if (isset($step->dsl['groups'])) {
$groups = $step->dsl['groups'];
if (!is_array($groups)) {
$groups = array($groups);
}
$assignedGroups = $userService->loadUserGroupsOfUser($user);
$targetGroupIds = [];
// Assigning new groups to the user
foreach ($groups as $groupToAssignId) {
$groupId = $this->referenceResolver->resolveReference($groupToAssignId);
$groupToAssign = $this->userGroupMatcher->matchOneByKey($groupId);
$targetGroupIds[] = $groupToAssign->id;
$present = false;
foreach ($assignedGroups as $assignedGroup) {
// Make sure we assign the user only to groups he isn't already assigned to
if ($assignedGroup->id == $groupToAssign->id) {
$present = true;
break;
}
}
if (!$present) {
$userService->assignUserToUserGroup($user, $groupToAssign);
}
}
// Unassigning groups that are not in the list in the migration
foreach ($assignedGroups as $assignedGroup) {
if (!in_array($assignedGroup->id, $targetGroupIds)) {
$userService->unAssignUserFromUserGroup($user, $assignedGroup);
}
}
}
$userCollection[$key] = $user;
}
$this->setReferences($userCollection, $step);
return $userCollection;
} | [
"protected",
"function",
"update",
"(",
"$",
"step",
")",
"{",
"$",
"userCollection",
"=",
"$",
"this",
"->",
"matchUsers",
"(",
"'user'",
",",
"$",
"step",
")",
";",
"if",
"(",
"count",
"(",
"$",
"userCollection",
")",
">",
"1",
"&&",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'references'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute User update because multiple users match, and a references section is specified in the dsl. References can be set when only 1 user matches\"",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"userCollection",
")",
">",
"1",
"&&",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'email'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not execute User update because multiple users match, and an email section is specified in the dsl.\"",
")",
";",
"}",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"foreach",
"(",
"$",
"userCollection",
"as",
"$",
"key",
"=>",
"$",
"user",
")",
"{",
"$",
"userUpdateStruct",
"=",
"$",
"userService",
"->",
"newUserUpdateStruct",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"userUpdateStruct",
"->",
"email",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'email'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"userUpdateStruct",
"->",
"password",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'password'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'enabled'",
"]",
")",
")",
"{",
"$",
"userUpdateStruct",
"->",
"enabled",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'enabled'",
"]",
")",
";",
"}",
"$",
"user",
"=",
"$",
"userService",
"->",
"updateUser",
"(",
"$",
"user",
",",
"$",
"userUpdateStruct",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
")",
")",
"{",
"$",
"groups",
"=",
"$",
"step",
"->",
"dsl",
"[",
"'groups'",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groups",
")",
")",
"{",
"$",
"groups",
"=",
"array",
"(",
"$",
"groups",
")",
";",
"}",
"$",
"assignedGroups",
"=",
"$",
"userService",
"->",
"loadUserGroupsOfUser",
"(",
"$",
"user",
")",
";",
"$",
"targetGroupIds",
"=",
"[",
"]",
";",
"// Assigning new groups to the user",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"groupToAssignId",
")",
"{",
"$",
"groupId",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"groupToAssignId",
")",
";",
"$",
"groupToAssign",
"=",
"$",
"this",
"->",
"userGroupMatcher",
"->",
"matchOneByKey",
"(",
"$",
"groupId",
")",
";",
"$",
"targetGroupIds",
"[",
"]",
"=",
"$",
"groupToAssign",
"->",
"id",
";",
"$",
"present",
"=",
"false",
";",
"foreach",
"(",
"$",
"assignedGroups",
"as",
"$",
"assignedGroup",
")",
"{",
"// Make sure we assign the user only to groups he isn't already assigned to",
"if",
"(",
"$",
"assignedGroup",
"->",
"id",
"==",
"$",
"groupToAssign",
"->",
"id",
")",
"{",
"$",
"present",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"present",
")",
"{",
"$",
"userService",
"->",
"assignUserToUserGroup",
"(",
"$",
"user",
",",
"$",
"groupToAssign",
")",
";",
"}",
"}",
"// Unassigning groups that are not in the list in the migration",
"foreach",
"(",
"$",
"assignedGroups",
"as",
"$",
"assignedGroup",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"assignedGroup",
"->",
"id",
",",
"$",
"targetGroupIds",
")",
")",
"{",
"$",
"userService",
"->",
"unAssignUserFromUserGroup",
"(",
"$",
"user",
",",
"$",
"assignedGroup",
")",
";",
"}",
"}",
"}",
"$",
"userCollection",
"[",
"$",
"key",
"]",
"=",
"$",
"user",
";",
"}",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"userCollection",
",",
"$",
"step",
")",
";",
"return",
"$",
"userCollection",
";",
"}"
] | Method to handle the update operation of the migration instructions
@todo allow setting extra profile attributes! | [
"Method",
"to",
"handle",
"the",
"update",
"operation",
"of",
"the",
"migration",
"instructions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/UserManager.php#L91-L164 |
kaliop-uk/ezmigrationbundle | Core/Executor/UserManager.php | UserManager.delete | protected function delete($step)
{
$userCollection = $this->matchUsers('delete', $step);
$this->setReferences($userCollection, $step);
$userService = $this->repository->getUserService();
foreach ($userCollection as $user) {
$userService->deleteUser($user);
}
return $userCollection;
} | php | protected function delete($step)
{
$userCollection = $this->matchUsers('delete', $step);
$this->setReferences($userCollection, $step);
$userService = $this->repository->getUserService();
foreach ($userCollection as $user) {
$userService->deleteUser($user);
}
return $userCollection;
} | [
"protected",
"function",
"delete",
"(",
"$",
"step",
")",
"{",
"$",
"userCollection",
"=",
"$",
"this",
"->",
"matchUsers",
"(",
"'delete'",
",",
"$",
"step",
")",
";",
"$",
"this",
"->",
"setReferences",
"(",
"$",
"userCollection",
",",
"$",
"step",
")",
";",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"foreach",
"(",
"$",
"userCollection",
"as",
"$",
"user",
")",
"{",
"$",
"userService",
"->",
"deleteUser",
"(",
"$",
"user",
")",
";",
"}",
"return",
"$",
"userCollection",
";",
"}"
] | Method to handle the delete operation of the migration instructions | [
"Method",
"to",
"handle",
"the",
"delete",
"operation",
"of",
"the",
"migration",
"instructions"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/UserManager.php#L169-L182 |
kaliop-uk/ezmigrationbundle | Core/Executor/UserManager.php | UserManager.getReferencesValues | protected function getReferencesValues($user, array $references, $step)
{
$refs = array();
foreach ($references as $reference) {
switch ($reference['attribute']) {
case 'user_id':
case 'id':
$value = $user->id;
break;
case 'email':
$value = $user->email;
break;
case 'enabled':
$value = $user->enabled;
break;
case 'login':
$value = $user->login;
break;
case 'groups_ids':
$value = [];
$userService = $this->repository->getUserService();
$userGroups = $userService->loadUserGroupsOfUser($user);
foreach ($userGroups as $userGroup) {
$value[] = $userGroup->id;
}
break;
default:
throw new \InvalidArgumentException('User Manager does not support setting references for attribute ' . $reference['attribute']);
}
$refs[$reference['identifier']] = $value;
}
return $refs;
} | php | protected function getReferencesValues($user, array $references, $step)
{
$refs = array();
foreach ($references as $reference) {
switch ($reference['attribute']) {
case 'user_id':
case 'id':
$value = $user->id;
break;
case 'email':
$value = $user->email;
break;
case 'enabled':
$value = $user->enabled;
break;
case 'login':
$value = $user->login;
break;
case 'groups_ids':
$value = [];
$userService = $this->repository->getUserService();
$userGroups = $userService->loadUserGroupsOfUser($user);
foreach ($userGroups as $userGroup) {
$value[] = $userGroup->id;
}
break;
default:
throw new \InvalidArgumentException('User Manager does not support setting references for attribute ' . $reference['attribute']);
}
$refs[$reference['identifier']] = $value;
}
return $refs;
} | [
"protected",
"function",
"getReferencesValues",
"(",
"$",
"user",
",",
"array",
"$",
"references",
",",
"$",
"step",
")",
"{",
"$",
"refs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"references",
"as",
"$",
"reference",
")",
"{",
"switch",
"(",
"$",
"reference",
"[",
"'attribute'",
"]",
")",
"{",
"case",
"'user_id'",
":",
"case",
"'id'",
":",
"$",
"value",
"=",
"$",
"user",
"->",
"id",
";",
"break",
";",
"case",
"'email'",
":",
"$",
"value",
"=",
"$",
"user",
"->",
"email",
";",
"break",
";",
"case",
"'enabled'",
":",
"$",
"value",
"=",
"$",
"user",
"->",
"enabled",
";",
"break",
";",
"case",
"'login'",
":",
"$",
"value",
"=",
"$",
"user",
"->",
"login",
";",
"break",
";",
"case",
"'groups_ids'",
":",
"$",
"value",
"=",
"[",
"]",
";",
"$",
"userService",
"=",
"$",
"this",
"->",
"repository",
"->",
"getUserService",
"(",
")",
";",
"$",
"userGroups",
"=",
"$",
"userService",
"->",
"loadUserGroupsOfUser",
"(",
"$",
"user",
")",
";",
"foreach",
"(",
"$",
"userGroups",
"as",
"$",
"userGroup",
")",
"{",
"$",
"value",
"[",
"]",
"=",
"$",
"userGroup",
"->",
"id",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'User Manager does not support setting references for attribute '",
".",
"$",
"reference",
"[",
"'attribute'",
"]",
")",
";",
"}",
"$",
"refs",
"[",
"$",
"reference",
"[",
"'identifier'",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"refs",
";",
"}"
] | @param User $user
@param array $references the definitions of the references to set
@throws \InvalidArgumentException When trying to assign a reference to an unsupported attribute
@return array key: the reference names, values: the reference values
@todo allow setting refs to all the attributes that can be gotten for Contents | [
"@param",
"User",
"$user",
"@param",
"array",
"$references",
"the",
"definitions",
"of",
"the",
"references",
"to",
"set",
"@throws",
"\\",
"InvalidArgumentException",
"When",
"trying",
"to",
"assign",
"a",
"reference",
"to",
"an",
"unsupported",
"attribute",
"@return",
"array",
"key",
":",
"the",
"reference",
"names",
"values",
":",
"the",
"reference",
"values"
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/Executor/UserManager.php#L229-L265 |
kaliop-uk/ezmigrationbundle | Core/ReferenceResolver/ChainPrefixResolver.php | ChainPrefixResolver.getRegexp | public function getRegexp()
{
$regexps = array();
/** @var PrefixBasedResolverInterface $resolver */
foreach ($this->resolvers as $resolver) {
$regexp = preg_replace('/^\^/', '', substr($resolver->getRegexp(), 1, -1));
if ($regexp !== '') {
$regexps[] = $regexp;
}
}
return '/^(' . implode('|', $regexps) . ')/';
} | php | public function getRegexp()
{
$regexps = array();
/** @var PrefixBasedResolverInterface $resolver */
foreach ($this->resolvers as $resolver) {
$regexp = preg_replace('/^\^/', '', substr($resolver->getRegexp(), 1, -1));
if ($regexp !== '') {
$regexps[] = $regexp;
}
}
return '/^(' . implode('|', $regexps) . ')/';
} | [
"public",
"function",
"getRegexp",
"(",
")",
"{",
"$",
"regexps",
"=",
"array",
"(",
")",
";",
"/** @var PrefixBasedResolverInterface $resolver */",
"foreach",
"(",
"$",
"this",
"->",
"resolvers",
"as",
"$",
"resolver",
")",
"{",
"$",
"regexp",
"=",
"preg_replace",
"(",
"'/^\\^/'",
",",
"''",
",",
"substr",
"(",
"$",
"resolver",
"->",
"getRegexp",
"(",
")",
",",
"1",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"$",
"regexp",
"!==",
"''",
")",
"{",
"$",
"regexps",
"[",
"]",
"=",
"$",
"regexp",
";",
"}",
"}",
"return",
"'/^('",
".",
"implode",
"(",
"'|'",
",",
"$",
"regexps",
")",
".",
"')/'",
";",
"}"
] | NB: assumes that all the resolvers we chain use '/' as delimiter...
@return string | [
"NB",
":",
"assumes",
"that",
"all",
"the",
"resolvers",
"we",
"chain",
"use",
"/",
"as",
"delimiter",
"..."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/ReferenceResolver/ChainPrefixResolver.php#L22-L33 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzRelation.php | EzRelation.hashToFieldValue | public function hashToFieldValue($fieldValue, array $context = array())
{
if (is_array($fieldValue) && array_key_exists('destinationContentId', $fieldValue)) {
// fromHash format
$id = $fieldValue['destinationContentId'];
} else {
// simplified format
$id = $fieldValue;
}
if ($id === null) {
return new Value();
}
// 1. resolve relations
$id = $this->referenceResolver->resolveReference($id);
// 2. resolve remote ids
$id = $this->contentMatcher->matchOneByKey($id)->id;
return new Value($id);
} | php | public function hashToFieldValue($fieldValue, array $context = array())
{
if (is_array($fieldValue) && array_key_exists('destinationContentId', $fieldValue)) {
// fromHash format
$id = $fieldValue['destinationContentId'];
} else {
// simplified format
$id = $fieldValue;
}
if ($id === null) {
return new Value();
}
// 1. resolve relations
$id = $this->referenceResolver->resolveReference($id);
// 2. resolve remote ids
$id = $this->contentMatcher->matchOneByKey($id)->id;
return new Value($id);
} | [
"public",
"function",
"hashToFieldValue",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fieldValue",
")",
"&&",
"array_key_exists",
"(",
"'destinationContentId'",
",",
"$",
"fieldValue",
")",
")",
"{",
"// fromHash format",
"$",
"id",
"=",
"$",
"fieldValue",
"[",
"'destinationContentId'",
"]",
";",
"}",
"else",
"{",
"// simplified format",
"$",
"id",
"=",
"$",
"fieldValue",
";",
"}",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"return",
"new",
"Value",
"(",
")",
";",
"}",
"// 1. resolve relations",
"$",
"id",
"=",
"$",
"this",
"->",
"referenceResolver",
"->",
"resolveReference",
"(",
"$",
"id",
")",
";",
"// 2. resolve remote ids",
"$",
"id",
"=",
"$",
"this",
"->",
"contentMatcher",
"->",
"matchOneByKey",
"(",
"$",
"id",
")",
"->",
"id",
";",
"return",
"new",
"Value",
"(",
"$",
"id",
")",
";",
"}"
] | Creates a value object to use as the field value when setting an ez relation field type.
@param array|string|int $fieldValue The definition of the field value, structured in the yml file
@param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
@return Value | [
"Creates",
"a",
"value",
"object",
"to",
"use",
"as",
"the",
"field",
"value",
"when",
"setting",
"an",
"ez",
"relation",
"field",
"type",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzRelation.php#L26-L46 |
kaliop-uk/ezmigrationbundle | Core/FieldHandler/EzMedia.php | EzMedia.hashToFieldValue | public function hashToFieldValue($fieldValue, array $context = array())
{
$fileName = '';
$mimeType = '';
$hasController = false;
$autoPlay = false;
$loop = false;
$height = 0;
$width = 0;
if ($fieldValue === null) {
return new MediaValue();
} else if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
// BC
if (isset($fieldValue['fileName'])) {
$fileName = $fieldValue['fileName'];
}
if (isset($fieldValue['mimeType'])) {
$fileName = $fieldValue['mimeType'];
}
if (isset($fieldValue['hasController'])) {
$hasController = $fieldValue['hasController'];
}
if (isset($fieldValue['inputUri'])) {
$filePath = $fieldValue['inputUri'];
} else {
$filePath = $fieldValue['path'];
}
// new attribute names
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
if (isset($fieldValue['has_controller'])) {
$hasController = $fieldValue['has_controller'];
}
if (isset($fieldValue['autoplay'])) {
$autoPlay = $fieldValue['autoplay'];
}
if (isset($fieldValue['loop'])) {
$loop = $fieldValue['loop'];
}
if (isset($fieldValue['height'])) {
$height = $fieldValue['height'];
}
if (isset($fieldValue['width'])) {
$width = $fieldValue['width'];
}
if (isset($fieldValue['mime_type'])) {
$mimeType = $fieldValue['mime_type'];
}
}
// 'default' format: path is relative to the 'media' dir
$realFilePath = dirname($context['path']) . '/media/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new MediaValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath),
'hasController' => $hasController,
'autoplay' => $autoPlay,
'loop'=> $loop,
'height' => $height,
'width' => $width,
)
);
} | php | public function hashToFieldValue($fieldValue, array $context = array())
{
$fileName = '';
$mimeType = '';
$hasController = false;
$autoPlay = false;
$loop = false;
$height = 0;
$width = 0;
if ($fieldValue === null) {
return new MediaValue();
} else if (is_string($fieldValue)) {
$filePath = $fieldValue;
} else {
// BC
if (isset($fieldValue['fileName'])) {
$fileName = $fieldValue['fileName'];
}
if (isset($fieldValue['mimeType'])) {
$fileName = $fieldValue['mimeType'];
}
if (isset($fieldValue['hasController'])) {
$hasController = $fieldValue['hasController'];
}
if (isset($fieldValue['inputUri'])) {
$filePath = $fieldValue['inputUri'];
} else {
$filePath = $fieldValue['path'];
}
// new attribute names
if (isset($fieldValue['filename'])) {
$fileName = $fieldValue['filename'];
}
if (isset($fieldValue['has_controller'])) {
$hasController = $fieldValue['has_controller'];
}
if (isset($fieldValue['autoplay'])) {
$autoPlay = $fieldValue['autoplay'];
}
if (isset($fieldValue['loop'])) {
$loop = $fieldValue['loop'];
}
if (isset($fieldValue['height'])) {
$height = $fieldValue['height'];
}
if (isset($fieldValue['width'])) {
$width = $fieldValue['width'];
}
if (isset($fieldValue['mime_type'])) {
$mimeType = $fieldValue['mime_type'];
}
}
// 'default' format: path is relative to the 'media' dir
$realFilePath = dirname($context['path']) . '/media/' . $filePath;
// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
if (!is_file($realFilePath) && is_file($filePath)) {
$realFilePath = $filePath;
}
return new MediaValue(
array(
'path' => $realFilePath,
'fileSize' => filesize($realFilePath),
'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath),
'hasController' => $hasController,
'autoplay' => $autoPlay,
'loop'=> $loop,
'height' => $height,
'width' => $width,
)
);
} | [
"public",
"function",
"hashToFieldValue",
"(",
"$",
"fieldValue",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"fileName",
"=",
"''",
";",
"$",
"mimeType",
"=",
"''",
";",
"$",
"hasController",
"=",
"false",
";",
"$",
"autoPlay",
"=",
"false",
";",
"$",
"loop",
"=",
"false",
";",
"$",
"height",
"=",
"0",
";",
"$",
"width",
"=",
"0",
";",
"if",
"(",
"$",
"fieldValue",
"===",
"null",
")",
"{",
"return",
"new",
"MediaValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"fieldValue",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
";",
"}",
"else",
"{",
"// BC",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'fileName'",
"]",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"fieldValue",
"[",
"'fileName'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'mimeType'",
"]",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"fieldValue",
"[",
"'mimeType'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'hasController'",
"]",
")",
")",
"{",
"$",
"hasController",
"=",
"$",
"fieldValue",
"[",
"'hasController'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'inputUri'",
"]",
")",
")",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
"[",
"'inputUri'",
"]",
";",
"}",
"else",
"{",
"$",
"filePath",
"=",
"$",
"fieldValue",
"[",
"'path'",
"]",
";",
"}",
"// new attribute names",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'filename'",
"]",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"fieldValue",
"[",
"'filename'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'has_controller'",
"]",
")",
")",
"{",
"$",
"hasController",
"=",
"$",
"fieldValue",
"[",
"'has_controller'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'autoplay'",
"]",
")",
")",
"{",
"$",
"autoPlay",
"=",
"$",
"fieldValue",
"[",
"'autoplay'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'loop'",
"]",
")",
")",
"{",
"$",
"loop",
"=",
"$",
"fieldValue",
"[",
"'loop'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'height'",
"]",
")",
")",
"{",
"$",
"height",
"=",
"$",
"fieldValue",
"[",
"'height'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'width'",
"]",
")",
")",
"{",
"$",
"width",
"=",
"$",
"fieldValue",
"[",
"'width'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldValue",
"[",
"'mime_type'",
"]",
")",
")",
"{",
"$",
"mimeType",
"=",
"$",
"fieldValue",
"[",
"'mime_type'",
"]",
";",
"}",
"}",
"// 'default' format: path is relative to the 'media' dir",
"$",
"realFilePath",
"=",
"dirname",
"(",
"$",
"context",
"[",
"'path'",
"]",
")",
".",
"'/media/'",
".",
"$",
"filePath",
";",
"// but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well",
"if",
"(",
"!",
"is_file",
"(",
"$",
"realFilePath",
")",
"&&",
"is_file",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"realFilePath",
"=",
"$",
"filePath",
";",
"}",
"return",
"new",
"MediaValue",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"realFilePath",
",",
"'fileSize'",
"=>",
"filesize",
"(",
"$",
"realFilePath",
")",
",",
"'fileName'",
"=>",
"$",
"fileName",
"!=",
"''",
"?",
"$",
"fileName",
":",
"basename",
"(",
"$",
"realFilePath",
")",
",",
"'mimeType'",
"=>",
"$",
"mimeType",
"!=",
"''",
"?",
"$",
"mimeType",
":",
"mime_content_type",
"(",
"$",
"realFilePath",
")",
",",
"'hasController'",
"=>",
"$",
"hasController",
",",
"'autoplay'",
"=>",
"$",
"autoPlay",
",",
"'loop'",
"=>",
"$",
"loop",
",",
"'height'",
"=>",
"$",
"height",
",",
"'width'",
"=>",
"$",
"width",
",",
")",
")",
";",
"}"
] | Creates a value object to use as the field value when setting a media field type.
@param array|string $fieldValue The path to the file or an array with 'path' and many other keys
@param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
@return MediaValue
@todo resolve refs more | [
"Creates",
"a",
"value",
"object",
"to",
"use",
"as",
"the",
"field",
"value",
"when",
"setting",
"a",
"media",
"field",
"type",
"."
] | train | https://github.com/kaliop-uk/ezmigrationbundle/blob/7dcdcf8a204f447db41fca16463881147f3eb4d9/Core/FieldHandler/EzMedia.php#L19-L94 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.