repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.getLogger | protected function getLogger()
{
if ($this->container->has('logger')) {
$logger = $this->container->get('logger');
\assert($logger instanceof LoggerInterface);
return $logger;
}
return new NullLogger();
} | php | protected function getLogger()
{
if ($this->container->has('logger')) {
$logger = $this->container->get('logger');
\assert($logger instanceof LoggerInterface);
return $logger;
}
return new NullLogger();
} | [
"protected",
"function",
"getLogger",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"'logger'",
")",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'logger'",
")",
";",
"\\",
"assert",
"(",
"$",
"logger",
"instanceof",
"LoggerInterface",
")",
";",
"return",
"$",
"logger",
";",
"}",
"return",
"new",
"NullLogger",
"(",
")",
";",
"}"
] | Proxy for the logger service of the container.
If no such service is found, a NullLogger is returned.
@return LoggerInterface | [
"Proxy",
"for",
"the",
"logger",
"service",
"of",
"the",
"container",
".",
"If",
"no",
"such",
"service",
"is",
"found",
"a",
"NullLogger",
"is",
"returned",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1189-L1199 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.redirectToList | final protected function redirectToList()
{
$parameters = [];
if ($filter = $this->admin->getFilterParameters()) {
$parameters['filter'] = $filter;
}
return $this->redirect($this->admin->generateUrl('list', $parameters));
} | php | final protected function redirectToList()
{
$parameters = [];
if ($filter = $this->admin->getFilterParameters()) {
$parameters['filter'] = $filter;
}
return $this->redirect($this->admin->generateUrl('list', $parameters));
} | [
"final",
"protected",
"function",
"redirectToList",
"(",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"filter",
"=",
"$",
"this",
"->",
"admin",
"->",
"getFilterParameters",
"(",
")",
")",
"{",
"$",
"parameters",
"[",
"'filter'",
"]",
"=",
"$",
"filter",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"admin",
"->",
"generateUrl",
"(",
"'list'",
",",
"$",
"parameters",
")",
")",
";",
"}"
] | Redirects the user to the list view.
@return RedirectResponse | [
"Redirects",
"the",
"user",
"to",
"the",
"list",
"view",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1293-L1302 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.isInPreviewMode | protected function isInPreviewMode()
{
return $this->admin->supportsPreviewMode()
&& ($this->isPreviewRequested()
|| $this->isPreviewApproved()
|| $this->isPreviewDeclined());
} | php | protected function isInPreviewMode()
{
return $this->admin->supportsPreviewMode()
&& ($this->isPreviewRequested()
|| $this->isPreviewApproved()
|| $this->isPreviewDeclined());
} | [
"protected",
"function",
"isInPreviewMode",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"admin",
"->",
"supportsPreviewMode",
"(",
")",
"&&",
"(",
"$",
"this",
"->",
"isPreviewRequested",
"(",
")",
"||",
"$",
"this",
"->",
"isPreviewApproved",
"(",
")",
"||",
"$",
"this",
"->",
"isPreviewDeclined",
"(",
")",
")",
";",
"}"
] | Returns true if the request is in the preview workflow.
That means either a preview is requested or the preview has already been shown
and it got approved/declined.
@return bool | [
"Returns",
"true",
"if",
"the",
"request",
"is",
"in",
"the",
"preview",
"workflow",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1336-L1342 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.getAclUsers | protected function getAclUsers()
{
$aclUsers = [];
$userManagerServiceName = $this->container->getParameter('sonata.admin.security.acl_user_manager');
if (null !== $userManagerServiceName && $this->has($userManagerServiceName)) {
$userManager = $this->get($userManagerServiceName);
if (method_exists($userManager, 'findUsers')) {
$aclUsers = $userManager->findUsers();
}
}
return \is_array($aclUsers) ? new \ArrayIterator($aclUsers) : $aclUsers;
} | php | protected function getAclUsers()
{
$aclUsers = [];
$userManagerServiceName = $this->container->getParameter('sonata.admin.security.acl_user_manager');
if (null !== $userManagerServiceName && $this->has($userManagerServiceName)) {
$userManager = $this->get($userManagerServiceName);
if (method_exists($userManager, 'findUsers')) {
$aclUsers = $userManager->findUsers();
}
}
return \is_array($aclUsers) ? new \ArrayIterator($aclUsers) : $aclUsers;
} | [
"protected",
"function",
"getAclUsers",
"(",
")",
"{",
"$",
"aclUsers",
"=",
"[",
"]",
";",
"$",
"userManagerServiceName",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sonata.admin.security.acl_user_manager'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"userManagerServiceName",
"&&",
"$",
"this",
"->",
"has",
"(",
"$",
"userManagerServiceName",
")",
")",
"{",
"$",
"userManager",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"userManagerServiceName",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"userManager",
",",
"'findUsers'",
")",
")",
"{",
"$",
"aclUsers",
"=",
"$",
"userManager",
"->",
"findUsers",
"(",
")",
";",
"}",
"}",
"return",
"\\",
"is_array",
"(",
"$",
"aclUsers",
")",
"?",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"aclUsers",
")",
":",
"$",
"aclUsers",
";",
"}"
] | Gets ACL users.
@return \Traversable | [
"Gets",
"ACL",
"users",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1361-L1375 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.getAclRoles | protected function getAclRoles()
{
$aclRoles = [];
$roleHierarchy = $this->container->getParameter('security.role_hierarchy.roles');
$pool = $this->container->get('sonata.admin.pool');
foreach ($pool->getAdminServiceIds() as $id) {
try {
$admin = $pool->getInstance($id);
} catch (\Exception $e) {
continue;
}
$baseRole = $admin->getSecurityHandler()->getBaseRole($admin);
foreach ($admin->getSecurityInformation() as $role => $permissions) {
$role = sprintf($baseRole, $role);
$aclRoles[] = $role;
}
}
foreach ($roleHierarchy as $name => $roles) {
$aclRoles[] = $name;
$aclRoles = array_merge($aclRoles, $roles);
}
$aclRoles = array_unique($aclRoles);
return \is_array($aclRoles) ? new \ArrayIterator($aclRoles) : $aclRoles;
} | php | protected function getAclRoles()
{
$aclRoles = [];
$roleHierarchy = $this->container->getParameter('security.role_hierarchy.roles');
$pool = $this->container->get('sonata.admin.pool');
foreach ($pool->getAdminServiceIds() as $id) {
try {
$admin = $pool->getInstance($id);
} catch (\Exception $e) {
continue;
}
$baseRole = $admin->getSecurityHandler()->getBaseRole($admin);
foreach ($admin->getSecurityInformation() as $role => $permissions) {
$role = sprintf($baseRole, $role);
$aclRoles[] = $role;
}
}
foreach ($roleHierarchy as $name => $roles) {
$aclRoles[] = $name;
$aclRoles = array_merge($aclRoles, $roles);
}
$aclRoles = array_unique($aclRoles);
return \is_array($aclRoles) ? new \ArrayIterator($aclRoles) : $aclRoles;
} | [
"protected",
"function",
"getAclRoles",
"(",
")",
"{",
"$",
"aclRoles",
"=",
"[",
"]",
";",
"$",
"roleHierarchy",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'security.role_hierarchy.roles'",
")",
";",
"$",
"pool",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sonata.admin.pool'",
")",
";",
"foreach",
"(",
"$",
"pool",
"->",
"getAdminServiceIds",
"(",
")",
"as",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"admin",
"=",
"$",
"pool",
"->",
"getInstance",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"$",
"baseRole",
"=",
"$",
"admin",
"->",
"getSecurityHandler",
"(",
")",
"->",
"getBaseRole",
"(",
"$",
"admin",
")",
";",
"foreach",
"(",
"$",
"admin",
"->",
"getSecurityInformation",
"(",
")",
"as",
"$",
"role",
"=>",
"$",
"permissions",
")",
"{",
"$",
"role",
"=",
"sprintf",
"(",
"$",
"baseRole",
",",
"$",
"role",
")",
";",
"$",
"aclRoles",
"[",
"]",
"=",
"$",
"role",
";",
"}",
"}",
"foreach",
"(",
"$",
"roleHierarchy",
"as",
"$",
"name",
"=>",
"$",
"roles",
")",
"{",
"$",
"aclRoles",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"aclRoles",
"=",
"array_merge",
"(",
"$",
"aclRoles",
",",
"$",
"roles",
")",
";",
"}",
"$",
"aclRoles",
"=",
"array_unique",
"(",
"$",
"aclRoles",
")",
";",
"return",
"\\",
"is_array",
"(",
"$",
"aclRoles",
")",
"?",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"aclRoles",
")",
":",
"$",
"aclRoles",
";",
"}"
] | Gets ACL roles.
@return \Traversable | [
"Gets",
"ACL",
"roles",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1382-L1410 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.validateCsrfToken | protected function validateCsrfToken($intention)
{
$request = $this->getRequest();
$token = $request->request->get('_sonata_csrf_token', false);
if ($this->container->has('security.csrf.token_manager')) {
$valid = $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($intention, $token));
} else {
return;
}
if (!$valid) {
throw new HttpException(400, 'The csrf token is not valid, CSRF attack?');
}
} | php | protected function validateCsrfToken($intention)
{
$request = $this->getRequest();
$token = $request->request->get('_sonata_csrf_token', false);
if ($this->container->has('security.csrf.token_manager')) {
$valid = $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($intention, $token));
} else {
return;
}
if (!$valid) {
throw new HttpException(400, 'The csrf token is not valid, CSRF attack?');
}
} | [
"protected",
"function",
"validateCsrfToken",
"(",
"$",
"intention",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"token",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'_sonata_csrf_token'",
",",
"false",
")",
";",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"'security.csrf.token_manager'",
")",
")",
"{",
"$",
"valid",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.csrf.token_manager'",
")",
"->",
"isTokenValid",
"(",
"new",
"CsrfToken",
"(",
"$",
"intention",
",",
"$",
"token",
")",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"valid",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"400",
",",
"'The csrf token is not valid, CSRF attack?'",
")",
";",
"}",
"}"
] | Validate CSRF token for action without form.
@param string $intention
@throws HttpException | [
"Validate",
"CSRF",
"token",
"for",
"action",
"without",
"form",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1419-L1433 | train |
sonata-project/SonataAdminBundle | src/Form/ChoiceList/ModelChoiceList.php | ModelChoiceList.getEntity | public function getEntity($key)
{
if (\count($this->identifier) > 1) {
// $key is a collection index
$entities = $this->getEntities();
return $entities[$key] ?? null;
} elseif ($this->entities) {
return isset($this->entities[$key]) ? $this->entities[$key] : null;
}
return $this->modelManager->find($this->class, $key);
} | php | public function getEntity($key)
{
if (\count($this->identifier) > 1) {
// $key is a collection index
$entities = $this->getEntities();
return $entities[$key] ?? null;
} elseif ($this->entities) {
return isset($this->entities[$key]) ? $this->entities[$key] : null;
}
return $this->modelManager->find($this->class, $key);
} | [
"public",
"function",
"getEntity",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"identifier",
")",
">",
"1",
")",
"{",
"// $key is a collection index",
"$",
"entities",
"=",
"$",
"this",
"->",
"getEntities",
"(",
")",
";",
"return",
"$",
"entities",
"[",
"$",
"key",
"]",
"??",
"null",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"entities",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"modelManager",
"->",
"find",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"key",
")",
";",
"}"
] | Returns the entity for the given key.
If the underlying entities have composite identifiers, the choices
are initialized. The key is expected to be the index in the choices
array in this case.
If they have single identifiers, they are either fetched from the
internal entity cache (if filled) or loaded from the database.
@param string $key The choice key (for entities with composite
identifiers) or entity ID (for entities with single
identifiers)
@return object The matching entity | [
"Returns",
"the",
"entity",
"for",
"the",
"given",
"key",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Form/ChoiceList/ModelChoiceList.php#L170-L182 | train |
sonata-project/SonataAdminBundle | src/Form/ChoiceList/ModelChoiceList.php | ModelChoiceList.getIdentifierValues | public function getIdentifierValues($entity)
{
try {
return $this->modelManager->getIdentifierValues($entity);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Unable to retrieve the identifier values for entity %s', ClassUtils::getClass($entity)), 0, $e);
}
} | php | public function getIdentifierValues($entity)
{
try {
return $this->modelManager->getIdentifierValues($entity);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Unable to retrieve the identifier values for entity %s', ClassUtils::getClass($entity)), 0, $e);
}
} | [
"public",
"function",
"getIdentifierValues",
"(",
"$",
"entity",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"modelManager",
"->",
"getIdentifierValues",
"(",
"$",
"entity",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unable to retrieve the identifier values for entity %s'",
",",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"entity",
")",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Returns the values of the identifier fields of an entity.
Doctrine must know about this entity, that is, the entity must already
be persisted or added to the identity map before. Otherwise an
exception is thrown.
@param object $entity The entity for which to get the identifier
@throws InvalidArgumentException If the entity does not exist in Doctrine's
identity map
@return array | [
"Returns",
"the",
"values",
"of",
"the",
"identifier",
"fields",
"of",
"an",
"entity",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Form/ChoiceList/ModelChoiceList.php#L198-L205 | train |
sonata-project/SonataAdminBundle | src/Form/ChoiceList/ModelChoiceList.php | ModelChoiceList.load | protected function load($choices)
{
if (\is_array($choices) && \count($choices) > 0) {
$entities = $choices;
} elseif ($this->query) {
$entities = $this->modelManager->executeQuery($this->query);
} else {
$entities = $this->modelManager->findBy($this->class);
}
if (null === $entities) {
return [];
}
$choices = [];
$this->entities = [];
foreach ($entities as $key => $entity) {
if ($this->propertyPath) {
// If the property option was given, use it
$value = $this->propertyAccessor->getValue($entity, $this->propertyPath);
} else {
// Otherwise expect a __toString() method in the entity
try {
$value = (string) $entity;
} catch (\Exception $e) {
throw new RuntimeException(sprintf('Unable to convert the entity "%s" to string, provide '
.'"property" option or implement "__toString()" method in your entity.', ClassUtils::getClass($entity)), 0, $e);
}
}
if (\count($this->identifier) > 1) {
// When the identifier consists of multiple field, use
// naturally ordered keys to refer to the choices
$choices[$key] = $value;
$this->entities[$key] = $entity;
} else {
// When the identifier is a single field, index choices by
// entity ID for performance reasons
$id = current($this->getIdentifierValues($entity));
$choices[$id] = $value;
$this->entities[$id] = $entity;
}
}
return $choices;
} | php | protected function load($choices)
{
if (\is_array($choices) && \count($choices) > 0) {
$entities = $choices;
} elseif ($this->query) {
$entities = $this->modelManager->executeQuery($this->query);
} else {
$entities = $this->modelManager->findBy($this->class);
}
if (null === $entities) {
return [];
}
$choices = [];
$this->entities = [];
foreach ($entities as $key => $entity) {
if ($this->propertyPath) {
// If the property option was given, use it
$value = $this->propertyAccessor->getValue($entity, $this->propertyPath);
} else {
// Otherwise expect a __toString() method in the entity
try {
$value = (string) $entity;
} catch (\Exception $e) {
throw new RuntimeException(sprintf('Unable to convert the entity "%s" to string, provide '
.'"property" option or implement "__toString()" method in your entity.', ClassUtils::getClass($entity)), 0, $e);
}
}
if (\count($this->identifier) > 1) {
// When the identifier consists of multiple field, use
// naturally ordered keys to refer to the choices
$choices[$key] = $value;
$this->entities[$key] = $entity;
} else {
// When the identifier is a single field, index choices by
// entity ID for performance reasons
$id = current($this->getIdentifierValues($entity));
$choices[$id] = $value;
$this->entities[$id] = $entity;
}
}
return $choices;
} | [
"protected",
"function",
"load",
"(",
"$",
"choices",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"choices",
")",
"&&",
"\\",
"count",
"(",
"$",
"choices",
")",
">",
"0",
")",
"{",
"$",
"entities",
"=",
"$",
"choices",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"query",
")",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"modelManager",
"->",
"executeQuery",
"(",
"$",
"this",
"->",
"query",
")",
";",
"}",
"else",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"modelManager",
"->",
"findBy",
"(",
"$",
"this",
"->",
"class",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"entities",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"choices",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"entities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"key",
"=>",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"propertyPath",
")",
"{",
"// If the property option was given, use it",
"$",
"value",
"=",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"propertyPath",
")",
";",
"}",
"else",
"{",
"// Otherwise expect a __toString() method in the entity",
"try",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"entity",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to convert the entity \"%s\" to string, provide '",
".",
"'\"property\" option or implement \"__toString()\" method in your entity.'",
",",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"entity",
")",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"identifier",
")",
">",
"1",
")",
"{",
"// When the identifier consists of multiple field, use",
"// naturally ordered keys to refer to the choices",
"$",
"choices",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"entities",
"[",
"$",
"key",
"]",
"=",
"$",
"entity",
";",
"}",
"else",
"{",
"// When the identifier is a single field, index choices by",
"// entity ID for performance reasons",
"$",
"id",
"=",
"current",
"(",
"$",
"this",
"->",
"getIdentifierValues",
"(",
"$",
"entity",
")",
")",
";",
"$",
"choices",
"[",
"$",
"id",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"entities",
"[",
"$",
"id",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"return",
"$",
"choices",
";",
"}"
] | Initializes the choices and returns them.
The choices are generated from the entities. If the entities have a
composite identifier, the choices are indexed using ascending integers.
Otherwise the identifiers are used as indices.
If the entities were passed in the "choices" option, this method
does not have any significant overhead. Otherwise, if a query builder
was passed in the "query" option, this builder is now used to construct
a query which is executed. In the last case, all entities for the
underlying class are fetched from the repository.
If the option "property" was passed, the property path in that option
is used as option values. Otherwise this method tries to convert
objects to strings using __toString().
@return array An array of choices | [
"Initializes",
"the",
"choices",
"and",
"returns",
"them",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Form/ChoiceList/ModelChoiceList.php#L242-L288 | train |
sonata-project/SonataAdminBundle | src/Form/ChoiceList/ModelChoiceList.php | ModelChoiceList.getReflProperty | private function getReflProperty(string $property): ReflectionProperty
{
if (!isset($this->reflProperties[$property])) {
$this->reflProperties[$property] = new \ReflectionProperty($this->class, $property);
$this->reflProperties[$property]->setAccessible(true);
}
return $this->reflProperties[$property];
} | php | private function getReflProperty(string $property): ReflectionProperty
{
if (!isset($this->reflProperties[$property])) {
$this->reflProperties[$property] = new \ReflectionProperty($this->class, $property);
$this->reflProperties[$property]->setAccessible(true);
}
return $this->reflProperties[$property];
} | [
"private",
"function",
"getReflProperty",
"(",
"string",
"$",
"property",
")",
":",
"ReflectionProperty",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"reflProperties",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reflProperties",
"[",
"$",
"property",
"]",
"=",
"new",
"\\",
"ReflectionProperty",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"property",
")",
";",
"$",
"this",
"->",
"reflProperties",
"[",
"$",
"property",
"]",
"->",
"setAccessible",
"(",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"reflProperties",
"[",
"$",
"property",
"]",
";",
"}"
] | Returns the \ReflectionProperty instance for a property of the
underlying class.
@param string $property The name of the property
@return \ReflectionProperty The reflection instance | [
"Returns",
"the",
"\\",
"ReflectionProperty",
"instance",
"for",
"a",
"property",
"of",
"the",
"underlying",
"class",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Form/ChoiceList/ModelChoiceList.php#L298-L306 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.renderListElement | public function renderListElement(
Environment $environment,
$object,
FieldDescriptionInterface $fieldDescription,
$params = []
) {
$template = $this->getTemplate(
$fieldDescription,
// NEXT_MAJOR: Remove this line and use commented line below instead
$fieldDescription->getAdmin()->getTemplate('base_list_field'),
//$this->getTemplateRegistry($fieldDescription->getAdmin()->getCode())->getTemplate('base_list_field'),
$environment
);
return $this->render($fieldDescription, $template, array_merge($params, [
'admin' => $fieldDescription->getAdmin(),
'object' => $object,
'value' => $this->getValueFromFieldDescription($object, $fieldDescription),
'field_description' => $fieldDescription,
]), $environment);
} | php | public function renderListElement(
Environment $environment,
$object,
FieldDescriptionInterface $fieldDescription,
$params = []
) {
$template = $this->getTemplate(
$fieldDescription,
// NEXT_MAJOR: Remove this line and use commented line below instead
$fieldDescription->getAdmin()->getTemplate('base_list_field'),
//$this->getTemplateRegistry($fieldDescription->getAdmin()->getCode())->getTemplate('base_list_field'),
$environment
);
return $this->render($fieldDescription, $template, array_merge($params, [
'admin' => $fieldDescription->getAdmin(),
'object' => $object,
'value' => $this->getValueFromFieldDescription($object, $fieldDescription),
'field_description' => $fieldDescription,
]), $environment);
} | [
"public",
"function",
"renderListElement",
"(",
"Environment",
"$",
"environment",
",",
"$",
"object",
",",
"FieldDescriptionInterface",
"$",
"fieldDescription",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplate",
"(",
"$",
"fieldDescription",
",",
"// NEXT_MAJOR: Remove this line and use commented line below instead",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
"->",
"getTemplate",
"(",
"'base_list_field'",
")",
",",
"//$this->getTemplateRegistry($fieldDescription->getAdmin()->getCode())->getTemplate('base_list_field'),",
"$",
"environment",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"fieldDescription",
",",
"$",
"template",
",",
"array_merge",
"(",
"$",
"params",
",",
"[",
"'admin'",
"=>",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
",",
"'object'",
"=>",
"$",
"object",
",",
"'value'",
"=>",
"$",
"this",
"->",
"getValueFromFieldDescription",
"(",
"$",
"object",
",",
"$",
"fieldDescription",
")",
",",
"'field_description'",
"=>",
"$",
"fieldDescription",
",",
"]",
")",
",",
"$",
"environment",
")",
";",
"}"
] | render a list element from the FieldDescription.
@param mixed $object
@param array $params
@return string | [
"render",
"a",
"list",
"element",
"from",
"the",
"FieldDescription",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L170-L190 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.renderViewElement | public function renderViewElement(
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$object
) {
$template = $this->getTemplate(
$fieldDescription,
'@SonataAdmin/CRUD/base_show_field.html.twig',
$environment
);
try {
$value = $fieldDescription->getValue($object);
} catch (NoValueException $e) {
$value = null;
}
return $this->render($fieldDescription, $template, [
'field_description' => $fieldDescription,
'object' => $object,
'value' => $value,
'admin' => $fieldDescription->getAdmin(),
], $environment);
} | php | public function renderViewElement(
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$object
) {
$template = $this->getTemplate(
$fieldDescription,
'@SonataAdmin/CRUD/base_show_field.html.twig',
$environment
);
try {
$value = $fieldDescription->getValue($object);
} catch (NoValueException $e) {
$value = null;
}
return $this->render($fieldDescription, $template, [
'field_description' => $fieldDescription,
'object' => $object,
'value' => $value,
'admin' => $fieldDescription->getAdmin(),
], $environment);
} | [
"public",
"function",
"renderViewElement",
"(",
"Environment",
"$",
"environment",
",",
"FieldDescriptionInterface",
"$",
"fieldDescription",
",",
"$",
"object",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplate",
"(",
"$",
"fieldDescription",
",",
"'@SonataAdmin/CRUD/base_show_field.html.twig'",
",",
"$",
"environment",
")",
";",
"try",
"{",
"$",
"value",
"=",
"$",
"fieldDescription",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}",
"catch",
"(",
"NoValueException",
"$",
"e",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"fieldDescription",
",",
"$",
"template",
",",
"[",
"'field_description'",
"=>",
"$",
"fieldDescription",
",",
"'object'",
"=>",
"$",
"object",
",",
"'value'",
"=>",
"$",
"value",
",",
"'admin'",
"=>",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
",",
"]",
",",
"$",
"environment",
")",
";",
"}"
] | render a view element.
@param mixed $object
@return string | [
"render",
"a",
"view",
"element",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L250-L273 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.renderViewElementCompare | public function renderViewElementCompare(
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$baseObject,
$compareObject
) {
$template = $this->getTemplate(
$fieldDescription,
'@SonataAdmin/CRUD/base_show_field.html.twig',
$environment
);
try {
$baseValue = $fieldDescription->getValue($baseObject);
} catch (NoValueException $e) {
$baseValue = null;
}
try {
$compareValue = $fieldDescription->getValue($compareObject);
} catch (NoValueException $e) {
$compareValue = null;
}
$baseValueOutput = $template->render([
'admin' => $fieldDescription->getAdmin(),
'field_description' => $fieldDescription,
'value' => $baseValue,
]);
$compareValueOutput = $template->render([
'field_description' => $fieldDescription,
'admin' => $fieldDescription->getAdmin(),
'value' => $compareValue,
]);
// Compare the rendered output of both objects by using the (possibly) overridden field block
$isDiff = $baseValueOutput !== $compareValueOutput;
return $this->render($fieldDescription, $template, [
'field_description' => $fieldDescription,
'value' => $baseValue,
'value_compare' => $compareValue,
'is_diff' => $isDiff,
'admin' => $fieldDescription->getAdmin(),
], $environment);
} | php | public function renderViewElementCompare(
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$baseObject,
$compareObject
) {
$template = $this->getTemplate(
$fieldDescription,
'@SonataAdmin/CRUD/base_show_field.html.twig',
$environment
);
try {
$baseValue = $fieldDescription->getValue($baseObject);
} catch (NoValueException $e) {
$baseValue = null;
}
try {
$compareValue = $fieldDescription->getValue($compareObject);
} catch (NoValueException $e) {
$compareValue = null;
}
$baseValueOutput = $template->render([
'admin' => $fieldDescription->getAdmin(),
'field_description' => $fieldDescription,
'value' => $baseValue,
]);
$compareValueOutput = $template->render([
'field_description' => $fieldDescription,
'admin' => $fieldDescription->getAdmin(),
'value' => $compareValue,
]);
// Compare the rendered output of both objects by using the (possibly) overridden field block
$isDiff = $baseValueOutput !== $compareValueOutput;
return $this->render($fieldDescription, $template, [
'field_description' => $fieldDescription,
'value' => $baseValue,
'value_compare' => $compareValue,
'is_diff' => $isDiff,
'admin' => $fieldDescription->getAdmin(),
], $environment);
} | [
"public",
"function",
"renderViewElementCompare",
"(",
"Environment",
"$",
"environment",
",",
"FieldDescriptionInterface",
"$",
"fieldDescription",
",",
"$",
"baseObject",
",",
"$",
"compareObject",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"getTemplate",
"(",
"$",
"fieldDescription",
",",
"'@SonataAdmin/CRUD/base_show_field.html.twig'",
",",
"$",
"environment",
")",
";",
"try",
"{",
"$",
"baseValue",
"=",
"$",
"fieldDescription",
"->",
"getValue",
"(",
"$",
"baseObject",
")",
";",
"}",
"catch",
"(",
"NoValueException",
"$",
"e",
")",
"{",
"$",
"baseValue",
"=",
"null",
";",
"}",
"try",
"{",
"$",
"compareValue",
"=",
"$",
"fieldDescription",
"->",
"getValue",
"(",
"$",
"compareObject",
")",
";",
"}",
"catch",
"(",
"NoValueException",
"$",
"e",
")",
"{",
"$",
"compareValue",
"=",
"null",
";",
"}",
"$",
"baseValueOutput",
"=",
"$",
"template",
"->",
"render",
"(",
"[",
"'admin'",
"=>",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
",",
"'field_description'",
"=>",
"$",
"fieldDescription",
",",
"'value'",
"=>",
"$",
"baseValue",
",",
"]",
")",
";",
"$",
"compareValueOutput",
"=",
"$",
"template",
"->",
"render",
"(",
"[",
"'field_description'",
"=>",
"$",
"fieldDescription",
",",
"'admin'",
"=>",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
",",
"'value'",
"=>",
"$",
"compareValue",
",",
"]",
")",
";",
"// Compare the rendered output of both objects by using the (possibly) overridden field block",
"$",
"isDiff",
"=",
"$",
"baseValueOutput",
"!==",
"$",
"compareValueOutput",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"fieldDescription",
",",
"$",
"template",
",",
"[",
"'field_description'",
"=>",
"$",
"fieldDescription",
",",
"'value'",
"=>",
"$",
"baseValue",
",",
"'value_compare'",
"=>",
"$",
"compareValue",
",",
"'is_diff'",
"=>",
"$",
"isDiff",
",",
"'admin'",
"=>",
"$",
"fieldDescription",
"->",
"getAdmin",
"(",
")",
",",
"]",
",",
"$",
"environment",
")",
";",
"}"
] | render a compared view element.
@param mixed $baseObject
@param mixed $compareObject
@return string | [
"render",
"a",
"compared",
"view",
"element",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L283-L329 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.getUrlsafeIdentifier | public function getUrlsafeIdentifier($model, AdminInterface $admin = null)
{
if (null === $admin) {
$admin = $this->pool->getAdminByClass(ClassUtils::getClass($model));
}
return $admin->getUrlsafeIdentifier($model);
} | php | public function getUrlsafeIdentifier($model, AdminInterface $admin = null)
{
if (null === $admin) {
$admin = $this->pool->getAdminByClass(ClassUtils::getClass($model));
}
return $admin->getUrlsafeIdentifier($model);
} | [
"public",
"function",
"getUrlsafeIdentifier",
"(",
"$",
"model",
",",
"AdminInterface",
"$",
"admin",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"admin",
")",
"{",
"$",
"admin",
"=",
"$",
"this",
"->",
"pool",
"->",
"getAdminByClass",
"(",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"model",
")",
")",
";",
"}",
"return",
"$",
"admin",
"->",
"getUrlsafeIdentifier",
"(",
"$",
"model",
")",
";",
"}"
] | Get the identifiers as a string that is safe to use in a url.
@param object $model
@return string string representation of the id that is safe to use in a url | [
"Get",
"the",
"identifiers",
"as",
"a",
"string",
"that",
"is",
"safe",
"to",
"use",
"in",
"a",
"url",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L387-L394 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.getCanonicalizedLocaleForMoment | final public function getCanonicalizedLocaleForMoment(array $context)
{
$locale = strtolower(str_replace('_', '-', $context['app']->getRequest()->getLocale()));
// "en" language doesn't require localization.
if (('en' === $lang = substr($locale, 0, 2)) && !\in_array($locale, ['en-au', 'en-ca', 'en-gb', 'en-ie', 'en-nz'], true)) {
return null;
}
foreach (self::MOMENT_UNSUPPORTED_LOCALES as $language => $locales) {
if ($language === $lang && !\in_array($locale, $locales, true)) {
$locale = $language;
}
}
return $locale;
} | php | final public function getCanonicalizedLocaleForMoment(array $context)
{
$locale = strtolower(str_replace('_', '-', $context['app']->getRequest()->getLocale()));
// "en" language doesn't require localization.
if (('en' === $lang = substr($locale, 0, 2)) && !\in_array($locale, ['en-au', 'en-ca', 'en-gb', 'en-ie', 'en-nz'], true)) {
return null;
}
foreach (self::MOMENT_UNSUPPORTED_LOCALES as $language => $locales) {
if ($language === $lang && !\in_array($locale, $locales, true)) {
$locale = $language;
}
}
return $locale;
} | [
"final",
"public",
"function",
"getCanonicalizedLocaleForMoment",
"(",
"array",
"$",
"context",
")",
"{",
"$",
"locale",
"=",
"strtolower",
"(",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"context",
"[",
"'app'",
"]",
"->",
"getRequest",
"(",
")",
"->",
"getLocale",
"(",
")",
")",
")",
";",
"// \"en\" language doesn't require localization.",
"if",
"(",
"(",
"'en'",
"===",
"$",
"lang",
"=",
"substr",
"(",
"$",
"locale",
",",
"0",
",",
"2",
")",
")",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"locale",
",",
"[",
"'en-au'",
",",
"'en-ca'",
",",
"'en-gb'",
",",
"'en-ie'",
",",
"'en-nz'",
"]",
",",
"true",
")",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
"(",
"self",
"::",
"MOMENT_UNSUPPORTED_LOCALES",
"as",
"$",
"language",
"=>",
"$",
"locales",
")",
"{",
"if",
"(",
"$",
"language",
"===",
"$",
"lang",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"locale",
",",
"$",
"locales",
",",
"true",
")",
")",
"{",
"$",
"locale",
"=",
"$",
"language",
";",
"}",
"}",
"return",
"$",
"locale",
";",
"}"
] | Returns a canonicalized locale for "moment" NPM library,
or `null` if the locale's language is "en", which doesn't require localization.
@return string|null | [
"Returns",
"a",
"canonicalized",
"locale",
"for",
"moment",
"NPM",
"library",
"or",
"null",
"if",
"the",
"locale",
"s",
"language",
"is",
"en",
"which",
"doesn",
"t",
"require",
"localization",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L469-L485 | train |
sonata-project/SonataAdminBundle | src/Twig/Extension/SonataAdminExtension.php | SonataAdminExtension.getCanonicalizedLocaleForSelect2 | final public function getCanonicalizedLocaleForSelect2(array $context)
{
$locale = str_replace('_', '-', $context['app']->getRequest()->getLocale());
// "en" language doesn't require localization.
if ('en' === $lang = substr($locale, 0, 2)) {
return null;
}
switch ($locale) {
case 'pt':
$locale = 'pt-PT';
break;
case 'ug':
$locale = 'ug-CN';
break;
case 'zh':
$locale = 'zh-CN';
break;
default:
if (!\in_array($locale, ['pt-BR', 'pt-PT', 'ug-CN', 'zh-CN', 'zh-TW'], true)) {
$locale = $lang;
}
}
return $locale;
} | php | final public function getCanonicalizedLocaleForSelect2(array $context)
{
$locale = str_replace('_', '-', $context['app']->getRequest()->getLocale());
// "en" language doesn't require localization.
if ('en' === $lang = substr($locale, 0, 2)) {
return null;
}
switch ($locale) {
case 'pt':
$locale = 'pt-PT';
break;
case 'ug':
$locale = 'ug-CN';
break;
case 'zh':
$locale = 'zh-CN';
break;
default:
if (!\in_array($locale, ['pt-BR', 'pt-PT', 'ug-CN', 'zh-CN', 'zh-TW'], true)) {
$locale = $lang;
}
}
return $locale;
} | [
"final",
"public",
"function",
"getCanonicalizedLocaleForSelect2",
"(",
"array",
"$",
"context",
")",
"{",
"$",
"locale",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"context",
"[",
"'app'",
"]",
"->",
"getRequest",
"(",
")",
"->",
"getLocale",
"(",
")",
")",
";",
"// \"en\" language doesn't require localization.",
"if",
"(",
"'en'",
"===",
"$",
"lang",
"=",
"substr",
"(",
"$",
"locale",
",",
"0",
",",
"2",
")",
")",
"{",
"return",
"null",
";",
"}",
"switch",
"(",
"$",
"locale",
")",
"{",
"case",
"'pt'",
":",
"$",
"locale",
"=",
"'pt-PT'",
";",
"break",
";",
"case",
"'ug'",
":",
"$",
"locale",
"=",
"'ug-CN'",
";",
"break",
";",
"case",
"'zh'",
":",
"$",
"locale",
"=",
"'zh-CN'",
";",
"break",
";",
"default",
":",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"locale",
",",
"[",
"'pt-BR'",
",",
"'pt-PT'",
",",
"'ug-CN'",
",",
"'zh-CN'",
",",
"'zh-TW'",
"]",
",",
"true",
")",
")",
"{",
"$",
"locale",
"=",
"$",
"lang",
";",
"}",
"}",
"return",
"$",
"locale",
";",
"}"
] | Returns a canonicalized locale for "select2" NPM library,
or `null` if the locale's language is "en", which doesn't require localization.
@return string|null | [
"Returns",
"a",
"canonicalized",
"locale",
"for",
"select2",
"NPM",
"library",
"or",
"null",
"if",
"the",
"locale",
"s",
"language",
"is",
"en",
"which",
"doesn",
"t",
"require",
"localization",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Twig/Extension/SonataAdminExtension.php#L493-L519 | train |
Alexia/php7mar | classes/reporter.php | reporter.add | public function add($line, $nlBefore = 0, $nlAfter = 0) {
$output = str_repeat("\n", $nlBefore).$line.str_repeat("\n", $nlAfter);
if (fwrite($this->file, $output) === false) {
die("There was an error attempting to write to the report file.\n".$this->fullFilePath."\n");
}
} | php | public function add($line, $nlBefore = 0, $nlAfter = 0) {
$output = str_repeat("\n", $nlBefore).$line.str_repeat("\n", $nlAfter);
if (fwrite($this->file, $output) === false) {
die("There was an error attempting to write to the report file.\n".$this->fullFilePath."\n");
}
} | [
"public",
"function",
"add",
"(",
"$",
"line",
",",
"$",
"nlBefore",
"=",
"0",
",",
"$",
"nlAfter",
"=",
"0",
")",
"{",
"$",
"output",
"=",
"str_repeat",
"(",
"\"\\n\"",
",",
"$",
"nlBefore",
")",
".",
"$",
"line",
".",
"str_repeat",
"(",
"\"\\n\"",
",",
"$",
"nlAfter",
")",
";",
"if",
"(",
"fwrite",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"output",
")",
"===",
"false",
")",
"{",
"die",
"(",
"\"There was an error attempting to write to the report file.\\n\"",
".",
"$",
"this",
"->",
"fullFilePath",
".",
"\"\\n\"",
")",
";",
"}",
"}"
] | Add a new line to the report.
@access public
@param string Line of text to add to the buffer.
@param integer Number of new line characters to add before the line.
@param integer Number of new line characters to add after the line.
@param string Line of text to add to the buffer.
@return void | [
"Add",
"a",
"new",
"line",
"to",
"the",
"report",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/reporter.php#L97-L102 | train |
Alexia/php7mar | classes/reporter.php | reporter.addToSection | public function addToSection($section, $test, $filePath, $lineNumber, $codeLine) {
if (empty($section)) {
throw new \Exception(__METHOD__.": The section can not be empty.");
}
$this->sectionBuffers[$section][$filePath][$test][] = [$lineNumber, $codeLine];
} | php | public function addToSection($section, $test, $filePath, $lineNumber, $codeLine) {
if (empty($section)) {
throw new \Exception(__METHOD__.": The section can not be empty.");
}
$this->sectionBuffers[$section][$filePath][$test][] = [$lineNumber, $codeLine];
} | [
"public",
"function",
"addToSection",
"(",
"$",
"section",
",",
"$",
"test",
",",
"$",
"filePath",
",",
"$",
"lineNumber",
",",
"$",
"codeLine",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"section",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"\": The section can not be empty.\"",
")",
";",
"}",
"$",
"this",
"->",
"sectionBuffers",
"[",
"$",
"section",
"]",
"[",
"$",
"filePath",
"]",
"[",
"$",
"test",
"]",
"[",
"]",
"=",
"[",
"$",
"lineNumber",
",",
"$",
"codeLine",
"]",
";",
"}"
] | Add text to the specified section.
@access public
@param string Section Name
@param string Test Name
@param string File Path
@param string Line Number
@param string Code Line
@return void | [
"Add",
"text",
"to",
"the",
"specified",
"section",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/reporter.php#L115-L120 | train |
Alexia/php7mar | classes/reporter.php | reporter.addSections | public function addSections() {
foreach ($this->sectionBuffers as $section => $filePaths) {
$this->add('# '.$section, 1, 1);
foreach ($filePaths as $filePath => $tests) {
$this->add('#### '.$filePath, 0, 1);
foreach ($tests as $test => $lines) {
$this->add('* '.$test, 0, 1);
foreach ($lines as $line) {
$this->add(" * Line {$line[0]}: `".str_replace('`', '\`', $line[1])."`", 0, 1);
}
}
$this->add('', 1, 0);
}
}
} | php | public function addSections() {
foreach ($this->sectionBuffers as $section => $filePaths) {
$this->add('# '.$section, 1, 1);
foreach ($filePaths as $filePath => $tests) {
$this->add('#### '.$filePath, 0, 1);
foreach ($tests as $test => $lines) {
$this->add('* '.$test, 0, 1);
foreach ($lines as $line) {
$this->add(" * Line {$line[0]}: `".str_replace('`', '\`', $line[1])."`", 0, 1);
}
}
$this->add('', 1, 0);
}
}
} | [
"public",
"function",
"addSections",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sectionBuffers",
"as",
"$",
"section",
"=>",
"$",
"filePaths",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"'# '",
".",
"$",
"section",
",",
"1",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"filePaths",
"as",
"$",
"filePath",
"=>",
"$",
"tests",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"'#### '",
".",
"$",
"filePath",
",",
"0",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"tests",
"as",
"$",
"test",
"=>",
"$",
"lines",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"'* '",
".",
"$",
"test",
",",
"0",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"\" * Line {$line[0]}: `\"",
".",
"str_replace",
"(",
"'`'",
",",
"'\\`'",
",",
"$",
"line",
"[",
"1",
"]",
")",
".",
"\"`\"",
",",
"0",
",",
"1",
")",
";",
"}",
"}",
"$",
"this",
"->",
"add",
"(",
"''",
",",
"1",
",",
"0",
")",
";",
"}",
"}",
"}"
] | Add sections in the buffer to the output.
@access public
@return void | [
"Add",
"sections",
"in",
"the",
"buffer",
"to",
"the",
"output",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/reporter.php#L128-L142 | train |
Alexia/php7mar | classes/scanner.php | scanner.recursiveScan | private function recursiveScan($startFolder) {
if (is_file($startFolder)) {
$this->files[] = $startFolder;
return;
}
$contents = scandir($startFolder);
foreach ($contents as $content) {
if (strpos($content, '.') === 0) {
continue;
}
$path = $startFolder.DIRECTORY_SEPARATOR.$content;
if (is_dir($path)) {
$this->recursiveScan($path);
} else {
$fileExtension = pathinfo($content, PATHINFO_EXTENSION);
if (strlen($fileExtension) == 0 || !in_array($fileExtension, $this->getFileExtensions())) {
continue;
}
$this->files[] = $path;
}
}
} | php | private function recursiveScan($startFolder) {
if (is_file($startFolder)) {
$this->files[] = $startFolder;
return;
}
$contents = scandir($startFolder);
foreach ($contents as $content) {
if (strpos($content, '.') === 0) {
continue;
}
$path = $startFolder.DIRECTORY_SEPARATOR.$content;
if (is_dir($path)) {
$this->recursiveScan($path);
} else {
$fileExtension = pathinfo($content, PATHINFO_EXTENSION);
if (strlen($fileExtension) == 0 || !in_array($fileExtension, $this->getFileExtensions())) {
continue;
}
$this->files[] = $path;
}
}
} | [
"private",
"function",
"recursiveScan",
"(",
"$",
"startFolder",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"startFolder",
")",
")",
"{",
"$",
"this",
"->",
"files",
"[",
"]",
"=",
"$",
"startFolder",
";",
"return",
";",
"}",
"$",
"contents",
"=",
"scandir",
"(",
"$",
"startFolder",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"content",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"content",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"path",
"=",
"$",
"startFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"content",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"recursiveScan",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"fileExtension",
"=",
"pathinfo",
"(",
"$",
"content",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"fileExtension",
")",
"==",
"0",
"||",
"!",
"in_array",
"(",
"$",
"fileExtension",
",",
"$",
"this",
"->",
"getFileExtensions",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"files",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"}",
"}"
] | Perform a recursive scan of the given path to return files only.
@access private
@param string Starting Folder
@return void | [
"Perform",
"a",
"recursive",
"scan",
"of",
"the",
"given",
"path",
"to",
"return",
"files",
"only",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/scanner.php#L64-L86 | train |
Alexia/php7mar | classes/scanner.php | scanner.scanNextFile | public function scanNextFile() {
$_file = each($this->files);
if ($_file === false) {
return false;
}
$file = $_file['value'];
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines === false) {
$lines = [];
}
return $lines;
} | php | public function scanNextFile() {
$_file = each($this->files);
if ($_file === false) {
return false;
}
$file = $_file['value'];
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines === false) {
$lines = [];
}
return $lines;
} | [
"public",
"function",
"scanNextFile",
"(",
")",
"{",
"$",
"_file",
"=",
"each",
"(",
"$",
"this",
"->",
"files",
")",
";",
"if",
"(",
"$",
"_file",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"file",
"=",
"$",
"_file",
"[",
"'value'",
"]",
";",
"$",
"lines",
"=",
"file",
"(",
"$",
"file",
",",
"FILE_IGNORE_NEW_LINES",
"|",
"FILE_SKIP_EMPTY_LINES",
")",
";",
"if",
"(",
"$",
"lines",
"===",
"false",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"lines",
";",
"}"
] | Scan the next file in the array and provide back an array of lines.
@access public
@return mixed Array of lines from the file or false for no more files. | [
"Scan",
"the",
"next",
"file",
"in",
"the",
"array",
"and",
"provide",
"back",
"an",
"array",
"of",
"lines",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/scanner.php#L94-L106 | train |
Alexia/php7mar | classes/options.php | options.printOptionsAndExit | private function printOptionsAndExit() {
echo "Available Options:\n";
foreach ($this->validShortOptions as $option => $info) {
echo "-\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n";
}
foreach ($this->validLongOptions as $option => $info) {
echo "--\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n";
}
exit;
} | php | private function printOptionsAndExit() {
echo "Available Options:\n";
foreach ($this->validShortOptions as $option => $info) {
echo "-\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n";
}
foreach ($this->validLongOptions as $option => $info) {
echo "--\033[1m{$option}\033[0m\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n\n";
}
exit;
} | [
"private",
"function",
"printOptionsAndExit",
"(",
")",
"{",
"echo",
"\"Available Options:\\n\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"validShortOptions",
"as",
"$",
"option",
"=>",
"$",
"info",
")",
"{",
"echo",
"\"-\\033[1m{$option}\\033[0m\\n\t{$info['comment']}\\n\t{$info['description']}\\n\t\tExample: {$info['example']}\\n\\n\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"validLongOptions",
"as",
"$",
"option",
"=>",
"$",
"info",
")",
"{",
"echo",
"\"--\\033[1m{$option}\\033[0m\\n\t{$info['comment']}\\n\t{$info['description']}\\n\t\tExample: {$info['example']}\\n\\n\"",
";",
"}",
"exit",
";",
"}"
] | Print out available options and exit.
@access private
@return void | [
"Print",
"out",
"available",
"options",
"and",
"exit",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/options.php#L155-L164 | train |
Alexia/php7mar | classes/options.php | options.parseOption | private function parseOption($rawOption) {
$regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#";
if (preg_match($regex, trim($rawOption), $matches)) {
if (isset($matches['option'])) {
$option = ltrim($matches['option'], '-');
if (isset($matches['value'])) {
$value = $matches['value'];
}
if (strlen($option) == 1) {
//Short Option
$validOptions = $this->validShortOptions;
} elseif (strlen($option) >= 2) {
//Long Option
$validOptions = $this->validLongOptions;
}
if (!isset($validOptions[$option])) {
die("The option `{$option}` does not exist.\n");
}
if ($validOptions[$option]['value'] === self::VALUE_REQUIRED && !isset($value)) {
die("The option `{$option}` requires a value, but none was given.\n");
}
if (isset($validOptions[$option]['allowed']) || (isset($validOptions[$option]['comma_delimited']) && $validOptions[$option]['comma_delimited'] == true)) {
$value = explode(',', $value);
$value = array_map('trim', $value);
}
if (isset($validOptions[$option]['allowed'])) {
foreach ($value as $_value) {
if (!in_array($_value, $validOptions[$option]['allowed'])) {
die("The value `{$_value}` for `{$option}` is not valid.\n");
}
}
}
$this->options[$option] = (isset($value) ? $value : true);
}
}
} | php | private function parseOption($rawOption) {
$regex = "#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\"]?.+?['|\"]?))?$#";
if (preg_match($regex, trim($rawOption), $matches)) {
if (isset($matches['option'])) {
$option = ltrim($matches['option'], '-');
if (isset($matches['value'])) {
$value = $matches['value'];
}
if (strlen($option) == 1) {
//Short Option
$validOptions = $this->validShortOptions;
} elseif (strlen($option) >= 2) {
//Long Option
$validOptions = $this->validLongOptions;
}
if (!isset($validOptions[$option])) {
die("The option `{$option}` does not exist.\n");
}
if ($validOptions[$option]['value'] === self::VALUE_REQUIRED && !isset($value)) {
die("The option `{$option}` requires a value, but none was given.\n");
}
if (isset($validOptions[$option]['allowed']) || (isset($validOptions[$option]['comma_delimited']) && $validOptions[$option]['comma_delimited'] == true)) {
$value = explode(',', $value);
$value = array_map('trim', $value);
}
if (isset($validOptions[$option]['allowed'])) {
foreach ($value as $_value) {
if (!in_array($_value, $validOptions[$option]['allowed'])) {
die("The value `{$_value}` for `{$option}` is not valid.\n");
}
}
}
$this->options[$option] = (isset($value) ? $value : true);
}
}
} | [
"private",
"function",
"parseOption",
"(",
"$",
"rawOption",
")",
"{",
"$",
"regex",
"=",
"\"#^(?P<option>-[a-zA-Z]{1}|--[a-zA-Z-]{2,})(?:=(?P<value>['|\\\"]?.+?['|\\\"]?))?$#\"",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"trim",
"(",
"$",
"rawOption",
")",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"'option'",
"]",
")",
")",
"{",
"$",
"option",
"=",
"ltrim",
"(",
"$",
"matches",
"[",
"'option'",
"]",
",",
"'-'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"matches",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"option",
")",
"==",
"1",
")",
"{",
"//Short Option",
"$",
"validOptions",
"=",
"$",
"this",
"->",
"validShortOptions",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"option",
")",
">=",
"2",
")",
"{",
"//Long Option",
"$",
"validOptions",
"=",
"$",
"this",
"->",
"validLongOptions",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"validOptions",
"[",
"$",
"option",
"]",
")",
")",
"{",
"die",
"(",
"\"The option `{$option}` does not exist.\\n\"",
")",
";",
"}",
"if",
"(",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'value'",
"]",
"===",
"self",
"::",
"VALUE_REQUIRED",
"&&",
"!",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"die",
"(",
"\"The option `{$option}` requires a value, but none was given.\\n\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'allowed'",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'comma_delimited'",
"]",
")",
"&&",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'comma_delimited'",
"]",
"==",
"true",
")",
")",
"{",
"$",
"value",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'allowed'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"_value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"_value",
",",
"$",
"validOptions",
"[",
"$",
"option",
"]",
"[",
"'allowed'",
"]",
")",
")",
"{",
"die",
"(",
"\"The value `{$_value}` for `{$option}` is not valid.\\n\"",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
"=",
"(",
"isset",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"true",
")",
";",
"}",
"}",
"}"
] | Parse a raw option
@access private
@param string Raw option from the command line.
@return array Option name, value if provided. | [
"Parse",
"a",
"raw",
"option"
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/options.php#L173-L209 | train |
Alexia/php7mar | classes/options.php | options.enforceOptions | private function enforceOptions() {
foreach ($this->validShortOptions as $option => $info) {
if ($info['option'] === self::OPTION_REQUIRED && !isset($this->options[$option])) {
die("The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n");
}
}
foreach ($this->validLongOptions as $option => $info) {
if ($info['option'] === self::OPTION_REQUIRED && !isset($this->options[$option])) {
die("The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n");
}
}
} | php | private function enforceOptions() {
foreach ($this->validShortOptions as $option => $info) {
if ($info['option'] === self::OPTION_REQUIRED && !isset($this->options[$option])) {
die("The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n");
}
}
foreach ($this->validLongOptions as $option => $info) {
if ($info['option'] === self::OPTION_REQUIRED && !isset($this->options[$option])) {
die("The option `{$option}` is required to be given.\n {$info['comment']}\n {$info['description']}\n Example: {$info['example']}\n");
}
}
} | [
"private",
"function",
"enforceOptions",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"validShortOptions",
"as",
"$",
"option",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"'option'",
"]",
"===",
"self",
"::",
"OPTION_REQUIRED",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
")",
")",
"{",
"die",
"(",
"\"The option `{$option}` is required to be given.\\n\t{$info['comment']}\\n\t{$info['description']}\\n\tExample: {$info['example']}\\n\"",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"validLongOptions",
"as",
"$",
"option",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"'option'",
"]",
"===",
"self",
"::",
"OPTION_REQUIRED",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
")",
")",
"{",
"die",
"(",
"\"The option `{$option}` is required to be given.\\n\t{$info['comment']}\\n\t{$info['description']}\\n\tExample: {$info['example']}\\n\"",
")",
";",
"}",
"}",
"}"
] | Enforce usage of required options.
@access private
@return void | [
"Enforce",
"usage",
"of",
"required",
"options",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/classes/options.php#L217-L228 | train |
Alexia/php7mar | mar.php | main.run | private function run() {
$issues = [];
$totalFiles = 0;
$totalLines = 0;
$filePath = $this->scanner->getCurrentFilePath();
if (!$this->options->getOption('t') || in_array('syntax', $this->options->getOption('t'), true)) {
$checkSyntax = true;
$versionGood = $this->tests->getPHPVersion();
if (!$versionGood) {
$this->reporter->add("ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.", 0, 1);
}
} else {
$checkSyntax = false;
}
while (($lines = $this->scanner->scanNextFile()) !== false) {
$totalFiles++;
//Check syntax and assign a line to grab if needed.
$grabLineNumber = null;
$grabLine = null;
if ($checkSyntax) {
$syntax = $this->tests->checkSyntax($filePath);
if (!isset($syntax['is_valid'])) {
$grabLineNumber = $syntax['line'];
}
}
foreach ($lines as $index => $line) {
$lineNumber = $index + 1;
$line = trim($line, "\r\n");
if ($lineNumber == $grabLineNumber) {
$grabLine = $line;
}
$totalLines++;
$issues = $this->tests->testLine($line);
foreach ($issues as $section => $tests) {
foreach ($tests as $test => $true) {
$this->reporter->addToSection($section, $test, $filePath, $lineNumber, $line);
}
}
}
if ($checkSyntax && $grabLine !== null) {
$this->reporter->addToSection('syntax', 'syntax', $filePath, $grabLineNumber, $grabLine.' //'.$syntax['error']);
}
$filePath = $this->scanner->getCurrentFilePath();
}
$this->reporter->add("Processed {$totalLines} lines contained in {$totalFiles} files.", 0, 1);
} | php | private function run() {
$issues = [];
$totalFiles = 0;
$totalLines = 0;
$filePath = $this->scanner->getCurrentFilePath();
if (!$this->options->getOption('t') || in_array('syntax', $this->options->getOption('t'), true)) {
$checkSyntax = true;
$versionGood = $this->tests->getPHPVersion();
if (!$versionGood) {
$this->reporter->add("ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.", 0, 1);
}
} else {
$checkSyntax = false;
}
while (($lines = $this->scanner->scanNextFile()) !== false) {
$totalFiles++;
//Check syntax and assign a line to grab if needed.
$grabLineNumber = null;
$grabLine = null;
if ($checkSyntax) {
$syntax = $this->tests->checkSyntax($filePath);
if (!isset($syntax['is_valid'])) {
$grabLineNumber = $syntax['line'];
}
}
foreach ($lines as $index => $line) {
$lineNumber = $index + 1;
$line = trim($line, "\r\n");
if ($lineNumber == $grabLineNumber) {
$grabLine = $line;
}
$totalLines++;
$issues = $this->tests->testLine($line);
foreach ($issues as $section => $tests) {
foreach ($tests as $test => $true) {
$this->reporter->addToSection($section, $test, $filePath, $lineNumber, $line);
}
}
}
if ($checkSyntax && $grabLine !== null) {
$this->reporter->addToSection('syntax', 'syntax', $filePath, $grabLineNumber, $grabLine.' //'.$syntax['error']);
}
$filePath = $this->scanner->getCurrentFilePath();
}
$this->reporter->add("Processed {$totalLines} lines contained in {$totalFiles} files.", 0, 1);
} | [
"private",
"function",
"run",
"(",
")",
"{",
"$",
"issues",
"=",
"[",
"]",
";",
"$",
"totalFiles",
"=",
"0",
";",
"$",
"totalLines",
"=",
"0",
";",
"$",
"filePath",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getCurrentFilePath",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
"->",
"getOption",
"(",
"'t'",
")",
"||",
"in_array",
"(",
"'syntax'",
",",
"$",
"this",
"->",
"options",
"->",
"getOption",
"(",
"'t'",
")",
",",
"true",
")",
")",
"{",
"$",
"checkSyntax",
"=",
"true",
";",
"$",
"versionGood",
"=",
"$",
"this",
"->",
"tests",
"->",
"getPHPVersion",
"(",
")",
";",
"if",
"(",
"!",
"$",
"versionGood",
")",
"{",
"$",
"this",
"->",
"reporter",
"->",
"add",
"(",
"\"ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.\"",
",",
"0",
",",
"1",
")",
";",
"}",
"}",
"else",
"{",
"$",
"checkSyntax",
"=",
"false",
";",
"}",
"while",
"(",
"(",
"$",
"lines",
"=",
"$",
"this",
"->",
"scanner",
"->",
"scanNextFile",
"(",
")",
")",
"!==",
"false",
")",
"{",
"$",
"totalFiles",
"++",
";",
"//Check syntax and assign a line to grab if needed.",
"$",
"grabLineNumber",
"=",
"null",
";",
"$",
"grabLine",
"=",
"null",
";",
"if",
"(",
"$",
"checkSyntax",
")",
"{",
"$",
"syntax",
"=",
"$",
"this",
"->",
"tests",
"->",
"checkSyntax",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"syntax",
"[",
"'is_valid'",
"]",
")",
")",
"{",
"$",
"grabLineNumber",
"=",
"$",
"syntax",
"[",
"'line'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"index",
"=>",
"$",
"line",
")",
"{",
"$",
"lineNumber",
"=",
"$",
"index",
"+",
"1",
";",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
",",
"\"\\r\\n\"",
")",
";",
"if",
"(",
"$",
"lineNumber",
"==",
"$",
"grabLineNumber",
")",
"{",
"$",
"grabLine",
"=",
"$",
"line",
";",
"}",
"$",
"totalLines",
"++",
";",
"$",
"issues",
"=",
"$",
"this",
"->",
"tests",
"->",
"testLine",
"(",
"$",
"line",
")",
";",
"foreach",
"(",
"$",
"issues",
"as",
"$",
"section",
"=>",
"$",
"tests",
")",
"{",
"foreach",
"(",
"$",
"tests",
"as",
"$",
"test",
"=>",
"$",
"true",
")",
"{",
"$",
"this",
"->",
"reporter",
"->",
"addToSection",
"(",
"$",
"section",
",",
"$",
"test",
",",
"$",
"filePath",
",",
"$",
"lineNumber",
",",
"$",
"line",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"checkSyntax",
"&&",
"$",
"grabLine",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"reporter",
"->",
"addToSection",
"(",
"'syntax'",
",",
"'syntax'",
",",
"$",
"filePath",
",",
"$",
"grabLineNumber",
",",
"$",
"grabLine",
".",
"' //'",
".",
"$",
"syntax",
"[",
"'error'",
"]",
")",
";",
"}",
"$",
"filePath",
"=",
"$",
"this",
"->",
"scanner",
"->",
"getCurrentFilePath",
"(",
")",
";",
"}",
"$",
"this",
"->",
"reporter",
"->",
"add",
"(",
"\"Processed {$totalLines} lines contained in {$totalFiles} files.\"",
",",
"0",
",",
"1",
")",
";",
"}"
] | Run tests, generator report sections.
@access private
@return void | [
"Run",
"tests",
"generator",
"report",
"sections",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/mar.php#L102-L153 | train |
Alexia/php7mar | mar.php | main.getRealPath | static public function getRealPath($path) {
if (strpos($path, '~') === 0) {
$path = substr_replace($path, $_SERVER['HOME'], 0, 1);
}
$_path = realpath($path);
if (!empty($path) && $_path !== false) {
return rtrim($_path, DIRECTORY_SEPARATOR);
}
return false;
} | php | static public function getRealPath($path) {
if (strpos($path, '~') === 0) {
$path = substr_replace($path, $_SERVER['HOME'], 0, 1);
}
$_path = realpath($path);
if (!empty($path) && $_path !== false) {
return rtrim($_path, DIRECTORY_SEPARATOR);
}
return false;
} | [
"static",
"public",
"function",
"getRealPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'~'",
")",
"===",
"0",
")",
"{",
"$",
"path",
"=",
"substr_replace",
"(",
"$",
"path",
",",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
",",
"0",
",",
"1",
")",
";",
"}",
"$",
"_path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
"&&",
"$",
"_path",
"!==",
"false",
")",
"{",
"return",
"rtrim",
"(",
"$",
"_path",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get a full real path name to a given path.
@access public
@param string File/Folder Path
@return mixed File/Folder path or false on error. | [
"Get",
"a",
"full",
"real",
"path",
"name",
"to",
"a",
"given",
"path",
"."
] | 9c3e0850542f332d10668ce94dd59fb0edcef475 | https://github.com/Alexia/php7mar/blob/9c3e0850542f332d10668ce94dd59fb0edcef475/mar.php#L177-L187 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Uninstall.php | Uninstall.getExtensionEntity | protected function getExtensionEntity()
{
if (!isset($this->extensionEntity)) {
$processId = $this->getProcessId();
$this->extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
if (!isset($this->extensionEntity)) {
throw new Error('Extension Entity not found.');
}
}
return $this->extensionEntity;
} | php | protected function getExtensionEntity()
{
if (!isset($this->extensionEntity)) {
$processId = $this->getProcessId();
$this->extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
if (!isset($this->extensionEntity)) {
throw new Error('Extension Entity not found.');
}
}
return $this->extensionEntity;
} | [
"protected",
"function",
"getExtensionEntity",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"extensionEntity",
")",
")",
"{",
"$",
"processId",
"=",
"$",
"this",
"->",
"getProcessId",
"(",
")",
";",
"$",
"this",
"->",
"extensionEntity",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getEntity",
"(",
"'Extension'",
",",
"$",
"processId",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"extensionEntity",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Extension Entity not found.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"extensionEntity",
";",
"}"
] | Get entity of this extension
@return \Espo\Entities\Extension | [
"Get",
"entity",
"of",
"this",
"extension"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Uninstall.php#L42-L53 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP/Utils.php | Utils.normalizeOptions | public function normalizeOptions(array $options)
{
$options['useSsl'] = (bool) ($options['useSsl'] == 'SSL');
$options['useStartTls'] = (bool) ($options['useStartTls'] == 'TLS');
$options['accountCanonicalForm'] = $this->accountCanonicalFormMap[ $options['accountCanonicalForm'] ];
return $options;
} | php | public function normalizeOptions(array $options)
{
$options['useSsl'] = (bool) ($options['useSsl'] == 'SSL');
$options['useStartTls'] = (bool) ($options['useStartTls'] == 'TLS');
$options['accountCanonicalForm'] = $this->accountCanonicalFormMap[ $options['accountCanonicalForm'] ];
return $options;
} | [
"public",
"function",
"normalizeOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"options",
"[",
"'useSsl'",
"]",
"=",
"(",
"bool",
")",
"(",
"$",
"options",
"[",
"'useSsl'",
"]",
"==",
"'SSL'",
")",
";",
"$",
"options",
"[",
"'useStartTls'",
"]",
"=",
"(",
"bool",
")",
"(",
"$",
"options",
"[",
"'useStartTls'",
"]",
"==",
"'TLS'",
")",
";",
"$",
"options",
"[",
"'accountCanonicalForm'",
"]",
"=",
"$",
"this",
"->",
"accountCanonicalFormMap",
"[",
"$",
"options",
"[",
"'accountCanonicalForm'",
"]",
"]",
";",
"return",
"$",
"options",
";",
"}"
] | Normalize options to LDAP client format
@param array $options
@return array | [
"Normalize",
"options",
"to",
"LDAP",
"client",
"format"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP/Utils.php#L154-L161 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP/Utils.php | Utils.getOption | public function getOption($name, $returns = null)
{
if (!isset($this->options)) {
$this->getOptions();
}
if (isset($this->options[$name])) {
return $this->options[$name];
}
return $returns;
} | php | public function getOption($name, $returns = null)
{
if (!isset($this->options)) {
$this->getOptions();
}
if (isset($this->options[$name])) {
return $this->options[$name];
}
return $returns;
} | [
"public",
"function",
"getOption",
"(",
"$",
"name",
",",
"$",
"returns",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
")",
")",
"{",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"returns",
";",
"}"
] | Get an ldap option
@param string $name
@param mixed $returns Return value
@return mixed | [
"Get",
"an",
"ldap",
"option"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP/Utils.php#L170-L181 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP/Utils.php | Utils.getLdapClientOptions | public function getLdapClientOptions()
{
$options = $this->getOptions();
$zendOptions = array_diff_key($options, array_flip($this->permittedEspoOptions));
return $zendOptions;
} | php | public function getLdapClientOptions()
{
$options = $this->getOptions();
$zendOptions = array_diff_key($options, array_flip($this->permittedEspoOptions));
return $zendOptions;
} | [
"public",
"function",
"getLdapClientOptions",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"zendOptions",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"array_flip",
"(",
"$",
"this",
"->",
"permittedEspoOptions",
")",
")",
";",
"return",
"$",
"zendOptions",
";",
"}"
] | Get Zend options for using Zend\Ldap
@return array | [
"Get",
"Zend",
"options",
"for",
"using",
"Zend",
"\\",
"Ldap"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP/Utils.php#L188-L194 | train |
espocrm/espocrm | application/Espo/Services/AdminNotifications.php | AdminNotifications.jobCheckNewVersion | public function jobCheckNewVersion($data)
{
$config = $this->getConfig();
if (!$config->get('adminNotifications') || !$config->get('adminNotificationsNewVersion')) {
return true;
}
$latestRelease = $this->getLatestRelease();
if (empty($latestRelease['version'])) {
$config->set('latestVersion', $latestRelease['version']);
$config->save();
return true;
}
if ($config->get('latestVersion') != $latestRelease['version']) {
$config->set('latestVersion', $latestRelease['version']);
if (!empty($latestRelease['notes'])) {
//todo: create notification
}
$config->save();
return true;
}
if (!empty($latestRelease['notes'])) {
//todo: find and modify notification
}
return true;
} | php | public function jobCheckNewVersion($data)
{
$config = $this->getConfig();
if (!$config->get('adminNotifications') || !$config->get('adminNotificationsNewVersion')) {
return true;
}
$latestRelease = $this->getLatestRelease();
if (empty($latestRelease['version'])) {
$config->set('latestVersion', $latestRelease['version']);
$config->save();
return true;
}
if ($config->get('latestVersion') != $latestRelease['version']) {
$config->set('latestVersion', $latestRelease['version']);
if (!empty($latestRelease['notes'])) {
//todo: create notification
}
$config->save();
return true;
}
if (!empty($latestRelease['notes'])) {
//todo: find and modify notification
}
return true;
} | [
"public",
"function",
"jobCheckNewVersion",
"(",
"$",
"data",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"if",
"(",
"!",
"$",
"config",
"->",
"get",
"(",
"'adminNotifications'",
")",
"||",
"!",
"$",
"config",
"->",
"get",
"(",
"'adminNotificationsNewVersion'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"latestRelease",
"=",
"$",
"this",
"->",
"getLatestRelease",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"latestRelease",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"config",
"->",
"set",
"(",
"'latestVersion'",
",",
"$",
"latestRelease",
"[",
"'version'",
"]",
")",
";",
"$",
"config",
"->",
"save",
"(",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'latestVersion'",
")",
"!=",
"$",
"latestRelease",
"[",
"'version'",
"]",
")",
"{",
"$",
"config",
"->",
"set",
"(",
"'latestVersion'",
",",
"$",
"latestRelease",
"[",
"'version'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"latestRelease",
"[",
"'notes'",
"]",
")",
")",
"{",
"//todo: create notification",
"}",
"$",
"config",
"->",
"save",
"(",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"latestRelease",
"[",
"'notes'",
"]",
")",
")",
"{",
"//todo: find and modify notification",
"}",
"return",
"true",
";",
"}"
] | Job for checking a new version of EspoCRM
@param object $data
@return boolean | [
"Job",
"for",
"checking",
"a",
"new",
"version",
"of",
"EspoCRM"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Services/AdminNotifications.php#L41-L72 | train |
espocrm/espocrm | application/Espo/Services/AdminNotifications.php | AdminNotifications.jobCheckNewExtensionVersion | public function jobCheckNewExtensionVersion($data)
{
$config = $this->getConfig();
if (!$config->get('adminNotifications') || !$config->get('adminNotificationsNewExtensionVersion')) {
return true;
}
$pdo = $this->getEntityManager()->getPDO();
$query = "
SELECT id, name, version, check_version_url as url
FROM extension
WHERE deleted = 0
AND is_installed = 1
ORDER BY created_at
";
$sth = $pdo->prepare($query);
$sth->execute();
$rowList = $sth->fetchAll(\PDO::FETCH_ASSOC);
$latestReleases = [];
foreach ($rowList as $row) {
$url = !empty($row['url']) ? $row['url'] : null;
$extensionName = $row['name'];
$latestRelease = $this->getLatestRelease($url, [
'name' => $extensionName,
]);
if (!empty($latestRelease) && !isset($latestRelease['error'])) {
$latestReleases[$extensionName] = $latestRelease;
}
}
$latestExtensionVersions = $config->get('latestExtensionVersions', []);
$save = false;
foreach ($latestReleases as $extensionName => $extensionData) {
if (empty($latestExtensionVersions[$extensionName])) {
$latestExtensionVersions[$extensionName] = $extensionData['version'];
$save = true;
continue;
}
if ($latestExtensionVersions[$extensionName] != $extensionData['version']) {
$latestExtensionVersions[$extensionName] = $extensionData['version'];
if (!empty($extensionData['notes'])) {
//todo: create notification
}
$save = true;
continue;
}
if (!empty($extensionData['notes'])) {
//todo: find and modify notification
}
}
if ($save) {
$config->set('latestExtensionVersions', $latestExtensionVersions);
$config->save();
}
return true;
} | php | public function jobCheckNewExtensionVersion($data)
{
$config = $this->getConfig();
if (!$config->get('adminNotifications') || !$config->get('adminNotificationsNewExtensionVersion')) {
return true;
}
$pdo = $this->getEntityManager()->getPDO();
$query = "
SELECT id, name, version, check_version_url as url
FROM extension
WHERE deleted = 0
AND is_installed = 1
ORDER BY created_at
";
$sth = $pdo->prepare($query);
$sth->execute();
$rowList = $sth->fetchAll(\PDO::FETCH_ASSOC);
$latestReleases = [];
foreach ($rowList as $row) {
$url = !empty($row['url']) ? $row['url'] : null;
$extensionName = $row['name'];
$latestRelease = $this->getLatestRelease($url, [
'name' => $extensionName,
]);
if (!empty($latestRelease) && !isset($latestRelease['error'])) {
$latestReleases[$extensionName] = $latestRelease;
}
}
$latestExtensionVersions = $config->get('latestExtensionVersions', []);
$save = false;
foreach ($latestReleases as $extensionName => $extensionData) {
if (empty($latestExtensionVersions[$extensionName])) {
$latestExtensionVersions[$extensionName] = $extensionData['version'];
$save = true;
continue;
}
if ($latestExtensionVersions[$extensionName] != $extensionData['version']) {
$latestExtensionVersions[$extensionName] = $extensionData['version'];
if (!empty($extensionData['notes'])) {
//todo: create notification
}
$save = true;
continue;
}
if (!empty($extensionData['notes'])) {
//todo: find and modify notification
}
}
if ($save) {
$config->set('latestExtensionVersions', $latestExtensionVersions);
$config->save();
}
return true;
} | [
"public",
"function",
"jobCheckNewExtensionVersion",
"(",
"$",
"data",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"if",
"(",
"!",
"$",
"config",
"->",
"get",
"(",
"'adminNotifications'",
")",
"||",
"!",
"$",
"config",
"->",
"get",
"(",
"'adminNotificationsNewExtensionVersion'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"pdo",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getPDO",
"(",
")",
";",
"$",
"query",
"=",
"\"\n SELECT id, name, version, check_version_url as url\n FROM extension\n WHERE deleted = 0\n AND is_installed = 1\n ORDER BY created_at\n \"",
";",
"$",
"sth",
"=",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"sth",
"->",
"execute",
"(",
")",
";",
"$",
"rowList",
"=",
"$",
"sth",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"latestReleases",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rowList",
"as",
"$",
"row",
")",
"{",
"$",
"url",
"=",
"!",
"empty",
"(",
"$",
"row",
"[",
"'url'",
"]",
")",
"?",
"$",
"row",
"[",
"'url'",
"]",
":",
"null",
";",
"$",
"extensionName",
"=",
"$",
"row",
"[",
"'name'",
"]",
";",
"$",
"latestRelease",
"=",
"$",
"this",
"->",
"getLatestRelease",
"(",
"$",
"url",
",",
"[",
"'name'",
"=>",
"$",
"extensionName",
",",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"latestRelease",
")",
"&&",
"!",
"isset",
"(",
"$",
"latestRelease",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"latestReleases",
"[",
"$",
"extensionName",
"]",
"=",
"$",
"latestRelease",
";",
"}",
"}",
"$",
"latestExtensionVersions",
"=",
"$",
"config",
"->",
"get",
"(",
"'latestExtensionVersions'",
",",
"[",
"]",
")",
";",
"$",
"save",
"=",
"false",
";",
"foreach",
"(",
"$",
"latestReleases",
"as",
"$",
"extensionName",
"=>",
"$",
"extensionData",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"latestExtensionVersions",
"[",
"$",
"extensionName",
"]",
")",
")",
"{",
"$",
"latestExtensionVersions",
"[",
"$",
"extensionName",
"]",
"=",
"$",
"extensionData",
"[",
"'version'",
"]",
";",
"$",
"save",
"=",
"true",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"latestExtensionVersions",
"[",
"$",
"extensionName",
"]",
"!=",
"$",
"extensionData",
"[",
"'version'",
"]",
")",
"{",
"$",
"latestExtensionVersions",
"[",
"$",
"extensionName",
"]",
"=",
"$",
"extensionData",
"[",
"'version'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"extensionData",
"[",
"'notes'",
"]",
")",
")",
"{",
"//todo: create notification",
"}",
"$",
"save",
"=",
"true",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"extensionData",
"[",
"'notes'",
"]",
")",
")",
"{",
"//todo: find and modify notification",
"}",
"}",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"config",
"->",
"set",
"(",
"'latestExtensionVersions'",
",",
"$",
"latestExtensionVersions",
")",
";",
"$",
"config",
"->",
"save",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Job for cheking a new version of installed extensions
@param object $data
@return boolean | [
"Job",
"for",
"cheking",
"a",
"new",
"version",
"of",
"installed",
"extensions"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Services/AdminNotifications.php#L81-L152 | train |
espocrm/espocrm | application/Espo/Core/Utils/Language.php | Language.getData | protected function getData()
{
$currentLanguage = $this->getLanguage();
if (!isset($this->data[$currentLanguage])) {
$this->init();
}
return $this->data[$currentLanguage];
} | php | protected function getData()
{
$currentLanguage = $this->getLanguage();
if (!isset($this->data[$currentLanguage])) {
$this->init();
}
return $this->data[$currentLanguage];
} | [
"protected",
"function",
"getData",
"(",
")",
"{",
"$",
"currentLanguage",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"currentLanguage",
"]",
")",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"currentLanguage",
"]",
";",
"}"
] | Get data of Unifier language files
@return array | [
"Get",
"data",
"of",
"Unifier",
"language",
"files"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Language.php#L263-L271 | train |
espocrm/espocrm | application/Espo/Core/Utils/Language.php | Language.delete | public function delete($scope, $category, $name)
{
if (is_array($name)) {
foreach ($name as $rowLabel) {
$this->delete($scope, $category, $rowLabel);
}
return;
}
$this->deletedData[$scope][$category][] = $name;
$currentLanguage = $this->getLanguage();
if (!isset($this->data[$currentLanguage])) {
$this->init();
}
if (isset($this->data[$currentLanguage][$scope][$category][$name])) {
unset($this->data[$currentLanguage][$scope][$category][$name]);
}
if (isset($this->changedData[$scope][$category][$name])) {
unset($this->changedData[$scope][$category][$name]);
}
} | php | public function delete($scope, $category, $name)
{
if (is_array($name)) {
foreach ($name as $rowLabel) {
$this->delete($scope, $category, $rowLabel);
}
return;
}
$this->deletedData[$scope][$category][] = $name;
$currentLanguage = $this->getLanguage();
if (!isset($this->data[$currentLanguage])) {
$this->init();
}
if (isset($this->data[$currentLanguage][$scope][$category][$name])) {
unset($this->data[$currentLanguage][$scope][$category][$name]);
}
if (isset($this->changedData[$scope][$category][$name])) {
unset($this->changedData[$scope][$category][$name]);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"scope",
",",
"$",
"category",
",",
"$",
"name",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"rowLabel",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"scope",
",",
"$",
"category",
",",
"$",
"rowLabel",
")",
";",
"}",
"return",
";",
"}",
"$",
"this",
"->",
"deletedData",
"[",
"$",
"scope",
"]",
"[",
"$",
"category",
"]",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"currentLanguage",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"currentLanguage",
"]",
")",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"currentLanguage",
"]",
"[",
"$",
"scope",
"]",
"[",
"$",
"category",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"currentLanguage",
"]",
"[",
"$",
"scope",
"]",
"[",
"$",
"category",
"]",
"[",
"$",
"name",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"changedData",
"[",
"$",
"scope",
"]",
"[",
"$",
"category",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"changedData",
"[",
"$",
"scope",
"]",
"[",
"$",
"category",
"]",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}"
] | Remove a label
@param string $name
@param string $category
@param string $scope
@return void | [
"Remove",
"a",
"label"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Language.php#L312-L335 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/RelationManager.php | RelationManager.getForeignLink | private function getForeignLink($parentLinkName, $parentLinkParams, $currentEntityDefs)
{
if (isset($parentLinkParams['foreign']) && isset($currentEntityDefs['links'][$parentLinkParams['foreign']])) {
return array(
'name' => $parentLinkParams['foreign'],
'params' => $currentEntityDefs['links'][$parentLinkParams['foreign']],
);
}
return false;
} | php | private function getForeignLink($parentLinkName, $parentLinkParams, $currentEntityDefs)
{
if (isset($parentLinkParams['foreign']) && isset($currentEntityDefs['links'][$parentLinkParams['foreign']])) {
return array(
'name' => $parentLinkParams['foreign'],
'params' => $currentEntityDefs['links'][$parentLinkParams['foreign']],
);
}
return false;
} | [
"private",
"function",
"getForeignLink",
"(",
"$",
"parentLinkName",
",",
"$",
"parentLinkParams",
",",
"$",
"currentEntityDefs",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parentLinkParams",
"[",
"'foreign'",
"]",
")",
"&&",
"isset",
"(",
"$",
"currentEntityDefs",
"[",
"'links'",
"]",
"[",
"$",
"parentLinkParams",
"[",
"'foreign'",
"]",
"]",
")",
")",
"{",
"return",
"array",
"(",
"'name'",
"=>",
"$",
"parentLinkParams",
"[",
"'foreign'",
"]",
",",
"'params'",
"=>",
"$",
"currentEntityDefs",
"[",
"'links'",
"]",
"[",
"$",
"parentLinkParams",
"[",
"'foreign'",
"]",
"]",
",",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get foreign Link
@param string $parentLinkName
@param array $parentLinkParams
@param array $currentEntityDefs
@return array - in format array('name', 'params') | [
"Get",
"foreign",
"Link"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/RelationManager.php#L94-L104 | train |
espocrm/espocrm | application/Espo/Core/Utils/ScheduledJob.php | ScheduledJob.getClassName | protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
$data = $this->getAll();
$name = ucfirst($name);
if (isset($data[$name])) {
return $data[$name];
}
return false;
} | php | protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
$data = $this->getAll();
$name = ucfirst($name);
if (isset($data[$name])) {
return $data[$name];
}
return false;
} | [
"protected",
"function",
"getClassName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"Util",
"::",
"normilizeClassName",
"(",
"$",
"name",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"$",
"name",
"=",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Get class name of a job
@param string $name
@return string | [
"Get",
"class",
"name",
"of",
"a",
"job"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/ScheduledJob.php#L151-L163 | train |
espocrm/espocrm | application/Espo/Core/Utils/ScheduledJob.php | ScheduledJob.isCronConfigured | public function isCronConfigured()
{
$r1From = new \DateTime('-' . $this->checkingCronPeriod);
$r1To = new \DateTime('+' . $this->checkingCronPeriod);
$r2From = new \DateTime('- 1 hour');
$r2To = new \DateTime();
$format = \Espo\Core\Utils\DateTime::$systemDateTimeFormat;
$selectParams = [
'select' => ['id'],
'leftJoins' => ['scheduledJob'],
'whereClause' => [
'OR' => [
[
['executedAt>=' => $r2From->format($format)] ,
['executedAt<=' => $r2To->format($format)],
],
[
['executeTime>=' => $r1From->format($format)],
['executeTime<='=> $r1To->format($format)],
'scheduledJob.job' => 'Dummy'
]
]
]
];
return !!$this->getEntityManager()->getRepository('Job')->findOne($selectParams);
} | php | public function isCronConfigured()
{
$r1From = new \DateTime('-' . $this->checkingCronPeriod);
$r1To = new \DateTime('+' . $this->checkingCronPeriod);
$r2From = new \DateTime('- 1 hour');
$r2To = new \DateTime();
$format = \Espo\Core\Utils\DateTime::$systemDateTimeFormat;
$selectParams = [
'select' => ['id'],
'leftJoins' => ['scheduledJob'],
'whereClause' => [
'OR' => [
[
['executedAt>=' => $r2From->format($format)] ,
['executedAt<=' => $r2To->format($format)],
],
[
['executeTime>=' => $r1From->format($format)],
['executeTime<='=> $r1To->format($format)],
'scheduledJob.job' => 'Dummy'
]
]
]
];
return !!$this->getEntityManager()->getRepository('Job')->findOne($selectParams);
} | [
"public",
"function",
"isCronConfigured",
"(",
")",
"{",
"$",
"r1From",
"=",
"new",
"\\",
"DateTime",
"(",
"'-'",
".",
"$",
"this",
"->",
"checkingCronPeriod",
")",
";",
"$",
"r1To",
"=",
"new",
"\\",
"DateTime",
"(",
"'+'",
".",
"$",
"this",
"->",
"checkingCronPeriod",
")",
";",
"$",
"r2From",
"=",
"new",
"\\",
"DateTime",
"(",
"'- 1 hour'",
")",
";",
"$",
"r2To",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"format",
"=",
"\\",
"Espo",
"\\",
"Core",
"\\",
"Utils",
"\\",
"DateTime",
"::",
"$",
"systemDateTimeFormat",
";",
"$",
"selectParams",
"=",
"[",
"'select'",
"=>",
"[",
"'id'",
"]",
",",
"'leftJoins'",
"=>",
"[",
"'scheduledJob'",
"]",
",",
"'whereClause'",
"=>",
"[",
"'OR'",
"=>",
"[",
"[",
"[",
"'executedAt>='",
"=>",
"$",
"r2From",
"->",
"format",
"(",
"$",
"format",
")",
"]",
",",
"[",
"'executedAt<='",
"=>",
"$",
"r2To",
"->",
"format",
"(",
"$",
"format",
")",
"]",
",",
"]",
",",
"[",
"[",
"'executeTime>='",
"=>",
"$",
"r1From",
"->",
"format",
"(",
"$",
"format",
")",
"]",
",",
"[",
"'executeTime<='",
"=>",
"$",
"r1To",
"->",
"format",
"(",
"$",
"format",
")",
"]",
",",
"'scheduledJob.job'",
"=>",
"'Dummy'",
"]",
"]",
"]",
"]",
";",
"return",
"!",
"!",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'Job'",
")",
"->",
"findOne",
"(",
"$",
"selectParams",
")",
";",
"}"
] | Check if crontab is configured properly
@return boolean | [
"Check",
"if",
"crontab",
"is",
"configured",
"properly"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/ScheduledJob.php#L209-L239 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.loginByToken | protected function loginByToken($username, \Espo\Entities\AuthToken $authToken = null)
{
if (!isset($authToken)) {
return null;
}
$userId = $authToken->get('userId');
$user = $this->getEntityManager()->getEntity('User', $userId);
$tokenUsername = $user->get('userName');
if (strtolower($username) != strtolower($tokenUsername)) {
$GLOBALS['log']->alert('Unauthorized access attempt for user ['.$username.'] from IP ['.$_SERVER['REMOTE_ADDR'].']');
return null;
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
)
));
return $user;
} | php | protected function loginByToken($username, \Espo\Entities\AuthToken $authToken = null)
{
if (!isset($authToken)) {
return null;
}
$userId = $authToken->get('userId');
$user = $this->getEntityManager()->getEntity('User', $userId);
$tokenUsername = $user->get('userName');
if (strtolower($username) != strtolower($tokenUsername)) {
$GLOBALS['log']->alert('Unauthorized access attempt for user ['.$username.'] from IP ['.$_SERVER['REMOTE_ADDR'].']');
return null;
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
)
));
return $user;
} | [
"protected",
"function",
"loginByToken",
"(",
"$",
"username",
",",
"\\",
"Espo",
"\\",
"Entities",
"\\",
"AuthToken",
"$",
"authToken",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"authToken",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"userId",
"=",
"$",
"authToken",
"->",
"get",
"(",
"'userId'",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getEntity",
"(",
"'User'",
",",
"$",
"userId",
")",
";",
"$",
"tokenUsername",
"=",
"$",
"user",
"->",
"get",
"(",
"'userName'",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"username",
")",
"!=",
"strtolower",
"(",
"$",
"tokenUsername",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"alert",
"(",
"'Unauthorized access attempt for user ['",
".",
"$",
"username",
".",
"'] from IP ['",
".",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
".",
"']'",
")",
";",
"return",
"null",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'User'",
")",
"->",
"findOne",
"(",
"array",
"(",
"'whereClause'",
"=>",
"array",
"(",
"'userName'",
"=>",
"$",
"username",
",",
")",
")",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Login by authorization token
@param string $username
@param \Espo\Entities\AuthToken $authToken
@return \Espo\Entities\User | null | [
"Login",
"by",
"authorization",
"token"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L198-L220 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.adminLogin | protected function adminLogin($username, $password)
{
$hash = $this->getPasswordHash()->hash($password);
$user = $this->getEntityManager()->getRepository('User')->findOne([
'whereClause' => [
'userName' => $username,
'password' => $hash,
'type' => ['admin', 'super-admin']
]
]);
return $user;
} | php | protected function adminLogin($username, $password)
{
$hash = $this->getPasswordHash()->hash($password);
$user = $this->getEntityManager()->getRepository('User')->findOne([
'whereClause' => [
'userName' => $username,
'password' => $hash,
'type' => ['admin', 'super-admin']
]
]);
return $user;
} | [
"protected",
"function",
"adminLogin",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"getPasswordHash",
"(",
")",
"->",
"hash",
"(",
"$",
"password",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'User'",
")",
"->",
"findOne",
"(",
"[",
"'whereClause'",
"=>",
"[",
"'userName'",
"=>",
"$",
"username",
",",
"'password'",
"=>",
"$",
"hash",
",",
"'type'",
"=>",
"[",
"'admin'",
",",
"'super-admin'",
"]",
"]",
"]",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Login user with administrator rights
@param string $username
@param string $password
@return \Espo\Entities\User | null | [
"Login",
"user",
"with",
"administrator",
"rights"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L229-L242 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.createUser | protected function createUser(array $userData, $isPortal = false)
{
$GLOBALS['log']->info('Creating new user ...');
$data = array();
// show full array of the LDAP user
$GLOBALS['log']->debug('LDAP: user data: ' .print_r($userData, true));
//set values from ldap server
$ldapFields = $this->loadFields('ldap');
foreach ($ldapFields as $espo => $ldap) {
$ldap = strtolower($ldap);
if (isset($userData[$ldap][0])) {
$GLOBALS['log']->debug('LDAP: Create a user wtih ['.$espo.'] = ['.$userData[$ldap][0].'].');
$data[$espo] = $userData[$ldap][0];
}
}
//set user fields
if ($isPortal) {
$userFields = $this->loadFields('portalUser');
$userFields['type'] = 'portal';
} else {
$userFields = $this->loadFields('user');
}
foreach ($userFields as $fieldName => $fieldValue) {
$data[$fieldName] = $fieldValue;
}
$this->getAuth()->useNoAuth();
$user = $this->getEntityManager()->getEntity('User');
$user->set($data);
$this->getEntityManager()->saveEntity($user);
return $this->getEntityManager()->getEntity('User', $user->id);
} | php | protected function createUser(array $userData, $isPortal = false)
{
$GLOBALS['log']->info('Creating new user ...');
$data = array();
// show full array of the LDAP user
$GLOBALS['log']->debug('LDAP: user data: ' .print_r($userData, true));
//set values from ldap server
$ldapFields = $this->loadFields('ldap');
foreach ($ldapFields as $espo => $ldap) {
$ldap = strtolower($ldap);
if (isset($userData[$ldap][0])) {
$GLOBALS['log']->debug('LDAP: Create a user wtih ['.$espo.'] = ['.$userData[$ldap][0].'].');
$data[$espo] = $userData[$ldap][0];
}
}
//set user fields
if ($isPortal) {
$userFields = $this->loadFields('portalUser');
$userFields['type'] = 'portal';
} else {
$userFields = $this->loadFields('user');
}
foreach ($userFields as $fieldName => $fieldValue) {
$data[$fieldName] = $fieldValue;
}
$this->getAuth()->useNoAuth();
$user = $this->getEntityManager()->getEntity('User');
$user->set($data);
$this->getEntityManager()->saveEntity($user);
return $this->getEntityManager()->getEntity('User', $user->id);
} | [
"protected",
"function",
"createUser",
"(",
"array",
"$",
"userData",
",",
"$",
"isPortal",
"=",
"false",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"info",
"(",
"'Creating new user ...'",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"// show full array of the LDAP user",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'LDAP: user data: '",
".",
"print_r",
"(",
"$",
"userData",
",",
"true",
")",
")",
";",
"//set values from ldap server",
"$",
"ldapFields",
"=",
"$",
"this",
"->",
"loadFields",
"(",
"'ldap'",
")",
";",
"foreach",
"(",
"$",
"ldapFields",
"as",
"$",
"espo",
"=>",
"$",
"ldap",
")",
"{",
"$",
"ldap",
"=",
"strtolower",
"(",
"$",
"ldap",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"userData",
"[",
"$",
"ldap",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'LDAP: Create a user wtih ['",
".",
"$",
"espo",
".",
"'] = ['",
".",
"$",
"userData",
"[",
"$",
"ldap",
"]",
"[",
"0",
"]",
".",
"'].'",
")",
";",
"$",
"data",
"[",
"$",
"espo",
"]",
"=",
"$",
"userData",
"[",
"$",
"ldap",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"//set user fields",
"if",
"(",
"$",
"isPortal",
")",
"{",
"$",
"userFields",
"=",
"$",
"this",
"->",
"loadFields",
"(",
"'portalUser'",
")",
";",
"$",
"userFields",
"[",
"'type'",
"]",
"=",
"'portal'",
";",
"}",
"else",
"{",
"$",
"userFields",
"=",
"$",
"this",
"->",
"loadFields",
"(",
"'user'",
")",
";",
"}",
"foreach",
"(",
"$",
"userFields",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldValue",
")",
"{",
"$",
"data",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"fieldValue",
";",
"}",
"$",
"this",
"->",
"getAuth",
"(",
")",
"->",
"useNoAuth",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getEntity",
"(",
"'User'",
")",
";",
"$",
"user",
"->",
"set",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"saveEntity",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getEntity",
"(",
"'User'",
",",
"$",
"user",
"->",
"id",
")",
";",
"}"
] | Create Espo user with data gets from LDAP server
@param array $userData LDAP entity data
@param boolean $isPortal Is portal user
@return \Espo\Entities\User | [
"Create",
"Espo",
"user",
"with",
"data",
"gets",
"from",
"LDAP",
"server"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L252-L290 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.findLdapUserDnByUsername | protected function findLdapUserDnByUsername($username)
{
$ldapClient = $this->getLdapClient();
$options = $this->getUtils()->getOptions();
$loginFilterString = '';
if (!empty($options['userLoginFilter'])) {
$loginFilterString = $this->convertToFilterFormat($options['userLoginFilter']);
}
$searchString = '(&(objectClass='.$options['userObjectClass'].')('.$options['userNameAttribute'].'='.$username.')'.$loginFilterString.')';
$result = $ldapClient->search($searchString, null, LDAP\Client::SEARCH_SCOPE_SUB);
$GLOBALS['log']->debug('LDAP: user search string: "' . $searchString . '"');
foreach ($result as $item) {
return $item["dn"];
}
} | php | protected function findLdapUserDnByUsername($username)
{
$ldapClient = $this->getLdapClient();
$options = $this->getUtils()->getOptions();
$loginFilterString = '';
if (!empty($options['userLoginFilter'])) {
$loginFilterString = $this->convertToFilterFormat($options['userLoginFilter']);
}
$searchString = '(&(objectClass='.$options['userObjectClass'].')('.$options['userNameAttribute'].'='.$username.')'.$loginFilterString.')';
$result = $ldapClient->search($searchString, null, LDAP\Client::SEARCH_SCOPE_SUB);
$GLOBALS['log']->debug('LDAP: user search string: "' . $searchString . '"');
foreach ($result as $item) {
return $item["dn"];
}
} | [
"protected",
"function",
"findLdapUserDnByUsername",
"(",
"$",
"username",
")",
"{",
"$",
"ldapClient",
"=",
"$",
"this",
"->",
"getLdapClient",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"getUtils",
"(",
")",
"->",
"getOptions",
"(",
")",
";",
"$",
"loginFilterString",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'userLoginFilter'",
"]",
")",
")",
"{",
"$",
"loginFilterString",
"=",
"$",
"this",
"->",
"convertToFilterFormat",
"(",
"$",
"options",
"[",
"'userLoginFilter'",
"]",
")",
";",
"}",
"$",
"searchString",
"=",
"'(&(objectClass='",
".",
"$",
"options",
"[",
"'userObjectClass'",
"]",
".",
"')('",
".",
"$",
"options",
"[",
"'userNameAttribute'",
"]",
".",
"'='",
".",
"$",
"username",
".",
"')'",
".",
"$",
"loginFilterString",
".",
"')'",
";",
"$",
"result",
"=",
"$",
"ldapClient",
"->",
"search",
"(",
"$",
"searchString",
",",
"null",
",",
"LDAP",
"\\",
"Client",
"::",
"SEARCH_SCOPE_SUB",
")",
";",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'LDAP: user search string: \"'",
".",
"$",
"searchString",
".",
"'\"'",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"[",
"\"dn\"",
"]",
";",
"}",
"}"
] | Find LDAP user DN by his username
@param string $username
@return string | null | [
"Find",
"LDAP",
"user",
"DN",
"by",
"his",
"username"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L299-L316 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.convertToFilterFormat | protected function convertToFilterFormat($filter)
{
$filter = trim($filter);
if (substr($filter, 0, 1) != '(') {
$filter = '(' . $filter;
}
if (substr($filter, -1) != ')') {
$filter = $filter . ')';
}
return $filter;
} | php | protected function convertToFilterFormat($filter)
{
$filter = trim($filter);
if (substr($filter, 0, 1) != '(') {
$filter = '(' . $filter;
}
if (substr($filter, -1) != ')') {
$filter = $filter . ')';
}
return $filter;
} | [
"protected",
"function",
"convertToFilterFormat",
"(",
"$",
"filter",
")",
"{",
"$",
"filter",
"=",
"trim",
"(",
"$",
"filter",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"filter",
",",
"0",
",",
"1",
")",
"!=",
"'('",
")",
"{",
"$",
"filter",
"=",
"'('",
".",
"$",
"filter",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"filter",
",",
"-",
"1",
")",
"!=",
"')'",
")",
"{",
"$",
"filter",
"=",
"$",
"filter",
".",
"')'",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] | Check and convert filter item into LDAP format
@param string $filter E.g. "memberof=CN=externalTesters,OU=groups,DC=espo,DC=local"
@return string | [
"Check",
"and",
"convert",
"filter",
"item",
"into",
"LDAP",
"format"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L325-L335 | train |
espocrm/espocrm | application/Espo/Core/Utils/Authentication/LDAP.php | LDAP.loadFields | protected function loadFields($type)
{
$options = $this->getUtils()->getOptions();
$typeMap = $type . 'FieldMap';
$fields = array();
foreach ($this->$typeMap as $fieldName => $fieldValue) {
if (isset($options[$fieldValue])) {
$fields[$fieldName] = $options[$fieldValue];
}
}
return $fields;
} | php | protected function loadFields($type)
{
$options = $this->getUtils()->getOptions();
$typeMap = $type . 'FieldMap';
$fields = array();
foreach ($this->$typeMap as $fieldName => $fieldValue) {
if (isset($options[$fieldValue])) {
$fields[$fieldName] = $options[$fieldValue];
}
}
return $fields;
} | [
"protected",
"function",
"loadFields",
"(",
"$",
"type",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getUtils",
"(",
")",
"->",
"getOptions",
"(",
")",
";",
"$",
"typeMap",
"=",
"$",
"type",
".",
"'FieldMap'",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"$",
"typeMap",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldValue",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"$",
"fieldValue",
"]",
")",
")",
"{",
"$",
"fields",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"options",
"[",
"$",
"fieldValue",
"]",
";",
"}",
"}",
"return",
"$",
"fields",
";",
"}"
] | Load fields for a user
@param string $type
@return array | [
"Load",
"fields",
"for",
"a",
"user"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Authentication/LDAP.php#L344-L358 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/FileUnifier.php | FileUnifier.unify | public function unify(array $paths, $isReturnModuleNames = false)
{
$data = $this->loadData($paths['corePath']);
if (!empty($paths['modulePath'])) {
$moduleDir = strstr($paths['modulePath'], '{*}', true);
$moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($moduleDir, false, '', false);
foreach ($moduleList as $moduleName) {
$moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']);
if ($isReturnModuleNames) {
if (!isset($data[$moduleName])) {
$data[$moduleName] = array();
}
$data[$moduleName] = Util::merge($data[$moduleName], $this->loadData($moduleFilePath));
continue;
}
$data = Util::merge($data, $this->loadData($moduleFilePath));
}
}
if (!empty($paths['customPath'])) {
$data = Util::merge($data, $this->loadData($paths['customPath']));
}
return $data;
} | php | public function unify(array $paths, $isReturnModuleNames = false)
{
$data = $this->loadData($paths['corePath']);
if (!empty($paths['modulePath'])) {
$moduleDir = strstr($paths['modulePath'], '{*}', true);
$moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($moduleDir, false, '', false);
foreach ($moduleList as $moduleName) {
$moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']);
if ($isReturnModuleNames) {
if (!isset($data[$moduleName])) {
$data[$moduleName] = array();
}
$data[$moduleName] = Util::merge($data[$moduleName], $this->loadData($moduleFilePath));
continue;
}
$data = Util::merge($data, $this->loadData($moduleFilePath));
}
}
if (!empty($paths['customPath'])) {
$data = Util::merge($data, $this->loadData($paths['customPath']));
}
return $data;
} | [
"public",
"function",
"unify",
"(",
"array",
"$",
"paths",
",",
"$",
"isReturnModuleNames",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"loadData",
"(",
"$",
"paths",
"[",
"'corePath'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
")",
"{",
"$",
"moduleDir",
"=",
"strstr",
"(",
"$",
"paths",
"[",
"'modulePath'",
"]",
",",
"'{*}'",
",",
"true",
")",
";",
"$",
"moduleList",
"=",
"isset",
"(",
"$",
"this",
"->",
"metadata",
")",
"?",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getModuleList",
"(",
")",
":",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getFileList",
"(",
"$",
"moduleDir",
",",
"false",
",",
"''",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"moduleList",
"as",
"$",
"moduleName",
")",
"{",
"$",
"moduleFilePath",
"=",
"str_replace",
"(",
"'{*}'",
",",
"$",
"moduleName",
",",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
";",
"if",
"(",
"$",
"isReturnModuleNames",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"moduleName",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"moduleName",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"data",
"[",
"$",
"moduleName",
"]",
"=",
"Util",
"::",
"merge",
"(",
"$",
"data",
"[",
"$",
"moduleName",
"]",
",",
"$",
"this",
"->",
"loadData",
"(",
"$",
"moduleFilePath",
")",
")",
";",
"continue",
";",
"}",
"$",
"data",
"=",
"Util",
"::",
"merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"loadData",
"(",
"$",
"moduleFilePath",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"Util",
"::",
"merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"loadData",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Unite files content
@param array $paths
@param bool $isReturnModuleNames - If need to return data with module names
@return array | [
"Unite",
"files",
"content"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/FileUnifier.php#L63-L91 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/FileUnifier.php | FileUnifier.loadData | protected function loadData($filePath, $returns = array())
{
if (file_exists($filePath)) {
$content = $this->getFileManager()->getContents($filePath);
$data = Json::getArrayData($content);
if (empty($data)) {
$GLOBALS['log']->warning('FileUnifier::unify() - Empty file or syntax error - ['.$filePath.']');
return $returns;
}
return $data;
}
return $returns;
} | php | protected function loadData($filePath, $returns = array())
{
if (file_exists($filePath)) {
$content = $this->getFileManager()->getContents($filePath);
$data = Json::getArrayData($content);
if (empty($data)) {
$GLOBALS['log']->warning('FileUnifier::unify() - Empty file or syntax error - ['.$filePath.']');
return $returns;
}
return $data;
}
return $returns;
} | [
"protected",
"function",
"loadData",
"(",
"$",
"filePath",
",",
"$",
"returns",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getContents",
"(",
"$",
"filePath",
")",
";",
"$",
"data",
"=",
"Json",
"::",
"getArrayData",
"(",
"$",
"content",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"warning",
"(",
"'FileUnifier::unify() - Empty file or syntax error - ['",
".",
"$",
"filePath",
".",
"']'",
")",
";",
"return",
"$",
"returns",
";",
"}",
"return",
"$",
"data",
";",
"}",
"return",
"$",
"returns",
";",
"}"
] | Load data from a file
@param string $filePath
@param array $returns
@return array | [
"Load",
"data",
"from",
"a",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/FileUnifier.php#L100-L114 | train |
espocrm/espocrm | application/Espo/Core/Utils/Cron/ScheduledJob.php | ScheduledJob.addLogRecord | public function addLogRecord($scheduledJobId, $status, $runTime = null, $targetId = null, $targetType = null)
{
if (!isset($runTime)) {
$runTime = date('Y-m-d H:i:s');
}
$entityManager = $this->getEntityManager();
$scheduledJob = $entityManager->getEntity('ScheduledJob', $scheduledJobId);
if (!$scheduledJob) {
return;
}
$scheduledJob->set('lastRun', $runTime);
$entityManager->saveEntity($scheduledJob, ['silent' => true]);
$scheduledJobLog = $entityManager->getEntity('ScheduledJobLogRecord');
$scheduledJobLog->set(array(
'scheduledJobId' => $scheduledJobId,
'name' => $scheduledJob->get('name'),
'status' => $status,
'executionTime' => $runTime,
'targetId' => $targetId,
'targetType' => $targetType
));
$scheduledJobLogId = $entityManager->saveEntity($scheduledJobLog);
return $scheduledJobLogId;
} | php | public function addLogRecord($scheduledJobId, $status, $runTime = null, $targetId = null, $targetType = null)
{
if (!isset($runTime)) {
$runTime = date('Y-m-d H:i:s');
}
$entityManager = $this->getEntityManager();
$scheduledJob = $entityManager->getEntity('ScheduledJob', $scheduledJobId);
if (!$scheduledJob) {
return;
}
$scheduledJob->set('lastRun', $runTime);
$entityManager->saveEntity($scheduledJob, ['silent' => true]);
$scheduledJobLog = $entityManager->getEntity('ScheduledJobLogRecord');
$scheduledJobLog->set(array(
'scheduledJobId' => $scheduledJobId,
'name' => $scheduledJob->get('name'),
'status' => $status,
'executionTime' => $runTime,
'targetId' => $targetId,
'targetType' => $targetType
));
$scheduledJobLogId = $entityManager->saveEntity($scheduledJobLog);
return $scheduledJobLogId;
} | [
"public",
"function",
"addLogRecord",
"(",
"$",
"scheduledJobId",
",",
"$",
"status",
",",
"$",
"runTime",
"=",
"null",
",",
"$",
"targetId",
"=",
"null",
",",
"$",
"targetType",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"runTime",
")",
")",
"{",
"$",
"runTime",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"scheduledJob",
"=",
"$",
"entityManager",
"->",
"getEntity",
"(",
"'ScheduledJob'",
",",
"$",
"scheduledJobId",
")",
";",
"if",
"(",
"!",
"$",
"scheduledJob",
")",
"{",
"return",
";",
"}",
"$",
"scheduledJob",
"->",
"set",
"(",
"'lastRun'",
",",
"$",
"runTime",
")",
";",
"$",
"entityManager",
"->",
"saveEntity",
"(",
"$",
"scheduledJob",
",",
"[",
"'silent'",
"=>",
"true",
"]",
")",
";",
"$",
"scheduledJobLog",
"=",
"$",
"entityManager",
"->",
"getEntity",
"(",
"'ScheduledJobLogRecord'",
")",
";",
"$",
"scheduledJobLog",
"->",
"set",
"(",
"array",
"(",
"'scheduledJobId'",
"=>",
"$",
"scheduledJobId",
",",
"'name'",
"=>",
"$",
"scheduledJob",
"->",
"get",
"(",
"'name'",
")",
",",
"'status'",
"=>",
"$",
"status",
",",
"'executionTime'",
"=>",
"$",
"runTime",
",",
"'targetId'",
"=>",
"$",
"targetId",
",",
"'targetType'",
"=>",
"$",
"targetType",
")",
")",
";",
"$",
"scheduledJobLogId",
"=",
"$",
"entityManager",
"->",
"saveEntity",
"(",
"$",
"scheduledJobLog",
")",
";",
"return",
"$",
"scheduledJobLogId",
";",
"}"
] | Add record to ScheduledJobLogRecord about executed job
@param string $scheduledJobId
@param string $status
@return string ID of created ScheduledJobLogRecord | [
"Add",
"record",
"to",
"ScheduledJobLogRecord",
"about",
"executed",
"job"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Cron/ScheduledJob.php#L79-L108 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata/Helper.php | Helper.getFieldDefsByType | public function getFieldDefsByType($fieldDef)
{
if (is_string($fieldDef)) {
$fieldDef = array('type' => $fieldDef);
}
if (isset($fieldDef['type'])) {
return $this->getMetadata()->get('fields.'.$fieldDef['type']);
}
return null;
} | php | public function getFieldDefsByType($fieldDef)
{
if (is_string($fieldDef)) {
$fieldDef = array('type' => $fieldDef);
}
if (isset($fieldDef['type'])) {
return $this->getMetadata()->get('fields.'.$fieldDef['type']);
}
return null;
} | [
"public",
"function",
"getFieldDefsByType",
"(",
"$",
"fieldDef",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"fieldDef",
")",
")",
"{",
"$",
"fieldDef",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"fieldDef",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fieldDef",
"[",
"'type'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"get",
"(",
"'fields.'",
".",
"$",
"fieldDef",
"[",
"'type'",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get field defenition by type in metadata, "fields" key
@param array | string $fieldDef - It can be a string or field defenition from entityDefs
@return array | null | [
"Get",
"field",
"defenition",
"by",
"type",
"in",
"metadata",
"fields",
"key"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata/Helper.php#L72-L83 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata/Helper.php | Helper.getAdditionalFieldList | public function getAdditionalFieldList($fieldName, array $fieldParams, array $definitionList)
{
if (empty($fieldParams['type']) || empty($definitionList)) {
return;
}
$fieldType = $fieldParams['type'];
$fieldDefinition = isset($definitionList[$fieldType]) ? $definitionList[$fieldType] : null;
if (isset($fieldDefinition) && !empty($fieldDefinition['fields']) && is_array($fieldDefinition['fields'])) {
$copiedParams = array_intersect_key($fieldParams, array_flip($this->copiedDefParams));
$additionalFields = array();
//add additional fields
foreach ($fieldDefinition['fields'] as $subFieldName => $subFieldParams) {
$namingType = isset($fieldDefinition['naming']) ? $fieldDefinition['naming'] : $this->defaultNaming;
$subFieldNaming = Util::getNaming($fieldName, $subFieldName, $namingType);
$additionalFields[$subFieldNaming] = array_merge($copiedParams, $subFieldParams);
}
return $additionalFields;
}
} | php | public function getAdditionalFieldList($fieldName, array $fieldParams, array $definitionList)
{
if (empty($fieldParams['type']) || empty($definitionList)) {
return;
}
$fieldType = $fieldParams['type'];
$fieldDefinition = isset($definitionList[$fieldType]) ? $definitionList[$fieldType] : null;
if (isset($fieldDefinition) && !empty($fieldDefinition['fields']) && is_array($fieldDefinition['fields'])) {
$copiedParams = array_intersect_key($fieldParams, array_flip($this->copiedDefParams));
$additionalFields = array();
//add additional fields
foreach ($fieldDefinition['fields'] as $subFieldName => $subFieldParams) {
$namingType = isset($fieldDefinition['naming']) ? $fieldDefinition['naming'] : $this->defaultNaming;
$subFieldNaming = Util::getNaming($fieldName, $subFieldName, $namingType);
$additionalFields[$subFieldNaming] = array_merge($copiedParams, $subFieldParams);
}
return $additionalFields;
}
} | [
"public",
"function",
"getAdditionalFieldList",
"(",
"$",
"fieldName",
",",
"array",
"$",
"fieldParams",
",",
"array",
"$",
"definitionList",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fieldParams",
"[",
"'type'",
"]",
")",
"||",
"empty",
"(",
"$",
"definitionList",
")",
")",
"{",
"return",
";",
"}",
"$",
"fieldType",
"=",
"$",
"fieldParams",
"[",
"'type'",
"]",
";",
"$",
"fieldDefinition",
"=",
"isset",
"(",
"$",
"definitionList",
"[",
"$",
"fieldType",
"]",
")",
"?",
"$",
"definitionList",
"[",
"$",
"fieldType",
"]",
":",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"fieldDefinition",
")",
"&&",
"!",
"empty",
"(",
"$",
"fieldDefinition",
"[",
"'fields'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"fieldDefinition",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"copiedParams",
"=",
"array_intersect_key",
"(",
"$",
"fieldParams",
",",
"array_flip",
"(",
"$",
"this",
"->",
"copiedDefParams",
")",
")",
";",
"$",
"additionalFields",
"=",
"array",
"(",
")",
";",
"//add additional fields",
"foreach",
"(",
"$",
"fieldDefinition",
"[",
"'fields'",
"]",
"as",
"$",
"subFieldName",
"=>",
"$",
"subFieldParams",
")",
"{",
"$",
"namingType",
"=",
"isset",
"(",
"$",
"fieldDefinition",
"[",
"'naming'",
"]",
")",
"?",
"$",
"fieldDefinition",
"[",
"'naming'",
"]",
":",
"$",
"this",
"->",
"defaultNaming",
";",
"$",
"subFieldNaming",
"=",
"Util",
"::",
"getNaming",
"(",
"$",
"fieldName",
",",
"$",
"subFieldName",
",",
"$",
"namingType",
")",
";",
"$",
"additionalFields",
"[",
"$",
"subFieldNaming",
"]",
"=",
"array_merge",
"(",
"$",
"copiedParams",
",",
"$",
"subFieldParams",
")",
";",
"}",
"return",
"$",
"additionalFields",
";",
"}",
"}"
] | Get additional field list based on field definition in metadata 'fields'
@param string $fieldName
@param array $fieldParams
@param array|null $definitionList
@return array | [
"Get",
"additional",
"field",
"list",
"based",
"on",
"field",
"definition",
"in",
"metadata",
"fields"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata/Helper.php#L139-L165 | train |
espocrm/espocrm | application/Espo/Core/Utils/SystemRequirements.php | SystemRequirements.getPhpRequiredList | protected function getPhpRequiredList($requiredOnly, array $additionalData = null)
{
$requiredList = [
'requiredPhpVersion',
'requiredPhpLibs',
];
if (!$requiredOnly) {
$requiredList = array_merge($requiredList, [
'recommendedPhpLibs',
'recommendedPhpParams',
]);
}
return $this->getRequiredList('phpRequirements', $requiredList, $additionalData);
} | php | protected function getPhpRequiredList($requiredOnly, array $additionalData = null)
{
$requiredList = [
'requiredPhpVersion',
'requiredPhpLibs',
];
if (!$requiredOnly) {
$requiredList = array_merge($requiredList, [
'recommendedPhpLibs',
'recommendedPhpParams',
]);
}
return $this->getRequiredList('phpRequirements', $requiredList, $additionalData);
} | [
"protected",
"function",
"getPhpRequiredList",
"(",
"$",
"requiredOnly",
",",
"array",
"$",
"additionalData",
"=",
"null",
")",
"{",
"$",
"requiredList",
"=",
"[",
"'requiredPhpVersion'",
",",
"'requiredPhpLibs'",
",",
"]",
";",
"if",
"(",
"!",
"$",
"requiredOnly",
")",
"{",
"$",
"requiredList",
"=",
"array_merge",
"(",
"$",
"requiredList",
",",
"[",
"'recommendedPhpLibs'",
",",
"'recommendedPhpParams'",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getRequiredList",
"(",
"'phpRequirements'",
",",
"$",
"requiredList",
",",
"$",
"additionalData",
")",
";",
"}"
] | Get required php params
@return array | [
"Get",
"required",
"php",
"params"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/SystemRequirements.php#L106-L121 | train |
espocrm/espocrm | application/Espo/Core/Utils/SystemRequirements.php | SystemRequirements.getDatabaseRequiredList | protected function getDatabaseRequiredList($requiredOnly, array $additionalData = null)
{
$databaseTypeName = 'Mysql';
$databaseHelper = $this->getDatabaseHelper();
$databaseParams = isset($additionalData['database']) ? $additionalData['database'] : null;
$dbalConnection = $databaseHelper->createDbalConnection($databaseParams);
if ($dbalConnection) {
$databaseHelper->setDbalConnection($dbalConnection);
$databaseType = $databaseHelper->getDatabaseType();
$databaseTypeName = ucfirst(strtolower($databaseType));
}
$requiredList = [
'required' . $databaseTypeName . 'Version',
];
if (!$requiredOnly) {
$requiredList = array_merge($requiredList, [
'recommended' . $databaseTypeName . 'Params',
'connection',
]);
}
return $this->getRequiredList('databaseRequirements', $requiredList, $additionalData);
} | php | protected function getDatabaseRequiredList($requiredOnly, array $additionalData = null)
{
$databaseTypeName = 'Mysql';
$databaseHelper = $this->getDatabaseHelper();
$databaseParams = isset($additionalData['database']) ? $additionalData['database'] : null;
$dbalConnection = $databaseHelper->createDbalConnection($databaseParams);
if ($dbalConnection) {
$databaseHelper->setDbalConnection($dbalConnection);
$databaseType = $databaseHelper->getDatabaseType();
$databaseTypeName = ucfirst(strtolower($databaseType));
}
$requiredList = [
'required' . $databaseTypeName . 'Version',
];
if (!$requiredOnly) {
$requiredList = array_merge($requiredList, [
'recommended' . $databaseTypeName . 'Params',
'connection',
]);
}
return $this->getRequiredList('databaseRequirements', $requiredList, $additionalData);
} | [
"protected",
"function",
"getDatabaseRequiredList",
"(",
"$",
"requiredOnly",
",",
"array",
"$",
"additionalData",
"=",
"null",
")",
"{",
"$",
"databaseTypeName",
"=",
"'Mysql'",
";",
"$",
"databaseHelper",
"=",
"$",
"this",
"->",
"getDatabaseHelper",
"(",
")",
";",
"$",
"databaseParams",
"=",
"isset",
"(",
"$",
"additionalData",
"[",
"'database'",
"]",
")",
"?",
"$",
"additionalData",
"[",
"'database'",
"]",
":",
"null",
";",
"$",
"dbalConnection",
"=",
"$",
"databaseHelper",
"->",
"createDbalConnection",
"(",
"$",
"databaseParams",
")",
";",
"if",
"(",
"$",
"dbalConnection",
")",
"{",
"$",
"databaseHelper",
"->",
"setDbalConnection",
"(",
"$",
"dbalConnection",
")",
";",
"$",
"databaseType",
"=",
"$",
"databaseHelper",
"->",
"getDatabaseType",
"(",
")",
";",
"$",
"databaseTypeName",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"databaseType",
")",
")",
";",
"}",
"$",
"requiredList",
"=",
"[",
"'required'",
".",
"$",
"databaseTypeName",
".",
"'Version'",
",",
"]",
";",
"if",
"(",
"!",
"$",
"requiredOnly",
")",
"{",
"$",
"requiredList",
"=",
"array_merge",
"(",
"$",
"requiredList",
",",
"[",
"'recommended'",
".",
"$",
"databaseTypeName",
".",
"'Params'",
",",
"'connection'",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getRequiredList",
"(",
"'databaseRequirements'",
",",
"$",
"requiredList",
",",
"$",
"additionalData",
")",
";",
"}"
] | Get required database params
@return array | [
"Get",
"required",
"database",
"params"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/SystemRequirements.php#L127-L152 | train |
espocrm/espocrm | application/Espo/Core/Utils/SystemRequirements.php | SystemRequirements.checkPhpRequirements | protected function checkPhpRequirements($type, $data, array $additionalData = null)
{
$list = [];
switch ($type) {
case 'requiredPhpVersion':
$actualVersion = $this->getSystemHelper()->getPhpVersion();
$requiredVersion = $data;
$acceptable = true;
if (version_compare($actualVersion, $requiredVersion) == -1) {
$acceptable = false;
}
$list[$type] = [
'type' => 'version',
'acceptable' => $acceptable,
'required' => $requiredVersion,
'actual' => $actualVersion,
];
break;
case 'requiredPhpLibs':
case 'recommendedPhpLibs':
foreach ($data as $name) {
$acceptable = $this->getSystemHelper()->hasPhpLib($name);
$list[$name] = array(
'type' => 'lib',
'acceptable' => $acceptable,
'actual' => $acceptable ? 'On' : 'Off',
);
}
break;
case 'recommendedPhpParams':
foreach ($data as $name => $value) {
$requiredValue = $value;
$actualValue = $this->getSystemHelper()->getPhpParam($name);
$acceptable = ( isset($actualValue) && Util::convertToByte($actualValue) >= Util::convertToByte($requiredValue) ) ? true : false;
$list[$name] = array(
'type' => 'param',
'acceptable' => $acceptable,
'required' => $requiredValue,
'actual' => $actualValue,
);
}
break;
}
return $list;
} | php | protected function checkPhpRequirements($type, $data, array $additionalData = null)
{
$list = [];
switch ($type) {
case 'requiredPhpVersion':
$actualVersion = $this->getSystemHelper()->getPhpVersion();
$requiredVersion = $data;
$acceptable = true;
if (version_compare($actualVersion, $requiredVersion) == -1) {
$acceptable = false;
}
$list[$type] = [
'type' => 'version',
'acceptable' => $acceptable,
'required' => $requiredVersion,
'actual' => $actualVersion,
];
break;
case 'requiredPhpLibs':
case 'recommendedPhpLibs':
foreach ($data as $name) {
$acceptable = $this->getSystemHelper()->hasPhpLib($name);
$list[$name] = array(
'type' => 'lib',
'acceptable' => $acceptable,
'actual' => $acceptable ? 'On' : 'Off',
);
}
break;
case 'recommendedPhpParams':
foreach ($data as $name => $value) {
$requiredValue = $value;
$actualValue = $this->getSystemHelper()->getPhpParam($name);
$acceptable = ( isset($actualValue) && Util::convertToByte($actualValue) >= Util::convertToByte($requiredValue) ) ? true : false;
$list[$name] = array(
'type' => 'param',
'acceptable' => $acceptable,
'required' => $requiredValue,
'actual' => $actualValue,
);
}
break;
}
return $list;
} | [
"protected",
"function",
"checkPhpRequirements",
"(",
"$",
"type",
",",
"$",
"data",
",",
"array",
"$",
"additionalData",
"=",
"null",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'requiredPhpVersion'",
":",
"$",
"actualVersion",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"getPhpVersion",
"(",
")",
";",
"$",
"requiredVersion",
"=",
"$",
"data",
";",
"$",
"acceptable",
"=",
"true",
";",
"if",
"(",
"version_compare",
"(",
"$",
"actualVersion",
",",
"$",
"requiredVersion",
")",
"==",
"-",
"1",
")",
"{",
"$",
"acceptable",
"=",
"false",
";",
"}",
"$",
"list",
"[",
"$",
"type",
"]",
"=",
"[",
"'type'",
"=>",
"'version'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'required'",
"=>",
"$",
"requiredVersion",
",",
"'actual'",
"=>",
"$",
"actualVersion",
",",
"]",
";",
"break",
";",
"case",
"'requiredPhpLibs'",
":",
"case",
"'recommendedPhpLibs'",
":",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
")",
"{",
"$",
"acceptable",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"hasPhpLib",
"(",
"$",
"name",
")",
";",
"$",
"list",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'lib'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'actual'",
"=>",
"$",
"acceptable",
"?",
"'On'",
":",
"'Off'",
",",
")",
";",
"}",
"break",
";",
"case",
"'recommendedPhpParams'",
":",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"requiredValue",
"=",
"$",
"value",
";",
"$",
"actualValue",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"getPhpParam",
"(",
"$",
"name",
")",
";",
"$",
"acceptable",
"=",
"(",
"isset",
"(",
"$",
"actualValue",
")",
"&&",
"Util",
"::",
"convertToByte",
"(",
"$",
"actualValue",
")",
">=",
"Util",
"::",
"convertToByte",
"(",
"$",
"requiredValue",
")",
")",
"?",
"true",
":",
"false",
";",
"$",
"list",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'param'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'required'",
"=>",
"$",
"requiredValue",
",",
"'actual'",
"=>",
"$",
"actualValue",
",",
")",
";",
"}",
"break",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Check php requirements
@param string $type
@param mixed $data
@return array | [
"Check",
"php",
"requirements"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/SystemRequirements.php#L189-L242 | train |
espocrm/espocrm | application/Espo/Core/Utils/SystemRequirements.php | SystemRequirements.checkDatabaseRequirements | protected function checkDatabaseRequirements($type, $data, array $additionalData = null)
{
$list = [];
$databaseHelper = $this->getDatabaseHelper();
$databaseParams = isset($additionalData['database']) ? $additionalData['database'] : null;
$pdo = $databaseHelper->createPdoConnection($databaseParams);
if (!$pdo) {
$type = 'connection';
}
switch ($type) {
case 'requiredMysqlVersion':
case 'requiredMariadbVersion':
$actualVersion = $databaseHelper->getPdoDatabaseVersion($pdo);
$requiredVersion = $data;
$acceptable = true;
if (version_compare($actualVersion, $requiredVersion) == -1) {
$acceptable = false;
}
$list[$type] = [
'type' => 'version',
'acceptable' => $acceptable,
'required' => $requiredVersion,
'actual' => $actualVersion,
];
break;
case 'recommendedMysqlParams':
case 'recommendedMariadbParams':
foreach ($data as $name => $value) {
$requiredValue = $value;
$actualValue = $databaseHelper->getPdoDatabaseParam($name, $pdo);
$acceptable = false;
switch (gettype($requiredValue)) {
case 'integer':
if (Util::convertToByte($actualValue) >= Util::convertToByte($requiredValue)) {
$acceptable = true;
}
break;
case 'string':
if (strtoupper($actualValue) == strtoupper($requiredValue)) {
$acceptable = true;
}
break;
}
$list[$name] = array(
'type' => 'param',
'acceptable' => $acceptable,
'required' => $requiredValue,
'actual' => $actualValue,
);
}
break;
case 'connection':
if (!$databaseParams) {
$databaseParams = $this->getConfig()->get('database');
}
$acceptable = true;
if (!$pdo instanceof \PDO) {
$acceptable = false;
}
$list['host'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['host'],
];
$list['dbname'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['dbname'],
];
$list['user'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['user'],
];
break;
}
return $list;
} | php | protected function checkDatabaseRequirements($type, $data, array $additionalData = null)
{
$list = [];
$databaseHelper = $this->getDatabaseHelper();
$databaseParams = isset($additionalData['database']) ? $additionalData['database'] : null;
$pdo = $databaseHelper->createPdoConnection($databaseParams);
if (!$pdo) {
$type = 'connection';
}
switch ($type) {
case 'requiredMysqlVersion':
case 'requiredMariadbVersion':
$actualVersion = $databaseHelper->getPdoDatabaseVersion($pdo);
$requiredVersion = $data;
$acceptable = true;
if (version_compare($actualVersion, $requiredVersion) == -1) {
$acceptable = false;
}
$list[$type] = [
'type' => 'version',
'acceptable' => $acceptable,
'required' => $requiredVersion,
'actual' => $actualVersion,
];
break;
case 'recommendedMysqlParams':
case 'recommendedMariadbParams':
foreach ($data as $name => $value) {
$requiredValue = $value;
$actualValue = $databaseHelper->getPdoDatabaseParam($name, $pdo);
$acceptable = false;
switch (gettype($requiredValue)) {
case 'integer':
if (Util::convertToByte($actualValue) >= Util::convertToByte($requiredValue)) {
$acceptable = true;
}
break;
case 'string':
if (strtoupper($actualValue) == strtoupper($requiredValue)) {
$acceptable = true;
}
break;
}
$list[$name] = array(
'type' => 'param',
'acceptable' => $acceptable,
'required' => $requiredValue,
'actual' => $actualValue,
);
}
break;
case 'connection':
if (!$databaseParams) {
$databaseParams = $this->getConfig()->get('database');
}
$acceptable = true;
if (!$pdo instanceof \PDO) {
$acceptable = false;
}
$list['host'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['host'],
];
$list['dbname'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['dbname'],
];
$list['user'] = [
'type' => 'connection',
'acceptable' => $acceptable,
'actual' => $databaseParams['user'],
];
break;
}
return $list;
} | [
"protected",
"function",
"checkDatabaseRequirements",
"(",
"$",
"type",
",",
"$",
"data",
",",
"array",
"$",
"additionalData",
"=",
"null",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"$",
"databaseHelper",
"=",
"$",
"this",
"->",
"getDatabaseHelper",
"(",
")",
";",
"$",
"databaseParams",
"=",
"isset",
"(",
"$",
"additionalData",
"[",
"'database'",
"]",
")",
"?",
"$",
"additionalData",
"[",
"'database'",
"]",
":",
"null",
";",
"$",
"pdo",
"=",
"$",
"databaseHelper",
"->",
"createPdoConnection",
"(",
"$",
"databaseParams",
")",
";",
"if",
"(",
"!",
"$",
"pdo",
")",
"{",
"$",
"type",
"=",
"'connection'",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'requiredMysqlVersion'",
":",
"case",
"'requiredMariadbVersion'",
":",
"$",
"actualVersion",
"=",
"$",
"databaseHelper",
"->",
"getPdoDatabaseVersion",
"(",
"$",
"pdo",
")",
";",
"$",
"requiredVersion",
"=",
"$",
"data",
";",
"$",
"acceptable",
"=",
"true",
";",
"if",
"(",
"version_compare",
"(",
"$",
"actualVersion",
",",
"$",
"requiredVersion",
")",
"==",
"-",
"1",
")",
"{",
"$",
"acceptable",
"=",
"false",
";",
"}",
"$",
"list",
"[",
"$",
"type",
"]",
"=",
"[",
"'type'",
"=>",
"'version'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'required'",
"=>",
"$",
"requiredVersion",
",",
"'actual'",
"=>",
"$",
"actualVersion",
",",
"]",
";",
"break",
";",
"case",
"'recommendedMysqlParams'",
":",
"case",
"'recommendedMariadbParams'",
":",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"requiredValue",
"=",
"$",
"value",
";",
"$",
"actualValue",
"=",
"$",
"databaseHelper",
"->",
"getPdoDatabaseParam",
"(",
"$",
"name",
",",
"$",
"pdo",
")",
";",
"$",
"acceptable",
"=",
"false",
";",
"switch",
"(",
"gettype",
"(",
"$",
"requiredValue",
")",
")",
"{",
"case",
"'integer'",
":",
"if",
"(",
"Util",
"::",
"convertToByte",
"(",
"$",
"actualValue",
")",
">=",
"Util",
"::",
"convertToByte",
"(",
"$",
"requiredValue",
")",
")",
"{",
"$",
"acceptable",
"=",
"true",
";",
"}",
"break",
";",
"case",
"'string'",
":",
"if",
"(",
"strtoupper",
"(",
"$",
"actualValue",
")",
"==",
"strtoupper",
"(",
"$",
"requiredValue",
")",
")",
"{",
"$",
"acceptable",
"=",
"true",
";",
"}",
"break",
";",
"}",
"$",
"list",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'param'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'required'",
"=>",
"$",
"requiredValue",
",",
"'actual'",
"=>",
"$",
"actualValue",
",",
")",
";",
"}",
"break",
";",
"case",
"'connection'",
":",
"if",
"(",
"!",
"$",
"databaseParams",
")",
"{",
"$",
"databaseParams",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'database'",
")",
";",
"}",
"$",
"acceptable",
"=",
"true",
";",
"if",
"(",
"!",
"$",
"pdo",
"instanceof",
"\\",
"PDO",
")",
"{",
"$",
"acceptable",
"=",
"false",
";",
"}",
"$",
"list",
"[",
"'host'",
"]",
"=",
"[",
"'type'",
"=>",
"'connection'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'actual'",
"=>",
"$",
"databaseParams",
"[",
"'host'",
"]",
",",
"]",
";",
"$",
"list",
"[",
"'dbname'",
"]",
"=",
"[",
"'type'",
"=>",
"'connection'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'actual'",
"=>",
"$",
"databaseParams",
"[",
"'dbname'",
"]",
",",
"]",
";",
"$",
"list",
"[",
"'user'",
"]",
"=",
"[",
"'type'",
"=>",
"'connection'",
",",
"'acceptable'",
"=>",
"$",
"acceptable",
",",
"'actual'",
"=>",
"$",
"databaseParams",
"[",
"'user'",
"]",
",",
"]",
";",
"break",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Check MySQL requirements
@param string $type
@param mixed $data
@return array | [
"Check",
"MySQL",
"requirements"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/SystemRequirements.php#L250-L341 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Fields/Base.php | Base.process | public function process($itemName, $entityName)
{
$inputs = array(
'itemName' => $itemName,
'entityName' => $entityName,
);
$this->setMethods($inputs);
$convertedDefs = $this->load($itemName, $entityName);
$inputs = $this->setArrayValue(null, $inputs);
$this->setMethods($inputs);
return $convertedDefs;
} | php | public function process($itemName, $entityName)
{
$inputs = array(
'itemName' => $itemName,
'entityName' => $entityName,
);
$this->setMethods($inputs);
$convertedDefs = $this->load($itemName, $entityName);
$inputs = $this->setArrayValue(null, $inputs);
$this->setMethods($inputs);
return $convertedDefs;
} | [
"public",
"function",
"process",
"(",
"$",
"itemName",
",",
"$",
"entityName",
")",
"{",
"$",
"inputs",
"=",
"array",
"(",
"'itemName'",
"=>",
"$",
"itemName",
",",
"'entityName'",
"=>",
"$",
"entityName",
",",
")",
";",
"$",
"this",
"->",
"setMethods",
"(",
"$",
"inputs",
")",
";",
"$",
"convertedDefs",
"=",
"$",
"this",
"->",
"load",
"(",
"$",
"itemName",
",",
"$",
"entityName",
")",
";",
"$",
"inputs",
"=",
"$",
"this",
"->",
"setArrayValue",
"(",
"null",
",",
"$",
"inputs",
")",
";",
"$",
"this",
"->",
"setMethods",
"(",
"$",
"inputs",
")",
";",
"return",
"$",
"convertedDefs",
";",
"}"
] | Start process Orm converting for fields
@param string $itemName Field name
@param string $entityName
@return array | [
"Start",
"process",
"Orm",
"converting",
"for",
"fields"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Fields/Base.php#L40-L54 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.backupExistingFiles | protected function backupExistingFiles()
{
parent::backupExistingFiles();
$backupPath = $this->getPath('backupPath');
/** copy scripts files */
$packagePath = $this->getPackagePath();
return $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
} | php | protected function backupExistingFiles()
{
parent::backupExistingFiles();
$backupPath = $this->getPath('backupPath');
/** copy scripts files */
$packagePath = $this->getPackagePath();
return $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
} | [
"protected",
"function",
"backupExistingFiles",
"(",
")",
"{",
"parent",
"::",
"backupExistingFiles",
"(",
")",
";",
"$",
"backupPath",
"=",
"$",
"this",
"->",
"getPath",
"(",
"'backupPath'",
")",
";",
"/** copy scripts files */",
"$",
"packagePath",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
")",
";",
"return",
"$",
"this",
"->",
"copy",
"(",
"array",
"(",
"$",
"packagePath",
",",
"self",
"::",
"SCRIPTS",
")",
",",
"array",
"(",
"$",
"backupPath",
",",
"self",
"::",
"SCRIPTS",
")",
",",
"true",
")",
";",
"}"
] | Copy Existing files to backup directory
@return bool | [
"Copy",
"Existing",
"files",
"to",
"backup",
"directory"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L60-L70 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.findExtension | protected function findExtension()
{
$manifest = $this->getManifest();
$this->extensionEntity = $this->getEntityManager()->getRepository('Extension')->where(array(
'name' => $manifest['name'],
'isInstalled' => true,
))->findOne();
return $this->extensionEntity;
} | php | protected function findExtension()
{
$manifest = $this->getManifest();
$this->extensionEntity = $this->getEntityManager()->getRepository('Extension')->where(array(
'name' => $manifest['name'],
'isInstalled' => true,
))->findOne();
return $this->extensionEntity;
} | [
"protected",
"function",
"findExtension",
"(",
")",
"{",
"$",
"manifest",
"=",
"$",
"this",
"->",
"getManifest",
"(",
")",
";",
"$",
"this",
"->",
"extensionEntity",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'Extension'",
")",
"->",
"where",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"manifest",
"[",
"'name'",
"]",
",",
"'isInstalled'",
"=>",
"true",
",",
")",
")",
"->",
"findOne",
"(",
")",
";",
"return",
"$",
"this",
"->",
"extensionEntity",
";",
"}"
] | Find Extension entity
@return \Espo\Entities\Extension | [
"Find",
"Extension",
"entity"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L117-L127 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.storeExtension | protected function storeExtension()
{
$entityManager = $this->getEntityManager();
$extensionEntity = $entityManager->getEntity('Extension', $this->getProcessId());
if (!isset($extensionEntity)) {
$extensionEntity = $entityManager->getEntity('Extension');
}
$manifest = $this->getManifest();
$fileList = $this->getCopyFileList();
$data = array(
'id' => $this->getProcessId(),
'name' => trim($manifest['name']),
'isInstalled' => true,
'version' => $manifest['version'],
'fileList' => $fileList,
'description' => $manifest['description'],
);
if (!empty($manifest['checkVersionUrl'])) {
$data['checkVersionUrl'] = $manifest['checkVersionUrl'];
}
$extensionEntity->set($data);
return $entityManager->saveEntity($extensionEntity);
} | php | protected function storeExtension()
{
$entityManager = $this->getEntityManager();
$extensionEntity = $entityManager->getEntity('Extension', $this->getProcessId());
if (!isset($extensionEntity)) {
$extensionEntity = $entityManager->getEntity('Extension');
}
$manifest = $this->getManifest();
$fileList = $this->getCopyFileList();
$data = array(
'id' => $this->getProcessId(),
'name' => trim($manifest['name']),
'isInstalled' => true,
'version' => $manifest['version'],
'fileList' => $fileList,
'description' => $manifest['description'],
);
if (!empty($manifest['checkVersionUrl'])) {
$data['checkVersionUrl'] = $manifest['checkVersionUrl'];
}
$extensionEntity->set($data);
return $entityManager->saveEntity($extensionEntity);
} | [
"protected",
"function",
"storeExtension",
"(",
")",
"{",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"extensionEntity",
"=",
"$",
"entityManager",
"->",
"getEntity",
"(",
"'Extension'",
",",
"$",
"this",
"->",
"getProcessId",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"extensionEntity",
")",
")",
"{",
"$",
"extensionEntity",
"=",
"$",
"entityManager",
"->",
"getEntity",
"(",
"'Extension'",
")",
";",
"}",
"$",
"manifest",
"=",
"$",
"this",
"->",
"getManifest",
"(",
")",
";",
"$",
"fileList",
"=",
"$",
"this",
"->",
"getCopyFileList",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getProcessId",
"(",
")",
",",
"'name'",
"=>",
"trim",
"(",
"$",
"manifest",
"[",
"'name'",
"]",
")",
",",
"'isInstalled'",
"=>",
"true",
",",
"'version'",
"=>",
"$",
"manifest",
"[",
"'version'",
"]",
",",
"'fileList'",
"=>",
"$",
"fileList",
",",
"'description'",
"=>",
"$",
"manifest",
"[",
"'description'",
"]",
",",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"manifest",
"[",
"'checkVersionUrl'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'checkVersionUrl'",
"]",
"=",
"$",
"manifest",
"[",
"'checkVersionUrl'",
"]",
";",
"}",
"$",
"extensionEntity",
"->",
"set",
"(",
"$",
"data",
")",
";",
"return",
"$",
"entityManager",
"->",
"saveEntity",
"(",
"$",
"extensionEntity",
")",
";",
"}"
] | Create a record of Extension Entity
@return bool | [
"Create",
"a",
"record",
"of",
"Extension",
"Entity"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L134-L162 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.compareVersion | protected function compareVersion()
{
$manifest = $this->getManifest();
$extensionEntity = $this->getExtensionEntity();
if (isset($extensionEntity)) {
$comparedVersion = version_compare($manifest['version'], $extensionEntity->get('version'), '>=');
if ($comparedVersion <= 0) {
$this->throwErrorAndRemovePackage('You cannot install an older version of this extension.');
}
}
} | php | protected function compareVersion()
{
$manifest = $this->getManifest();
$extensionEntity = $this->getExtensionEntity();
if (isset($extensionEntity)) {
$comparedVersion = version_compare($manifest['version'], $extensionEntity->get('version'), '>=');
if ($comparedVersion <= 0) {
$this->throwErrorAndRemovePackage('You cannot install an older version of this extension.');
}
}
} | [
"protected",
"function",
"compareVersion",
"(",
")",
"{",
"$",
"manifest",
"=",
"$",
"this",
"->",
"getManifest",
"(",
")",
";",
"$",
"extensionEntity",
"=",
"$",
"this",
"->",
"getExtensionEntity",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"extensionEntity",
")",
")",
"{",
"$",
"comparedVersion",
"=",
"version_compare",
"(",
"$",
"manifest",
"[",
"'version'",
"]",
",",
"$",
"extensionEntity",
"->",
"get",
"(",
"'version'",
")",
",",
"'>='",
")",
";",
"if",
"(",
"$",
"comparedVersion",
"<=",
"0",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"'You cannot install an older version of this extension.'",
")",
";",
"}",
"}",
"}"
] | Compare version between installed and a new extensions
@return void | [
"Compare",
"version",
"between",
"installed",
"and",
"a",
"new",
"extensions"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L169-L180 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.uninstallExtension | protected function uninstallExtension()
{
$extensionEntity = $this->getExtensionEntity();
$this->executeAction(ExtensionManager::UNINSTALL, array(
'id' => $extensionEntity->get('id'),
'skipSystemRebuild' => true,
'skipAfterScript' => true,
)
);
} | php | protected function uninstallExtension()
{
$extensionEntity = $this->getExtensionEntity();
$this->executeAction(ExtensionManager::UNINSTALL, array(
'id' => $extensionEntity->get('id'),
'skipSystemRebuild' => true,
'skipAfterScript' => true,
)
);
} | [
"protected",
"function",
"uninstallExtension",
"(",
")",
"{",
"$",
"extensionEntity",
"=",
"$",
"this",
"->",
"getExtensionEntity",
"(",
")",
";",
"$",
"this",
"->",
"executeAction",
"(",
"ExtensionManager",
"::",
"UNINSTALL",
",",
"array",
"(",
"'id'",
"=>",
"$",
"extensionEntity",
"->",
"get",
"(",
"'id'",
")",
",",
"'skipSystemRebuild'",
"=>",
"true",
",",
"'skipAfterScript'",
"=>",
"true",
",",
")",
")",
";",
"}"
] | If extension already installed, uninstall an old version
@return void | [
"If",
"extension",
"already",
"installed",
"uninstall",
"an",
"old",
"version"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L203-L213 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Extension/Install.php | Install.deleteExtension | protected function deleteExtension()
{
$extensionEntity = $this->getExtensionEntity();
$this->executeAction(ExtensionManager::DELETE, array('id' => $extensionEntity->get('id')));
} | php | protected function deleteExtension()
{
$extensionEntity = $this->getExtensionEntity();
$this->executeAction(ExtensionManager::DELETE, array('id' => $extensionEntity->get('id')));
} | [
"protected",
"function",
"deleteExtension",
"(",
")",
"{",
"$",
"extensionEntity",
"=",
"$",
"this",
"->",
"getExtensionEntity",
"(",
")",
";",
"$",
"this",
"->",
"executeAction",
"(",
"ExtensionManager",
"::",
"DELETE",
",",
"array",
"(",
"'id'",
"=>",
"$",
"extensionEntity",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"}"
] | Delete extension package
@return void | [
"Delete",
"extension",
"package"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Extension/Install.php#L220-L225 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.runScript | protected function runScript($type)
{
$packagePath = $this->getPackagePath();
$scriptNames = $this->getParams('scriptNames');
$scriptName = $scriptNames[$type];
if (!isset($scriptName)) {
return;
}
$beforeInstallScript = Util::concatPath( array($packagePath, self::SCRIPTS, $scriptName) ) . '.php';
if (file_exists($beforeInstallScript)) {
require_once($beforeInstallScript);
$script = new $scriptName();
try {
$script->run($this->getContainer(), $this->scriptParams);
} catch (\Exception $e) {
$this->throwErrorAndRemovePackage($e->getMessage());
}
}
} | php | protected function runScript($type)
{
$packagePath = $this->getPackagePath();
$scriptNames = $this->getParams('scriptNames');
$scriptName = $scriptNames[$type];
if (!isset($scriptName)) {
return;
}
$beforeInstallScript = Util::concatPath( array($packagePath, self::SCRIPTS, $scriptName) ) . '.php';
if (file_exists($beforeInstallScript)) {
require_once($beforeInstallScript);
$script = new $scriptName();
try {
$script->run($this->getContainer(), $this->scriptParams);
} catch (\Exception $e) {
$this->throwErrorAndRemovePackage($e->getMessage());
}
}
} | [
"protected",
"function",
"runScript",
"(",
"$",
"type",
")",
"{",
"$",
"packagePath",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
")",
";",
"$",
"scriptNames",
"=",
"$",
"this",
"->",
"getParams",
"(",
"'scriptNames'",
")",
";",
"$",
"scriptName",
"=",
"$",
"scriptNames",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"scriptName",
")",
")",
"{",
"return",
";",
"}",
"$",
"beforeInstallScript",
"=",
"Util",
"::",
"concatPath",
"(",
"array",
"(",
"$",
"packagePath",
",",
"self",
"::",
"SCRIPTS",
",",
"$",
"scriptName",
")",
")",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"beforeInstallScript",
")",
")",
"{",
"require_once",
"(",
"$",
"beforeInstallScript",
")",
";",
"$",
"script",
"=",
"new",
"$",
"scriptName",
"(",
")",
";",
"try",
"{",
"$",
"script",
"->",
"run",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
",",
"$",
"this",
"->",
"scriptParams",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Run scripts by type
@param string $type Ex. "before", "after"
@return void | [
"Run",
"scripts",
"by",
"type"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L279-L301 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.getPath | protected function getPath($name = 'packagePath', $isPackage = false)
{
$postfix = $isPackage ? $this->packagePostfix : '';
$processId = $this->getProcessId();
$path = Util::concatPath($this->getParams($name), $processId);
return $path . $postfix;
} | php | protected function getPath($name = 'packagePath', $isPackage = false)
{
$postfix = $isPackage ? $this->packagePostfix : '';
$processId = $this->getProcessId();
$path = Util::concatPath($this->getParams($name), $processId);
return $path . $postfix;
} | [
"protected",
"function",
"getPath",
"(",
"$",
"name",
"=",
"'packagePath'",
",",
"$",
"isPackage",
"=",
"false",
")",
"{",
"$",
"postfix",
"=",
"$",
"isPackage",
"?",
"$",
"this",
"->",
"packagePostfix",
":",
"''",
";",
"$",
"processId",
"=",
"$",
"this",
"->",
"getProcessId",
"(",
")",
";",
"$",
"path",
"=",
"Util",
"::",
"concatPath",
"(",
"$",
"this",
"->",
"getParams",
"(",
"$",
"name",
")",
",",
"$",
"processId",
")",
";",
"return",
"$",
"path",
".",
"$",
"postfix",
";",
"}"
] | Get package path
@param string $processId
@return string | [
"Get",
"package",
"path"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L309-L317 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.getDeleteFileList | protected function getDeleteFileList()
{
if (!isset($this->data['deleteFileList'])) {
$deleteFileList = array();
$deleteList = array_merge($this->getDeleteList('delete'), $this->getDeleteList('deleteBeforeCopy'), $this->getDeleteList('vendor'));
foreach ($deleteList as $key => $itemPath) {
if (is_dir($itemPath)) {
$fileList = $this->getFileManager()->getFileList($itemPath, true, '', true, true);
$fileList = $this->concatStringWithArray($itemPath, $fileList);
$deleteFileList = array_merge($deleteFileList, $fileList);
continue;
}
$deleteFileList[] = $itemPath;
}
$this->data['deleteFileList'] = $deleteFileList;
}
return $this->data['deleteFileList'];
} | php | protected function getDeleteFileList()
{
if (!isset($this->data['deleteFileList'])) {
$deleteFileList = array();
$deleteList = array_merge($this->getDeleteList('delete'), $this->getDeleteList('deleteBeforeCopy'), $this->getDeleteList('vendor'));
foreach ($deleteList as $key => $itemPath) {
if (is_dir($itemPath)) {
$fileList = $this->getFileManager()->getFileList($itemPath, true, '', true, true);
$fileList = $this->concatStringWithArray($itemPath, $fileList);
$deleteFileList = array_merge($deleteFileList, $fileList);
continue;
}
$deleteFileList[] = $itemPath;
}
$this->data['deleteFileList'] = $deleteFileList;
}
return $this->data['deleteFileList'];
} | [
"protected",
"function",
"getDeleteFileList",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'deleteFileList'",
"]",
")",
")",
"{",
"$",
"deleteFileList",
"=",
"array",
"(",
")",
";",
"$",
"deleteList",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getDeleteList",
"(",
"'delete'",
")",
",",
"$",
"this",
"->",
"getDeleteList",
"(",
"'deleteBeforeCopy'",
")",
",",
"$",
"this",
"->",
"getDeleteList",
"(",
"'vendor'",
")",
")",
";",
"foreach",
"(",
"$",
"deleteList",
"as",
"$",
"key",
"=>",
"$",
"itemPath",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"itemPath",
")",
")",
"{",
"$",
"fileList",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getFileList",
"(",
"$",
"itemPath",
",",
"true",
",",
"''",
",",
"true",
",",
"true",
")",
";",
"$",
"fileList",
"=",
"$",
"this",
"->",
"concatStringWithArray",
"(",
"$",
"itemPath",
",",
"$",
"fileList",
")",
";",
"$",
"deleteFileList",
"=",
"array_merge",
"(",
"$",
"deleteFileList",
",",
"$",
"fileList",
")",
";",
"continue",
";",
"}",
"$",
"deleteFileList",
"[",
"]",
"=",
"$",
"itemPath",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"'deleteFileList'",
"]",
"=",
"$",
"deleteFileList",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"[",
"'deleteFileList'",
"]",
";",
"}"
] | Get a list of files defined in manifest.json
@return array | [
"Get",
"a",
"list",
"of",
"files",
"defined",
"in",
"manifest",
".",
"json"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L349-L371 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.deleteFiles | protected function deleteFiles($type = 'delete', $withEmptyDirs = false)
{
$deleteList = $this->getDeleteList($type);
if (!empty($deleteList)) {
return $this->getFileManager()->remove($deleteList, null, $withEmptyDirs);
}
return true;
} | php | protected function deleteFiles($type = 'delete', $withEmptyDirs = false)
{
$deleteList = $this->getDeleteList($type);
if (!empty($deleteList)) {
return $this->getFileManager()->remove($deleteList, null, $withEmptyDirs);
}
return true;
} | [
"protected",
"function",
"deleteFiles",
"(",
"$",
"type",
"=",
"'delete'",
",",
"$",
"withEmptyDirs",
"=",
"false",
")",
"{",
"$",
"deleteList",
"=",
"$",
"this",
"->",
"getDeleteList",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"deleteList",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"remove",
"(",
"$",
"deleteList",
",",
"null",
",",
"$",
"withEmptyDirs",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Delete files defined in a manifest
@return boolen | [
"Delete",
"files",
"defined",
"in",
"a",
"manifest"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L378-L387 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.checkManifest | protected function checkManifest(array $manifest)
{
$requiredFields = array(
'name',
'version',
);
foreach ($requiredFields as $fieldName) {
if (empty($manifest[$fieldName])) {
return false;
}
}
return true;
} | php | protected function checkManifest(array $manifest)
{
$requiredFields = array(
'name',
'version',
);
foreach ($requiredFields as $fieldName) {
if (empty($manifest[$fieldName])) {
return false;
}
}
return true;
} | [
"protected",
"function",
"checkManifest",
"(",
"array",
"$",
"manifest",
")",
"{",
"$",
"requiredFields",
"=",
"array",
"(",
"'name'",
",",
"'version'",
",",
")",
";",
"foreach",
"(",
"$",
"requiredFields",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"manifest",
"[",
"$",
"fieldName",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check if the manifest is correct
@param array $manifest
@return boolean | [
"Check",
"if",
"the",
"manifest",
"is",
"correct"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L578-L592 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.unzipArchive | protected function unzipArchive($packagePath = null)
{
$packagePath = isset($packagePath) ? $packagePath : $this->getPackagePath();
$packageArchivePath = $this->getPackagePath(true);
if (!file_exists($packageArchivePath)) {
throw new Error('Package Archive doesn\'t exist.');
}
$res = $this->getZipUtil()->unzip($packageArchivePath, $packagePath);
if ($res === false) {
throw new Error('Unnable to unzip the file - '.$packagePath.'.');
}
} | php | protected function unzipArchive($packagePath = null)
{
$packagePath = isset($packagePath) ? $packagePath : $this->getPackagePath();
$packageArchivePath = $this->getPackagePath(true);
if (!file_exists($packageArchivePath)) {
throw new Error('Package Archive doesn\'t exist.');
}
$res = $this->getZipUtil()->unzip($packageArchivePath, $packagePath);
if ($res === false) {
throw new Error('Unnable to unzip the file - '.$packagePath.'.');
}
} | [
"protected",
"function",
"unzipArchive",
"(",
"$",
"packagePath",
"=",
"null",
")",
"{",
"$",
"packagePath",
"=",
"isset",
"(",
"$",
"packagePath",
")",
"?",
"$",
"packagePath",
":",
"$",
"this",
"->",
"getPackagePath",
"(",
")",
";",
"$",
"packageArchivePath",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
"true",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"packageArchivePath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Package Archive doesn\\'t exist.'",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"getZipUtil",
"(",
")",
"->",
"unzip",
"(",
"$",
"packageArchivePath",
",",
"$",
"packagePath",
")",
";",
"if",
"(",
"$",
"res",
"===",
"false",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unnable to unzip the file - '",
".",
"$",
"packagePath",
".",
"'.'",
")",
";",
"}",
"}"
] | Unzip a package archieve
@return void | [
"Unzip",
"a",
"package",
"archieve"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L610-L623 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.deletePackageFiles | protected function deletePackageFiles()
{
$packagePath = $this->getPackagePath();
$res = $this->getFileManager()->removeInDir($packagePath, true);
return $res;
} | php | protected function deletePackageFiles()
{
$packagePath = $this->getPackagePath();
$res = $this->getFileManager()->removeInDir($packagePath, true);
return $res;
} | [
"protected",
"function",
"deletePackageFiles",
"(",
")",
"{",
"$",
"packagePath",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"removeInDir",
"(",
"$",
"packagePath",
",",
"true",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Delete temporary package files
@return boolean | [
"Delete",
"temporary",
"package",
"files"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L630-L636 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.deletePackageArchive | protected function deletePackageArchive()
{
$packageArchive = $this->getPackagePath(true);
$res = $this->getFileManager()->removeFile($packageArchive);
return $res;
} | php | protected function deletePackageArchive()
{
$packageArchive = $this->getPackagePath(true);
$res = $this->getFileManager()->removeFile($packageArchive);
return $res;
} | [
"protected",
"function",
"deletePackageArchive",
"(",
")",
"{",
"$",
"packageArchive",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
"true",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"removeFile",
"(",
"$",
"packageArchive",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Delete temporary package archive
@return boolean | [
"Delete",
"temporary",
"package",
"archive"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L643-L649 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base.php | Base.executeAction | protected function executeAction($actionName, $data)
{
$actionManager = $this->getActionManager();
$currentAction = $actionManager->getAction();
$actionManager->setAction($actionName);
$actionManager->run($data);
$actionManager->setAction($currentAction);
} | php | protected function executeAction($actionName, $data)
{
$actionManager = $this->getActionManager();
$currentAction = $actionManager->getAction();
$actionManager->setAction($actionName);
$actionManager->run($data);
$actionManager->setAction($currentAction);
} | [
"protected",
"function",
"executeAction",
"(",
"$",
"actionName",
",",
"$",
"data",
")",
"{",
"$",
"actionManager",
"=",
"$",
"this",
"->",
"getActionManager",
"(",
")",
";",
"$",
"currentAction",
"=",
"$",
"actionManager",
"->",
"getAction",
"(",
")",
";",
"$",
"actionManager",
"->",
"setAction",
"(",
"$",
"actionName",
")",
";",
"$",
"actionManager",
"->",
"run",
"(",
"$",
"data",
")",
";",
"$",
"actionManager",
"->",
"setAction",
"(",
"$",
"currentAction",
")",
";",
"}"
] | Execute an action. For ex., execute uninstall action in install
@param string $actionName
@param string $data
@return void | [
"Execute",
"an",
"action",
".",
"For",
"ex",
".",
"execute",
"uninstall",
"action",
"in",
"install"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base.php#L670-L680 | train |
espocrm/espocrm | application/Espo/Core/Utils/Log/Monolog/Handler/StreamHandler.php | StreamHandler.pruneMessage | protected function pruneMessage(array $record)
{
$message = (string) $record['message'];
if (strlen($message) > $this->maxErrorMessageLength) {
$record['message'] = substr($message, 0, $this->maxErrorMessageLength) . '...';
$record['formatted'] = $this->getFormatter()->format($record);
}
return (string) $record['formatted'];
} | php | protected function pruneMessage(array $record)
{
$message = (string) $record['message'];
if (strlen($message) > $this->maxErrorMessageLength) {
$record['message'] = substr($message, 0, $this->maxErrorMessageLength) . '...';
$record['formatted'] = $this->getFormatter()->format($record);
}
return (string) $record['formatted'];
} | [
"protected",
"function",
"pruneMessage",
"(",
"array",
"$",
"record",
")",
"{",
"$",
"message",
"=",
"(",
"string",
")",
"$",
"record",
"[",
"'message'",
"]",
";",
"if",
"(",
"strlen",
"(",
"$",
"message",
")",
">",
"$",
"this",
"->",
"maxErrorMessageLength",
")",
"{",
"$",
"record",
"[",
"'message'",
"]",
"=",
"substr",
"(",
"$",
"message",
",",
"0",
",",
"$",
"this",
"->",
"maxErrorMessageLength",
")",
".",
"'...'",
";",
"$",
"record",
"[",
"'formatted'",
"]",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
")",
"->",
"format",
"(",
"$",
"record",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"record",
"[",
"'formatted'",
"]",
";",
"}"
] | Cut the error message depends on maxErrorMessageLength
@param array $record
@return string | [
"Cut",
"the",
"error",
"message",
"depends",
"on",
"maxErrorMessageLength"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Log/Monolog/Handler/StreamHandler.php#L86-L96 | train |
espocrm/espocrm | application/Espo/Core/Utils/PasswordHash.php | PasswordHash.hash | public function hash($password, $useMd5 = true)
{
$salt = $this->getSalt();
if ($useMd5) {
$password = md5($password);
}
$hash = crypt($password, $salt);
$hash = str_replace($salt, '', $hash);
return $hash;
} | php | public function hash($password, $useMd5 = true)
{
$salt = $this->getSalt();
if ($useMd5) {
$password = md5($password);
}
$hash = crypt($password, $salt);
$hash = str_replace($salt, '', $hash);
return $hash;
} | [
"public",
"function",
"hash",
"(",
"$",
"password",
",",
"$",
"useMd5",
"=",
"true",
")",
"{",
"$",
"salt",
"=",
"$",
"this",
"->",
"getSalt",
"(",
")",
";",
"if",
"(",
"$",
"useMd5",
")",
"{",
"$",
"password",
"=",
"md5",
"(",
"$",
"password",
")",
";",
"}",
"$",
"hash",
"=",
"crypt",
"(",
"$",
"password",
",",
"$",
"salt",
")",
";",
"$",
"hash",
"=",
"str_replace",
"(",
"$",
"salt",
",",
"''",
",",
"$",
"hash",
")",
";",
"return",
"$",
"hash",
";",
"}"
] | Get hash of a pawword
@param string $password
@return string | [
"Get",
"hash",
"of",
"a",
"pawword"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/PasswordHash.php#L60-L72 | train |
espocrm/espocrm | application/Espo/Core/Utils/PasswordHash.php | PasswordHash.getSalt | protected function getSalt()
{
$salt = $this->getConfig()->get('passwordSalt');
if (!isset($salt)) {
throw new Error('Option "passwordSalt" does not exist in config.php');
}
$salt = $this->normalizeSalt($salt);
return $salt;
} | php | protected function getSalt()
{
$salt = $this->getConfig()->get('passwordSalt');
if (!isset($salt)) {
throw new Error('Option "passwordSalt" does not exist in config.php');
}
$salt = $this->normalizeSalt($salt);
return $salt;
} | [
"protected",
"function",
"getSalt",
"(",
")",
"{",
"$",
"salt",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'passwordSalt'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"salt",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Option \"passwordSalt\" does not exist in config.php'",
")",
";",
"}",
"$",
"salt",
"=",
"$",
"this",
"->",
"normalizeSalt",
"(",
"$",
"salt",
")",
";",
"return",
"$",
"salt",
";",
"}"
] | Get a salt from config and normalize it
@return string | [
"Get",
"a",
"salt",
"from",
"config",
"and",
"normalize",
"it"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/PasswordHash.php#L79-L89 | train |
espocrm/espocrm | application/Espo/Core/Utils/Log/Monolog/Logger.php | Logger.getLevelCode | public function getLevelCode($levelName)
{
$levelName = strtoupper($levelName);
$levels = $this->getLevels();
if (isset($levels[$levelName])) {
return $levels[$levelName];
}
return $levels[$this->defaultLevelName];
} | php | public function getLevelCode($levelName)
{
$levelName = strtoupper($levelName);
$levels = $this->getLevels();
if (isset($levels[$levelName])) {
return $levels[$levelName];
}
return $levels[$this->defaultLevelName];
} | [
"public",
"function",
"getLevelCode",
"(",
"$",
"levelName",
")",
"{",
"$",
"levelName",
"=",
"strtoupper",
"(",
"$",
"levelName",
")",
";",
"$",
"levels",
"=",
"$",
"this",
"->",
"getLevels",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"levels",
"[",
"$",
"levelName",
"]",
")",
")",
"{",
"return",
"$",
"levels",
"[",
"$",
"levelName",
"]",
";",
"}",
"return",
"$",
"levels",
"[",
"$",
"this",
"->",
"defaultLevelName",
"]",
";",
"}"
] | Get Level Code
@param string $level Ex. DEBUG, ...
@return int | [
"Get",
"Level",
"Code"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Log/Monolog/Logger.php#L41-L52 | train |
espocrm/espocrm | install/core/Language.php | Language.mergeWithDefaults | protected function mergeWithDefaults($data)
{
$defaultLangFile = 'install/core/i18n/'.$this->defaultLanguage.'/install.json';
$defaultData = $this->getLangData($defaultLangFile);
foreach ($data as $categoryName => &$labels) {
foreach ($defaultData[$categoryName] as $defaultLabelName => $defaultLabel) {
if (!isset($labels[$defaultLabelName])) {
$labels[$defaultLabelName] = $defaultLabel;
}
}
}
$data = array_merge($defaultData, $data);
return $data;
} | php | protected function mergeWithDefaults($data)
{
$defaultLangFile = 'install/core/i18n/'.$this->defaultLanguage.'/install.json';
$defaultData = $this->getLangData($defaultLangFile);
foreach ($data as $categoryName => &$labels) {
foreach ($defaultData[$categoryName] as $defaultLabelName => $defaultLabel) {
if (!isset($labels[$defaultLabelName])) {
$labels[$defaultLabelName] = $defaultLabel;
}
}
}
$data = array_merge($defaultData, $data);
return $data;
} | [
"protected",
"function",
"mergeWithDefaults",
"(",
"$",
"data",
")",
"{",
"$",
"defaultLangFile",
"=",
"'install/core/i18n/'",
".",
"$",
"this",
"->",
"defaultLanguage",
".",
"'/install.json'",
";",
"$",
"defaultData",
"=",
"$",
"this",
"->",
"getLangData",
"(",
"$",
"defaultLangFile",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"categoryName",
"=>",
"&",
"$",
"labels",
")",
"{",
"foreach",
"(",
"$",
"defaultData",
"[",
"$",
"categoryName",
"]",
"as",
"$",
"defaultLabelName",
"=>",
"$",
"defaultLabel",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"labels",
"[",
"$",
"defaultLabelName",
"]",
")",
")",
"{",
"$",
"labels",
"[",
"$",
"defaultLabelName",
"]",
"=",
"$",
"defaultLabel",
";",
"}",
"}",
"}",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"defaultData",
",",
"$",
"data",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Merge current language with default one
@param array $data
@return array | [
"Merge",
"current",
"language",
"with",
"default",
"one"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/install/core/Language.php#L82-L98 | train |
espocrm/espocrm | install/core/Language.php | Language.afterRetrieve | protected function afterRetrieve(array &$i18n)
{
/** Get rewrite rules */
$serverType = $this->getSystemHelper()->getServerType();
$serverOs = $this->getSystemHelper()->getOs();
$rewriteRules = $this->getSystemHelper()->getRewriteRules();
if (isset($i18n['options']['modRewriteInstruction'][$serverType][$serverOs])) {
$modRewriteInstruction = $i18n['options']['modRewriteInstruction'][$serverType][$serverOs];
preg_match_all('/\{(.*?)\}/', $modRewriteInstruction, $match);
if (isset($match[1])) {
foreach ($match[1] as $varName) {
if (isset($rewriteRules[$varName])) {
$modRewriteInstruction = str_replace('{'.$varName.'}', $rewriteRules[$varName], $modRewriteInstruction);
}
}
}
$i18n['options']['modRewriteInstruction'][$serverType][$serverOs] = $modRewriteInstruction;
}
} | php | protected function afterRetrieve(array &$i18n)
{
/** Get rewrite rules */
$serverType = $this->getSystemHelper()->getServerType();
$serverOs = $this->getSystemHelper()->getOs();
$rewriteRules = $this->getSystemHelper()->getRewriteRules();
if (isset($i18n['options']['modRewriteInstruction'][$serverType][$serverOs])) {
$modRewriteInstruction = $i18n['options']['modRewriteInstruction'][$serverType][$serverOs];
preg_match_all('/\{(.*?)\}/', $modRewriteInstruction, $match);
if (isset($match[1])) {
foreach ($match[1] as $varName) {
if (isset($rewriteRules[$varName])) {
$modRewriteInstruction = str_replace('{'.$varName.'}', $rewriteRules[$varName], $modRewriteInstruction);
}
}
}
$i18n['options']['modRewriteInstruction'][$serverType][$serverOs] = $modRewriteInstruction;
}
} | [
"protected",
"function",
"afterRetrieve",
"(",
"array",
"&",
"$",
"i18n",
")",
"{",
"/** Get rewrite rules */",
"$",
"serverType",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"getServerType",
"(",
")",
";",
"$",
"serverOs",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"getOs",
"(",
")",
";",
"$",
"rewriteRules",
"=",
"$",
"this",
"->",
"getSystemHelper",
"(",
")",
"->",
"getRewriteRules",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"i18n",
"[",
"'options'",
"]",
"[",
"'modRewriteInstruction'",
"]",
"[",
"$",
"serverType",
"]",
"[",
"$",
"serverOs",
"]",
")",
")",
"{",
"$",
"modRewriteInstruction",
"=",
"$",
"i18n",
"[",
"'options'",
"]",
"[",
"'modRewriteInstruction'",
"]",
"[",
"$",
"serverType",
"]",
"[",
"$",
"serverOs",
"]",
";",
"preg_match_all",
"(",
"'/\\{(.*?)\\}/'",
",",
"$",
"modRewriteInstruction",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"match",
"[",
"1",
"]",
"as",
"$",
"varName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"rewriteRules",
"[",
"$",
"varName",
"]",
")",
")",
"{",
"$",
"modRewriteInstruction",
"=",
"str_replace",
"(",
"'{'",
".",
"$",
"varName",
".",
"'}'",
",",
"$",
"rewriteRules",
"[",
"$",
"varName",
"]",
",",
"$",
"modRewriteInstruction",
")",
";",
"}",
"}",
"}",
"$",
"i18n",
"[",
"'options'",
"]",
"[",
"'modRewriteInstruction'",
"]",
"[",
"$",
"serverType",
"]",
"[",
"$",
"serverOs",
"]",
"=",
"$",
"modRewriteInstruction",
";",
"}",
"}"
] | After retrieve actions
@param array $i18n
@return array $i18n | [
"After",
"retrieve",
"actions"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/install/core/Language.php#L114-L135 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Schema/rebuildActions/Currency.php | Currency.exchangeRates | protected function exchangeRates($baseCurrency, $defaultCurrency, array $currencyRates)
{
$precision = 5;
$defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], $precision);
$exchangedRates = array();
$exchangedRates[$baseCurrency] = $defaultCurrencyRate;
unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);
foreach ($currencyRates as $currencyName => $rate) {
$exchangedRates[$currencyName] = round($rate * $defaultCurrencyRate, $precision);
}
return $exchangedRates;
} | php | protected function exchangeRates($baseCurrency, $defaultCurrency, array $currencyRates)
{
$precision = 5;
$defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], $precision);
$exchangedRates = array();
$exchangedRates[$baseCurrency] = $defaultCurrencyRate;
unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);
foreach ($currencyRates as $currencyName => $rate) {
$exchangedRates[$currencyName] = round($rate * $defaultCurrencyRate, $precision);
}
return $exchangedRates;
} | [
"protected",
"function",
"exchangeRates",
"(",
"$",
"baseCurrency",
",",
"$",
"defaultCurrency",
",",
"array",
"$",
"currencyRates",
")",
"{",
"$",
"precision",
"=",
"5",
";",
"$",
"defaultCurrencyRate",
"=",
"round",
"(",
"1",
"/",
"$",
"currencyRates",
"[",
"$",
"defaultCurrency",
"]",
",",
"$",
"precision",
")",
";",
"$",
"exchangedRates",
"=",
"array",
"(",
")",
";",
"$",
"exchangedRates",
"[",
"$",
"baseCurrency",
"]",
"=",
"$",
"defaultCurrencyRate",
";",
"unset",
"(",
"$",
"currencyRates",
"[",
"$",
"baseCurrency",
"]",
",",
"$",
"currencyRates",
"[",
"$",
"defaultCurrency",
"]",
")",
";",
"foreach",
"(",
"$",
"currencyRates",
"as",
"$",
"currencyName",
"=>",
"$",
"rate",
")",
"{",
"$",
"exchangedRates",
"[",
"$",
"currencyName",
"]",
"=",
"round",
"(",
"$",
"rate",
"*",
"$",
"defaultCurrencyRate",
",",
"$",
"precision",
")",
";",
"}",
"return",
"$",
"exchangedRates",
";",
"}"
] | Calculate exchange rates if defaultCurrency doesn't equals baseCurrency
@param string $baseCurrency
@param string $defaultCurrency
@param array $currencyRates [description]
@return array - List of new currency rates | [
"Calculate",
"exchange",
"rates",
"if",
"defaultCurrency",
"doesn",
"t",
"equals",
"baseCurrency"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Schema/rebuildActions/Currency.php#L73-L88 | train |
espocrm/espocrm | application/Espo/Core/Utils/Json.php | Json.encode | public static function encode($value, $options = 0)
{
$json = json_encode($value, $options);
$error = self::getLastError();
if ($json === null || !empty($error)) {
$GLOBALS['log']->error('Json::encode():' . $error . ' - ' . print_r($value, true));
}
return $json;
} | php | public static function encode($value, $options = 0)
{
$json = json_encode($value, $options);
$error = self::getLastError();
if ($json === null || !empty($error)) {
$GLOBALS['log']->error('Json::encode():' . $error . ' - ' . print_r($value, true));
}
return $json;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"value",
",",
"$",
"options",
"=",
"0",
")",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"$",
"error",
"=",
"self",
"::",
"getLastError",
"(",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
"||",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"error",
"(",
"'Json::encode():'",
".",
"$",
"error",
".",
"' - '",
".",
"print_r",
"(",
"$",
"value",
",",
"true",
")",
")",
";",
"}",
"return",
"$",
"json",
";",
"}"
] | JSON encode a string
@param string $value
@param int $options Default 0
@return string | [
"JSON",
"encode",
"a",
"string"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Json.php#L41-L51 | train |
espocrm/espocrm | application/Espo/Core/Utils/Json.php | Json.isJSON | public static function isJSON($json)
{
if ($json === '[]' || $json === '{}') {
return true;
} else if (is_array($json)) {
return false;
}
return static::decode($json) != null;
} | php | public static function isJSON($json)
{
if ($json === '[]' || $json === '{}') {
return true;
} else if (is_array($json)) {
return false;
}
return static::decode($json) != null;
} | [
"public",
"static",
"function",
"isJSON",
"(",
"$",
"json",
")",
"{",
"if",
"(",
"$",
"json",
"===",
"'[]'",
"||",
"$",
"json",
"===",
"'{}'",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"json",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"static",
"::",
"decode",
"(",
"$",
"json",
")",
"!=",
"null",
";",
"}"
] | Check if the string is JSON
@param string $json
@return bool | [
"Check",
"if",
"the",
"string",
"is",
"JSON"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Json.php#L87-L96 | train |
espocrm/espocrm | application/Espo/Core/Utils/System.php | System.getServerType | public function getServerType()
{
$serverSoft = $_SERVER['SERVER_SOFTWARE'];
preg_match('/^(.*?)\//i', $serverSoft, $match);
if (empty($match[1])) {
preg_match('/^(.*)\/?/i', $serverSoft, $match);
}
$serverName = strtolower( trim($match[1]) );
return $serverName;
} | php | public function getServerType()
{
$serverSoft = $_SERVER['SERVER_SOFTWARE'];
preg_match('/^(.*?)\//i', $serverSoft, $match);
if (empty($match[1])) {
preg_match('/^(.*)\/?/i', $serverSoft, $match);
}
$serverName = strtolower( trim($match[1]) );
return $serverName;
} | [
"public",
"function",
"getServerType",
"(",
")",
"{",
"$",
"serverSoft",
"=",
"$",
"_SERVER",
"[",
"'SERVER_SOFTWARE'",
"]",
";",
"preg_match",
"(",
"'/^(.*?)\\//i'",
",",
"$",
"serverSoft",
",",
"$",
"match",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"{",
"preg_match",
"(",
"'/^(.*)\\/?/i'",
",",
"$",
"serverSoft",
",",
"$",
"match",
")",
";",
"}",
"$",
"serverName",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
";",
"return",
"$",
"serverName",
";",
"}"
] | Get web server name
@return string Ex. "microsoft-iis", "nginx", "apache" | [
"Get",
"web",
"server",
"name"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/System.php#L39-L50 | train |
espocrm/espocrm | application/Espo/Core/HookManager.php | HookManager.sortHooks | protected function sortHooks(array $hooks)
{
foreach ($hooks as $scopeName => &$scopeHooks) {
foreach ($scopeHooks as $hookName => &$hookList) {
usort($hookList, array($this, 'cmpHooks'));
}
}
return $hooks;
} | php | protected function sortHooks(array $hooks)
{
foreach ($hooks as $scopeName => &$scopeHooks) {
foreach ($scopeHooks as $hookName => &$hookList) {
usort($hookList, array($this, 'cmpHooks'));
}
}
return $hooks;
} | [
"protected",
"function",
"sortHooks",
"(",
"array",
"$",
"hooks",
")",
"{",
"foreach",
"(",
"$",
"hooks",
"as",
"$",
"scopeName",
"=>",
"&",
"$",
"scopeHooks",
")",
"{",
"foreach",
"(",
"$",
"scopeHooks",
"as",
"$",
"hookName",
"=>",
"&",
"$",
"hookList",
")",
"{",
"usort",
"(",
"$",
"hookList",
",",
"array",
"(",
"$",
"this",
",",
"'cmpHooks'",
")",
")",
";",
"}",
"}",
"return",
"$",
"hooks",
";",
"}"
] | Sort hooks by an order
@param array $hooks
@return array | [
"Sort",
"hooks",
"by",
"an",
"order"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/HookManager.php#L193-L202 | train |
espocrm/espocrm | application/Espo/Core/HookManager.php | HookManager.getHookList | protected function getHookList($scope, $hookName)
{
$key = $scope . '_' . $hookName;
if (!isset($this->hookListHash[$key])) {
$hookList = array();
if (isset($this->data['Common'][$hookName])) {
$hookList = $this->data['Common'][$hookName];
}
if (isset($this->data[$scope][$hookName])) {
$hookList = array_merge($hookList, $this->data[$scope][$hookName]);
usort($hookList, array($this, 'cmpHooks'));
}
$normalizedList = array();
foreach ($hookList as $hookData) {
$normalizedList[] = $hookData['className'];
}
$this->hookListHash[$key] = $normalizedList;
}
return $this->hookListHash[$key];
} | php | protected function getHookList($scope, $hookName)
{
$key = $scope . '_' . $hookName;
if (!isset($this->hookListHash[$key])) {
$hookList = array();
if (isset($this->data['Common'][$hookName])) {
$hookList = $this->data['Common'][$hookName];
}
if (isset($this->data[$scope][$hookName])) {
$hookList = array_merge($hookList, $this->data[$scope][$hookName]);
usort($hookList, array($this, 'cmpHooks'));
}
$normalizedList = array();
foreach ($hookList as $hookData) {
$normalizedList[] = $hookData['className'];
}
$this->hookListHash[$key] = $normalizedList;
}
return $this->hookListHash[$key];
} | [
"protected",
"function",
"getHookList",
"(",
"$",
"scope",
",",
"$",
"hookName",
")",
"{",
"$",
"key",
"=",
"$",
"scope",
".",
"'_'",
".",
"$",
"hookName",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"hookListHash",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"hookList",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'Common'",
"]",
"[",
"$",
"hookName",
"]",
")",
")",
"{",
"$",
"hookList",
"=",
"$",
"this",
"->",
"data",
"[",
"'Common'",
"]",
"[",
"$",
"hookName",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"scope",
"]",
"[",
"$",
"hookName",
"]",
")",
")",
"{",
"$",
"hookList",
"=",
"array_merge",
"(",
"$",
"hookList",
",",
"$",
"this",
"->",
"data",
"[",
"$",
"scope",
"]",
"[",
"$",
"hookName",
"]",
")",
";",
"usort",
"(",
"$",
"hookList",
",",
"array",
"(",
"$",
"this",
",",
"'cmpHooks'",
")",
")",
";",
"}",
"$",
"normalizedList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"hookList",
"as",
"$",
"hookData",
")",
"{",
"$",
"normalizedList",
"[",
"]",
"=",
"$",
"hookData",
"[",
"'className'",
"]",
";",
"}",
"$",
"this",
"->",
"hookListHash",
"[",
"$",
"key",
"]",
"=",
"$",
"normalizedList",
";",
"}",
"return",
"$",
"this",
"->",
"hookListHash",
"[",
"$",
"key",
"]",
";",
"}"
] | Get sorted hook list
@param string $scope
@param string $hookName
@return array | [
"Get",
"sorted",
"hook",
"list"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/HookManager.php#L212-L237 | train |
espocrm/espocrm | application/Espo/Core/HookManager.php | HookManager.hookExists | protected function hookExists($className, array $hookData)
{
$class = preg_replace('/^.*\\\(.*)$/', '$1', $className);
foreach ($hookData as $hookData) {
if (preg_match('/\\\\'.$class.'$/', $hookData['className'])) {
return true;
}
}
return false;
} | php | protected function hookExists($className, array $hookData)
{
$class = preg_replace('/^.*\\\(.*)$/', '$1', $className);
foreach ($hookData as $hookData) {
if (preg_match('/\\\\'.$class.'$/', $hookData['className'])) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hookExists",
"(",
"$",
"className",
",",
"array",
"$",
"hookData",
")",
"{",
"$",
"class",
"=",
"preg_replace",
"(",
"'/^.*\\\\\\(.*)$/'",
",",
"'$1'",
",",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"hookData",
"as",
"$",
"hookData",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\\\\\\\'",
".",
"$",
"class",
".",
"'$/'",
",",
"$",
"hookData",
"[",
"'className'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if hook exists in the list
@param string $className
@param array $hookData
@return boolean | [
"Check",
"if",
"hook",
"exists",
"in",
"the",
"list"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/HookManager.php#L247-L258 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Converter.php | Converter.process | public function process()
{
$entityDefs = $this->getEntityDefs(true);
$ormMetadata = array();
foreach($entityDefs as $entityName => $entityMetadata) {
if (empty($entityMetadata)) {
$GLOBALS['log']->critical('Orm\Converter:process(), Entity:'.$entityName.' - metadata cannot be converted into ORM format');
continue;
}
$ormMetadata = Util::merge($ormMetadata, $this->convertEntity($entityName, $entityMetadata));
}
$ormMetadata = $this->afterProcess($ormMetadata);
return $ormMetadata;
} | php | public function process()
{
$entityDefs = $this->getEntityDefs(true);
$ormMetadata = array();
foreach($entityDefs as $entityName => $entityMetadata) {
if (empty($entityMetadata)) {
$GLOBALS['log']->critical('Orm\Converter:process(), Entity:'.$entityName.' - metadata cannot be converted into ORM format');
continue;
}
$ormMetadata = Util::merge($ormMetadata, $this->convertEntity($entityName, $entityMetadata));
}
$ormMetadata = $this->afterProcess($ormMetadata);
return $ormMetadata;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"entityDefs",
"=",
"$",
"this",
"->",
"getEntityDefs",
"(",
"true",
")",
";",
"$",
"ormMetadata",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"entityDefs",
"as",
"$",
"entityName",
"=>",
"$",
"entityMetadata",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"entityMetadata",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"critical",
"(",
"'Orm\\Converter:process(), Entity:'",
".",
"$",
"entityName",
".",
"' - metadata cannot be converted into ORM format'",
")",
";",
"continue",
";",
"}",
"$",
"ormMetadata",
"=",
"Util",
"::",
"merge",
"(",
"$",
"ormMetadata",
",",
"$",
"this",
"->",
"convertEntity",
"(",
"$",
"entityName",
",",
"$",
"entityMetadata",
")",
")",
";",
"}",
"$",
"ormMetadata",
"=",
"$",
"this",
"->",
"afterProcess",
"(",
"$",
"ormMetadata",
")",
";",
"return",
"$",
"ormMetadata",
";",
"}"
] | Orm metadata convertation process
@return array | [
"Orm",
"metadata",
"convertation",
"process"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Converter.php#L167-L185 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Converter.php | Converter.convertFields | protected function convertFields($entityName, &$entityMetadata)
{
//List of unmerged fields with default field defenitions in $outputMeta
$unmergedFields = array(
'name',
);
$outputMeta = array(
'id' => array(
'type' => Entity::ID,
'dbType' => 'varchar'
),
'name' => array(
'type' => isset($entityMetadata['fields']['name']['type']) ? $entityMetadata['fields']['name']['type'] : Entity::VARCHAR,
'notStorable' => true
),
'deleted' => array(
'type' => Entity::BOOL,
'default' => false
)
);
foreach ($entityMetadata['fields'] as $fieldName => $fieldParams) {
if (empty($fieldParams['type'])) continue;
/** check if "fields" option exists in $fieldMeta */
$fieldTypeMetadata = $this->getMetadataHelper()->getFieldDefsByType($fieldParams);
$fieldDefs = $this->convertField($entityName, $fieldName, $fieldParams, $fieldTypeMetadata);
if ($fieldDefs !== false) {
//push fieldDefs to the ORM metadata array
if (isset($outputMeta[$fieldName]) && !in_array($fieldName, $unmergedFields)) {
$outputMeta[$fieldName] = array_merge($outputMeta[$fieldName], $fieldDefs);
} else {
$outputMeta[$fieldName] = $fieldDefs;
}
}
/** check and set the linkDefs from 'fields' metadata */
if (isset($fieldTypeMetadata['linkDefs'])) {
$linkDefs = $this->getMetadataHelper()->getLinkDefsInFieldMeta($entityName, $fieldParams, $fieldTypeMetadata['linkDefs']);
if (isset($linkDefs)) {
if (!isset($entityMetadata['links'])) {
$entityMetadata['links'] = array();
}
$entityMetadata['links'] = Util::merge( array($fieldName => $linkDefs), $entityMetadata['links'] );
}
}
}
return $outputMeta;
} | php | protected function convertFields($entityName, &$entityMetadata)
{
//List of unmerged fields with default field defenitions in $outputMeta
$unmergedFields = array(
'name',
);
$outputMeta = array(
'id' => array(
'type' => Entity::ID,
'dbType' => 'varchar'
),
'name' => array(
'type' => isset($entityMetadata['fields']['name']['type']) ? $entityMetadata['fields']['name']['type'] : Entity::VARCHAR,
'notStorable' => true
),
'deleted' => array(
'type' => Entity::BOOL,
'default' => false
)
);
foreach ($entityMetadata['fields'] as $fieldName => $fieldParams) {
if (empty($fieldParams['type'])) continue;
/** check if "fields" option exists in $fieldMeta */
$fieldTypeMetadata = $this->getMetadataHelper()->getFieldDefsByType($fieldParams);
$fieldDefs = $this->convertField($entityName, $fieldName, $fieldParams, $fieldTypeMetadata);
if ($fieldDefs !== false) {
//push fieldDefs to the ORM metadata array
if (isset($outputMeta[$fieldName]) && !in_array($fieldName, $unmergedFields)) {
$outputMeta[$fieldName] = array_merge($outputMeta[$fieldName], $fieldDefs);
} else {
$outputMeta[$fieldName] = $fieldDefs;
}
}
/** check and set the linkDefs from 'fields' metadata */
if (isset($fieldTypeMetadata['linkDefs'])) {
$linkDefs = $this->getMetadataHelper()->getLinkDefsInFieldMeta($entityName, $fieldParams, $fieldTypeMetadata['linkDefs']);
if (isset($linkDefs)) {
if (!isset($entityMetadata['links'])) {
$entityMetadata['links'] = array();
}
$entityMetadata['links'] = Util::merge( array($fieldName => $linkDefs), $entityMetadata['links'] );
}
}
}
return $outputMeta;
} | [
"protected",
"function",
"convertFields",
"(",
"$",
"entityName",
",",
"&",
"$",
"entityMetadata",
")",
"{",
"//List of unmerged fields with default field defenitions in $outputMeta",
"$",
"unmergedFields",
"=",
"array",
"(",
"'name'",
",",
")",
";",
"$",
"outputMeta",
"=",
"array",
"(",
"'id'",
"=>",
"array",
"(",
"'type'",
"=>",
"Entity",
"::",
"ID",
",",
"'dbType'",
"=>",
"'varchar'",
")",
",",
"'name'",
"=>",
"array",
"(",
"'type'",
"=>",
"isset",
"(",
"$",
"entityMetadata",
"[",
"'fields'",
"]",
"[",
"'name'",
"]",
"[",
"'type'",
"]",
")",
"?",
"$",
"entityMetadata",
"[",
"'fields'",
"]",
"[",
"'name'",
"]",
"[",
"'type'",
"]",
":",
"Entity",
"::",
"VARCHAR",
",",
"'notStorable'",
"=>",
"true",
")",
",",
"'deleted'",
"=>",
"array",
"(",
"'type'",
"=>",
"Entity",
"::",
"BOOL",
",",
"'default'",
"=>",
"false",
")",
")",
";",
"foreach",
"(",
"$",
"entityMetadata",
"[",
"'fields'",
"]",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fieldParams",
"[",
"'type'",
"]",
")",
")",
"continue",
";",
"/** check if \"fields\" option exists in $fieldMeta */",
"$",
"fieldTypeMetadata",
"=",
"$",
"this",
"->",
"getMetadataHelper",
"(",
")",
"->",
"getFieldDefsByType",
"(",
"$",
"fieldParams",
")",
";",
"$",
"fieldDefs",
"=",
"$",
"this",
"->",
"convertField",
"(",
"$",
"entityName",
",",
"$",
"fieldName",
",",
"$",
"fieldParams",
",",
"$",
"fieldTypeMetadata",
")",
";",
"if",
"(",
"$",
"fieldDefs",
"!==",
"false",
")",
"{",
"//push fieldDefs to the ORM metadata array",
"if",
"(",
"isset",
"(",
"$",
"outputMeta",
"[",
"$",
"fieldName",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"fieldName",
",",
"$",
"unmergedFields",
")",
")",
"{",
"$",
"outputMeta",
"[",
"$",
"fieldName",
"]",
"=",
"array_merge",
"(",
"$",
"outputMeta",
"[",
"$",
"fieldName",
"]",
",",
"$",
"fieldDefs",
")",
";",
"}",
"else",
"{",
"$",
"outputMeta",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"fieldDefs",
";",
"}",
"}",
"/** check and set the linkDefs from 'fields' metadata */",
"if",
"(",
"isset",
"(",
"$",
"fieldTypeMetadata",
"[",
"'linkDefs'",
"]",
")",
")",
"{",
"$",
"linkDefs",
"=",
"$",
"this",
"->",
"getMetadataHelper",
"(",
")",
"->",
"getLinkDefsInFieldMeta",
"(",
"$",
"entityName",
",",
"$",
"fieldParams",
",",
"$",
"fieldTypeMetadata",
"[",
"'linkDefs'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"linkDefs",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entityMetadata",
"[",
"'links'",
"]",
")",
")",
"{",
"$",
"entityMetadata",
"[",
"'links'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"entityMetadata",
"[",
"'links'",
"]",
"=",
"Util",
"::",
"merge",
"(",
"array",
"(",
"$",
"fieldName",
"=>",
"$",
"linkDefs",
")",
",",
"$",
"entityMetadata",
"[",
"'links'",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"outputMeta",
";",
"}"
] | Metadata conversion from Espo format into Doctrine
@param string $entityName
@param array $entityMetadata
@return array | [
"Metadata",
"conversion",
"from",
"Espo",
"format",
"into",
"Doctrine"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Converter.php#L292-L344 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Converter.php | Converter.correctFields | protected function correctFields($entityName, array $ormMetadata)
{
$entityDefs = $this->getEntityDefs();
$entityMetadata = $ormMetadata[$entityName];
//load custom field definitions and customCodes
foreach ($entityMetadata['fields'] as $fieldName => $fieldParams) {
if (empty($fieldParams['type'])) continue;
$fieldType = ucfirst($fieldParams['type']);
$className = '\Espo\Custom\Core\Utils\Database\Orm\Fields\\' . $fieldType;
if (!class_exists($className)) {
$className = '\Espo\Core\Utils\Database\Orm\Fields\\' . $fieldType;
}
if (class_exists($className) && method_exists($className, 'load')) {
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs);
$fieldResult = $helperClass->process($fieldName, $entityName);
if (isset($fieldResult['unset'])) {
$ormMetadata = Util::unsetInArray($ormMetadata, $fieldResult['unset']);
unset($fieldResult['unset']);
}
$ormMetadata = Util::merge($ormMetadata, $fieldResult);
}
$defaultAttributes = $this->metadata->get(['entityDefs', $entityName, 'fields', $fieldName, 'defaultAttributes']);
if ($defaultAttributes && array_key_exists($fieldName, $defaultAttributes)) {
$defaultMetadataPart = array(
$entityName => array(
'fields' => array(
$fieldName => array(
'default' => $defaultAttributes[$fieldName]
)
)
)
);
$ormMetadata = Util::merge($ormMetadata, $defaultMetadataPart);
}
}
//todo move to separate file
//add a field 'isFollowed' for scopes with 'stream => true'
$scopeDefs = $this->getMetadata()->get('scopes.'.$entityName);
if (isset($scopeDefs['stream']) && $scopeDefs['stream']) {
if (!isset($entityMetadata['fields']['isFollowed'])) {
$ormMetadata[$entityName]['fields']['isFollowed'] = array(
'type' => 'varchar',
'notStorable' => true,
'notExportable' => true,
);
$ormMetadata[$entityName]['fields']['followersIds'] = array(
'type' => 'jsonArray',
'notStorable' => true,
'notExportable' => true,
);
$ormMetadata[$entityName]['fields']['followersNames'] = array(
'type' => 'jsonObject',
'notStorable' => true,
'notExportable' => true,
);
}
} //END: add a field 'isFollowed' for stream => true
return $ormMetadata;
} | php | protected function correctFields($entityName, array $ormMetadata)
{
$entityDefs = $this->getEntityDefs();
$entityMetadata = $ormMetadata[$entityName];
//load custom field definitions and customCodes
foreach ($entityMetadata['fields'] as $fieldName => $fieldParams) {
if (empty($fieldParams['type'])) continue;
$fieldType = ucfirst($fieldParams['type']);
$className = '\Espo\Custom\Core\Utils\Database\Orm\Fields\\' . $fieldType;
if (!class_exists($className)) {
$className = '\Espo\Core\Utils\Database\Orm\Fields\\' . $fieldType;
}
if (class_exists($className) && method_exists($className, 'load')) {
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs);
$fieldResult = $helperClass->process($fieldName, $entityName);
if (isset($fieldResult['unset'])) {
$ormMetadata = Util::unsetInArray($ormMetadata, $fieldResult['unset']);
unset($fieldResult['unset']);
}
$ormMetadata = Util::merge($ormMetadata, $fieldResult);
}
$defaultAttributes = $this->metadata->get(['entityDefs', $entityName, 'fields', $fieldName, 'defaultAttributes']);
if ($defaultAttributes && array_key_exists($fieldName, $defaultAttributes)) {
$defaultMetadataPart = array(
$entityName => array(
'fields' => array(
$fieldName => array(
'default' => $defaultAttributes[$fieldName]
)
)
)
);
$ormMetadata = Util::merge($ormMetadata, $defaultMetadataPart);
}
}
//todo move to separate file
//add a field 'isFollowed' for scopes with 'stream => true'
$scopeDefs = $this->getMetadata()->get('scopes.'.$entityName);
if (isset($scopeDefs['stream']) && $scopeDefs['stream']) {
if (!isset($entityMetadata['fields']['isFollowed'])) {
$ormMetadata[$entityName]['fields']['isFollowed'] = array(
'type' => 'varchar',
'notStorable' => true,
'notExportable' => true,
);
$ormMetadata[$entityName]['fields']['followersIds'] = array(
'type' => 'jsonArray',
'notStorable' => true,
'notExportable' => true,
);
$ormMetadata[$entityName]['fields']['followersNames'] = array(
'type' => 'jsonObject',
'notStorable' => true,
'notExportable' => true,
);
}
} //END: add a field 'isFollowed' for stream => true
return $ormMetadata;
} | [
"protected",
"function",
"correctFields",
"(",
"$",
"entityName",
",",
"array",
"$",
"ormMetadata",
")",
"{",
"$",
"entityDefs",
"=",
"$",
"this",
"->",
"getEntityDefs",
"(",
")",
";",
"$",
"entityMetadata",
"=",
"$",
"ormMetadata",
"[",
"$",
"entityName",
"]",
";",
"//load custom field definitions and customCodes",
"foreach",
"(",
"$",
"entityMetadata",
"[",
"'fields'",
"]",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fieldParams",
"[",
"'type'",
"]",
")",
")",
"continue",
";",
"$",
"fieldType",
"=",
"ucfirst",
"(",
"$",
"fieldParams",
"[",
"'type'",
"]",
")",
";",
"$",
"className",
"=",
"'\\Espo\\Custom\\Core\\Utils\\Database\\Orm\\Fields\\\\'",
".",
"$",
"fieldType",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"className",
"=",
"'\\Espo\\Core\\Utils\\Database\\Orm\\Fields\\\\'",
".",
"$",
"fieldType",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
"&&",
"method_exists",
"(",
"$",
"className",
",",
"'load'",
")",
")",
"{",
"$",
"helperClass",
"=",
"new",
"$",
"className",
"(",
"$",
"this",
"->",
"metadata",
",",
"$",
"ormMetadata",
",",
"$",
"entityDefs",
")",
";",
"$",
"fieldResult",
"=",
"$",
"helperClass",
"->",
"process",
"(",
"$",
"fieldName",
",",
"$",
"entityName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"fieldResult",
"[",
"'unset'",
"]",
")",
")",
"{",
"$",
"ormMetadata",
"=",
"Util",
"::",
"unsetInArray",
"(",
"$",
"ormMetadata",
",",
"$",
"fieldResult",
"[",
"'unset'",
"]",
")",
";",
"unset",
"(",
"$",
"fieldResult",
"[",
"'unset'",
"]",
")",
";",
"}",
"$",
"ormMetadata",
"=",
"Util",
"::",
"merge",
"(",
"$",
"ormMetadata",
",",
"$",
"fieldResult",
")",
";",
"}",
"$",
"defaultAttributes",
"=",
"$",
"this",
"->",
"metadata",
"->",
"get",
"(",
"[",
"'entityDefs'",
",",
"$",
"entityName",
",",
"'fields'",
",",
"$",
"fieldName",
",",
"'defaultAttributes'",
"]",
")",
";",
"if",
"(",
"$",
"defaultAttributes",
"&&",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"defaultAttributes",
")",
")",
"{",
"$",
"defaultMetadataPart",
"=",
"array",
"(",
"$",
"entityName",
"=>",
"array",
"(",
"'fields'",
"=>",
"array",
"(",
"$",
"fieldName",
"=>",
"array",
"(",
"'default'",
"=>",
"$",
"defaultAttributes",
"[",
"$",
"fieldName",
"]",
")",
")",
")",
")",
";",
"$",
"ormMetadata",
"=",
"Util",
"::",
"merge",
"(",
"$",
"ormMetadata",
",",
"$",
"defaultMetadataPart",
")",
";",
"}",
"}",
"//todo move to separate file",
"//add a field 'isFollowed' for scopes with 'stream => true'",
"$",
"scopeDefs",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"get",
"(",
"'scopes.'",
".",
"$",
"entityName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"scopeDefs",
"[",
"'stream'",
"]",
")",
"&&",
"$",
"scopeDefs",
"[",
"'stream'",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entityMetadata",
"[",
"'fields'",
"]",
"[",
"'isFollowed'",
"]",
")",
")",
"{",
"$",
"ormMetadata",
"[",
"$",
"entityName",
"]",
"[",
"'fields'",
"]",
"[",
"'isFollowed'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'varchar'",
",",
"'notStorable'",
"=>",
"true",
",",
"'notExportable'",
"=>",
"true",
",",
")",
";",
"$",
"ormMetadata",
"[",
"$",
"entityName",
"]",
"[",
"'fields'",
"]",
"[",
"'followersIds'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'jsonArray'",
",",
"'notStorable'",
"=>",
"true",
",",
"'notExportable'",
"=>",
"true",
",",
")",
";",
"$",
"ormMetadata",
"[",
"$",
"entityName",
"]",
"[",
"'fields'",
"]",
"[",
"'followersNames'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"'jsonObject'",
",",
"'notStorable'",
"=>",
"true",
",",
"'notExportable'",
"=>",
"true",
",",
")",
";",
"}",
"}",
"//END: add a field 'isFollowed' for stream => true",
"return",
"$",
"ormMetadata",
";",
"}"
] | Correct fields defenitions based on \Espo\Custom\Core\Utils\Database\Orm\Fields
@param array $ormMetadata
@return array | [
"Correct",
"fields",
"defenitions",
"based",
"on",
"\\",
"Espo",
"\\",
"Custom",
"\\",
"Core",
"\\",
"Utils",
"\\",
"Database",
"\\",
"Orm",
"\\",
"Fields"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Converter.php#L353-L419 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Unifier.php | Unifier.unify | public function unify($name, $paths, $recursively = false)
{
$content = $this->unifySingle($paths['corePath'], $name, $recursively);
if (!empty($paths['modulePath'])) {
$customDir = strstr($paths['modulePath'], '{*}', true);
$moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($customDir, false, '', false);
foreach ($moduleList as $moduleName) {
$curPath = str_replace('{*}', $moduleName, $paths['modulePath']);
if ($this->useObjects) {
$content = Utils\DataUtil::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
} else {
$content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
}
}
}
if (!empty($paths['customPath'])) {
if ($this->useObjects) {
$content = Utils\DataUtil::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
} else {
$content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
}
}
return $content;
} | php | public function unify($name, $paths, $recursively = false)
{
$content = $this->unifySingle($paths['corePath'], $name, $recursively);
if (!empty($paths['modulePath'])) {
$customDir = strstr($paths['modulePath'], '{*}', true);
$moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($customDir, false, '', false);
foreach ($moduleList as $moduleName) {
$curPath = str_replace('{*}', $moduleName, $paths['modulePath']);
if ($this->useObjects) {
$content = Utils\DataUtil::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
} else {
$content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
}
}
}
if (!empty($paths['customPath'])) {
if ($this->useObjects) {
$content = Utils\DataUtil::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
} else {
$content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
}
}
return $content;
} | [
"public",
"function",
"unify",
"(",
"$",
"name",
",",
"$",
"paths",
",",
"$",
"recursively",
"=",
"false",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"unifySingle",
"(",
"$",
"paths",
"[",
"'corePath'",
"]",
",",
"$",
"name",
",",
"$",
"recursively",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
")",
"{",
"$",
"customDir",
"=",
"strstr",
"(",
"$",
"paths",
"[",
"'modulePath'",
"]",
",",
"'{*}'",
",",
"true",
")",
";",
"$",
"moduleList",
"=",
"isset",
"(",
"$",
"this",
"->",
"metadata",
")",
"?",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getModuleList",
"(",
")",
":",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getFileList",
"(",
"$",
"customDir",
",",
"false",
",",
"''",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"moduleList",
"as",
"$",
"moduleName",
")",
"{",
"$",
"curPath",
"=",
"str_replace",
"(",
"'{*}'",
",",
"$",
"moduleName",
",",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"useObjects",
")",
"{",
"$",
"content",
"=",
"Utils",
"\\",
"DataUtil",
"::",
"merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"unifySingle",
"(",
"$",
"curPath",
",",
"$",
"name",
",",
"$",
"recursively",
",",
"$",
"moduleName",
")",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"Utils",
"\\",
"Util",
"::",
"merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"unifySingle",
"(",
"$",
"curPath",
",",
"$",
"name",
",",
"$",
"recursively",
",",
"$",
"moduleName",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useObjects",
")",
"{",
"$",
"content",
"=",
"Utils",
"\\",
"DataUtil",
"::",
"merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"unifySingle",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
",",
"$",
"name",
",",
"$",
"recursively",
")",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"Utils",
"\\",
"Util",
"::",
"merge",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"unifySingle",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
",",
"$",
"name",
",",
"$",
"recursively",
")",
")",
";",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Unite file content to the file
@param string $name
@param array $paths
@param boolean $recursively Note: only for first level of sub directory, other levels of sub directories will be ignored
@return array | [
"Unite",
"file",
"content",
"to",
"the",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Unifier.php#L72-L101 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Unifier.php | Unifier.unifyGetContents | protected function unifyGetContents($paths, $defaults)
{
$fileContent = $this->getFileManager()->getContents($paths);
if ($this->useObjects) {
$decoded = Utils\Json::decode($fileContent);
} else {
$decoded = Utils\Json::getArrayData($fileContent, null);
}
if (!isset($decoded)) {
$GLOBALS['log']->emergency('Syntax error in '.Utils\Util::concatPath($paths));
if ($this->useObjects) {
return (object) [];
} else {
return array();
}
}
return $decoded;
} | php | protected function unifyGetContents($paths, $defaults)
{
$fileContent = $this->getFileManager()->getContents($paths);
if ($this->useObjects) {
$decoded = Utils\Json::decode($fileContent);
} else {
$decoded = Utils\Json::getArrayData($fileContent, null);
}
if (!isset($decoded)) {
$GLOBALS['log']->emergency('Syntax error in '.Utils\Util::concatPath($paths));
if ($this->useObjects) {
return (object) [];
} else {
return array();
}
}
return $decoded;
} | [
"protected",
"function",
"unifyGetContents",
"(",
"$",
"paths",
",",
"$",
"defaults",
")",
"{",
"$",
"fileContent",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getContents",
"(",
"$",
"paths",
")",
";",
"if",
"(",
"$",
"this",
"->",
"useObjects",
")",
"{",
"$",
"decoded",
"=",
"Utils",
"\\",
"Json",
"::",
"decode",
"(",
"$",
"fileContent",
")",
";",
"}",
"else",
"{",
"$",
"decoded",
"=",
"Utils",
"\\",
"Json",
"::",
"getArrayData",
"(",
"$",
"fileContent",
",",
"null",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"decoded",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"emergency",
"(",
"'Syntax error in '",
".",
"Utils",
"\\",
"Util",
"::",
"concatPath",
"(",
"$",
"paths",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"useObjects",
")",
"{",
"return",
"(",
"object",
")",
"[",
"]",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}",
"return",
"$",
"decoded",
";",
"}"
] | Helpful method for get content from files for unite Files
@param string | array $paths
@param string | array() $defaults - It can be a string like ["metadata","layouts"] OR an array with default values
@return array | [
"Helpful",
"method",
"for",
"get",
"content",
"from",
"files",
"for",
"unite",
"Files"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Unifier.php#L183-L203 | train |
espocrm/espocrm | application/Espo/Core/Utils/Config.php | Config.get | public function get($name, $default = null)
{
$keys = explode('.', $name);
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
return $default;
}
}
return $lastBranch;
} | php | public function get($name, $default = null)
{
$keys = explode('.', $name);
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
return $default;
}
}
return $lastBranch;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"lastBranch",
"=",
"$",
"this",
"->",
"loadConfig",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"keyName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"lastBranch",
"[",
"$",
"keyName",
"]",
")",
"&&",
"(",
"is_array",
"(",
"$",
"lastBranch",
")",
"||",
"is_object",
"(",
"$",
"lastBranch",
")",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"lastBranch",
")",
")",
"{",
"$",
"lastBranch",
"=",
"$",
"lastBranch",
"[",
"$",
"keyName",
"]",
";",
"}",
"else",
"{",
"$",
"lastBranch",
"=",
"$",
"lastBranch",
"->",
"$",
"keyName",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"return",
"$",
"lastBranch",
";",
"}"
] | Get an option from config
@param string $name
@param string $default
@return string | array | [
"Get",
"an",
"option",
"from",
"config"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Config.php#L83-L101 | train |
espocrm/espocrm | application/Espo/Core/Utils/Config.php | Config.has | public function has($name)
{
$keys = explode('.', $name);
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
return false;
}
}
return true;
} | php | public function has($name)
{
$keys = explode('.', $name);
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
return false;
}
}
return true;
} | [
"public",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"lastBranch",
"=",
"$",
"this",
"->",
"loadConfig",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"keyName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"lastBranch",
"[",
"$",
"keyName",
"]",
")",
"&&",
"(",
"is_array",
"(",
"$",
"lastBranch",
")",
"||",
"is_object",
"(",
"$",
"lastBranch",
")",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"lastBranch",
")",
")",
"{",
"$",
"lastBranch",
"=",
"$",
"lastBranch",
"[",
"$",
"keyName",
"]",
";",
"}",
"else",
"{",
"$",
"lastBranch",
"=",
"$",
"lastBranch",
"->",
"$",
"keyName",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether parameter is set
@param string $name
@return bool | [
"Whether",
"parameter",
"is",
"set"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Config.php#L109-L127 | train |
espocrm/espocrm | application/Espo/Core/Utils/Config.php | Config.set | public function set($name, $value = null, $dontMarkDirty = false)
{
if (is_object($name)) {
$name = get_object_vars($name);
}
if (!is_array($name)) {
$name = array($name => $value);
}
foreach ($name as $key => $value) {
if (in_array($key, $this->associativeArrayAttributeList) && is_object($value)) {
$value = (array) $value;
}
$this->data[$key] = $value;
if (!$dontMarkDirty) {
$this->changedData[$key] = $value;
}
}
} | php | public function set($name, $value = null, $dontMarkDirty = false)
{
if (is_object($name)) {
$name = get_object_vars($name);
}
if (!is_array($name)) {
$name = array($name => $value);
}
foreach ($name as $key => $value) {
if (in_array($key, $this->associativeArrayAttributeList) && is_object($value)) {
$value = (array) $value;
}
$this->data[$key] = $value;
if (!$dontMarkDirty) {
$this->changedData[$key] = $value;
}
}
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"dontMarkDirty",
"=",
"false",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"get_object_vars",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"array",
"(",
"$",
"name",
"=>",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"name",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"associativeArrayAttributeList",
")",
"&&",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"$",
"dontMarkDirty",
")",
"{",
"$",
"this",
"->",
"changedData",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Set an option to the config
@param string $name
@param string $value
@return bool | [
"Set",
"an",
"option",
"to",
"the",
"config"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Config.php#L136-L155 | train |
espocrm/espocrm | application/Espo/Core/Utils/Config.php | Config.remove | public function remove($name)
{
if (array_key_exists($name, $this->data)) {
unset($this->data[$name]);
$this->removeData[] = $name;
return true;
}
return null;
} | php | public function remove($name)
{
if (array_key_exists($name, $this->data)) {
unset($this->data[$name]);
$this->removeData[] = $name;
return true;
}
return null;
} | [
"public",
"function",
"remove",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
";",
"$",
"this",
"->",
"removeData",
"[",
"]",
"=",
"$",
"name",
";",
"return",
"true",
";",
"}",
"return",
"null",
";",
"}"
] | Remove an option in config
@param string $name
@return bool | null - null if an option doesn't exist | [
"Remove",
"an",
"option",
"in",
"config"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Config.php#L163-L172 | train |
espocrm/espocrm | application/Espo/Core/Utils/Config.php | Config.updateCacheTimestamp | public function updateCacheTimestamp($onlyValue = false)
{
$timestamp = [
$this->cacheTimestamp => time()
];
if ($onlyValue) {
return $timestamp;
}
return $this->set($timestamp);
} | php | public function updateCacheTimestamp($onlyValue = false)
{
$timestamp = [
$this->cacheTimestamp => time()
];
if ($onlyValue) {
return $timestamp;
}
return $this->set($timestamp);
} | [
"public",
"function",
"updateCacheTimestamp",
"(",
"$",
"onlyValue",
"=",
"false",
")",
"{",
"$",
"timestamp",
"=",
"[",
"$",
"this",
"->",
"cacheTimestamp",
"=>",
"time",
"(",
")",
"]",
";",
"if",
"(",
"$",
"onlyValue",
")",
"{",
"return",
"$",
"timestamp",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"timestamp",
")",
";",
"}"
] | Update cache timestamp
@param $onlyValue - If need to return just timestamp array
@return bool | array | [
"Update",
"cache",
"timestamp"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Config.php#L257-L268 | train |
espocrm/espocrm | application/Espo/Core/Upgrades/Actions/Base/Install.php | Install.run | public function run($data)
{
$processId = $data['id'];
$GLOBALS['log']->debug('Installation process ['.$processId.']: start run.');
if (empty($processId)) {
throw new Error('Installation package ID was not specified.');
}
$this->setProcessId($processId);
$this->initialize();
/** check if an archive is unzipped, if no then unzip */
$packagePath = $this->getPackagePath();
if (!file_exists($packagePath)) {
$this->unzipArchive();
$this->isAcceptable();
}
//check permissions copied and deleted files
$this->checkIsWritable();
$this->enableMaintenanceMode();
$this->beforeRunAction();
$this->backupExistingFiles();
//beforeInstallFiles
if (!$this->copyFiles('before')) {
$this->throwErrorAndRemovePackage('Cannot copy beforeInstall files.');
}
/* run before install script */
if (!isset($data['skipBeforeScript']) || !$data['skipBeforeScript']) {
$this->runScript('before');
}
/* remove files defined in a manifest "deleteBeforeCopy" */
$this->deleteFiles('deleteBeforeCopy', true);
/* copy files from directory "Files" to EspoCRM files */
if (!$this->copyFiles()) {
$this->throwErrorAndRemovePackage('Cannot copy files.');
}
/* remove files defined in a manifest */
$this->deleteFiles('delete', true);
$this->deleteFiles('vendor');
$this->copyFiles('vendor');
$this->disableMaintenanceMode();
if (!isset($data['skipSystemRebuild']) || !$data['skipSystemRebuild']) {
if (!$this->systemRebuild()) {
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
}
}
//afterInstallFiles
if (!$this->copyFiles('after')) {
$this->throwErrorAndRemovePackage('Cannot copy afterInstall files.');
}
/* run after install script */
if (!isset($data['skipAfterScript']) || !$data['skipAfterScript']) {
$this->runScript('after');
}
$this->afterRunAction();
$this->finalize();
/* delete unziped files */
$this->deletePackageFiles();
if ($this->getManifestParam('skipBackup')) {
$this->getFileManager()->removeInDir([$this->getPath('backupPath'), self::FILES]);
}
$GLOBALS['log']->debug('Installation process ['.$processId.']: end run.');
$this->clearCache();
} | php | public function run($data)
{
$processId = $data['id'];
$GLOBALS['log']->debug('Installation process ['.$processId.']: start run.');
if (empty($processId)) {
throw new Error('Installation package ID was not specified.');
}
$this->setProcessId($processId);
$this->initialize();
/** check if an archive is unzipped, if no then unzip */
$packagePath = $this->getPackagePath();
if (!file_exists($packagePath)) {
$this->unzipArchive();
$this->isAcceptable();
}
//check permissions copied and deleted files
$this->checkIsWritable();
$this->enableMaintenanceMode();
$this->beforeRunAction();
$this->backupExistingFiles();
//beforeInstallFiles
if (!$this->copyFiles('before')) {
$this->throwErrorAndRemovePackage('Cannot copy beforeInstall files.');
}
/* run before install script */
if (!isset($data['skipBeforeScript']) || !$data['skipBeforeScript']) {
$this->runScript('before');
}
/* remove files defined in a manifest "deleteBeforeCopy" */
$this->deleteFiles('deleteBeforeCopy', true);
/* copy files from directory "Files" to EspoCRM files */
if (!$this->copyFiles()) {
$this->throwErrorAndRemovePackage('Cannot copy files.');
}
/* remove files defined in a manifest */
$this->deleteFiles('delete', true);
$this->deleteFiles('vendor');
$this->copyFiles('vendor');
$this->disableMaintenanceMode();
if (!isset($data['skipSystemRebuild']) || !$data['skipSystemRebuild']) {
if (!$this->systemRebuild()) {
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
}
}
//afterInstallFiles
if (!$this->copyFiles('after')) {
$this->throwErrorAndRemovePackage('Cannot copy afterInstall files.');
}
/* run after install script */
if (!isset($data['skipAfterScript']) || !$data['skipAfterScript']) {
$this->runScript('after');
}
$this->afterRunAction();
$this->finalize();
/* delete unziped files */
$this->deletePackageFiles();
if ($this->getManifestParam('skipBackup')) {
$this->getFileManager()->removeInDir([$this->getPath('backupPath'), self::FILES]);
}
$GLOBALS['log']->debug('Installation process ['.$processId.']: end run.');
$this->clearCache();
} | [
"public",
"function",
"run",
"(",
"$",
"data",
")",
"{",
"$",
"processId",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'Installation process ['",
".",
"$",
"processId",
".",
"']: start run.'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"processId",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Installation package ID was not specified.'",
")",
";",
"}",
"$",
"this",
"->",
"setProcessId",
"(",
"$",
"processId",
")",
";",
"$",
"this",
"->",
"initialize",
"(",
")",
";",
"/** check if an archive is unzipped, if no then unzip */",
"$",
"packagePath",
"=",
"$",
"this",
"->",
"getPackagePath",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"packagePath",
")",
")",
"{",
"$",
"this",
"->",
"unzipArchive",
"(",
")",
";",
"$",
"this",
"->",
"isAcceptable",
"(",
")",
";",
"}",
"//check permissions copied and deleted files",
"$",
"this",
"->",
"checkIsWritable",
"(",
")",
";",
"$",
"this",
"->",
"enableMaintenanceMode",
"(",
")",
";",
"$",
"this",
"->",
"beforeRunAction",
"(",
")",
";",
"$",
"this",
"->",
"backupExistingFiles",
"(",
")",
";",
"//beforeInstallFiles",
"if",
"(",
"!",
"$",
"this",
"->",
"copyFiles",
"(",
"'before'",
")",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"'Cannot copy beforeInstall files.'",
")",
";",
"}",
"/* run before install script */",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'skipBeforeScript'",
"]",
")",
"||",
"!",
"$",
"data",
"[",
"'skipBeforeScript'",
"]",
")",
"{",
"$",
"this",
"->",
"runScript",
"(",
"'before'",
")",
";",
"}",
"/* remove files defined in a manifest \"deleteBeforeCopy\" */",
"$",
"this",
"->",
"deleteFiles",
"(",
"'deleteBeforeCopy'",
",",
"true",
")",
";",
"/* copy files from directory \"Files\" to EspoCRM files */",
"if",
"(",
"!",
"$",
"this",
"->",
"copyFiles",
"(",
")",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"'Cannot copy files.'",
")",
";",
"}",
"/* remove files defined in a manifest */",
"$",
"this",
"->",
"deleteFiles",
"(",
"'delete'",
",",
"true",
")",
";",
"$",
"this",
"->",
"deleteFiles",
"(",
"'vendor'",
")",
";",
"$",
"this",
"->",
"copyFiles",
"(",
"'vendor'",
")",
";",
"$",
"this",
"->",
"disableMaintenanceMode",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'skipSystemRebuild'",
"]",
")",
"||",
"!",
"$",
"data",
"[",
"'skipSystemRebuild'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"systemRebuild",
"(",
")",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"'Error occurred while EspoCRM rebuild.'",
")",
";",
"}",
"}",
"//afterInstallFiles",
"if",
"(",
"!",
"$",
"this",
"->",
"copyFiles",
"(",
"'after'",
")",
")",
"{",
"$",
"this",
"->",
"throwErrorAndRemovePackage",
"(",
"'Cannot copy afterInstall files.'",
")",
";",
"}",
"/* run after install script */",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'skipAfterScript'",
"]",
")",
"||",
"!",
"$",
"data",
"[",
"'skipAfterScript'",
"]",
")",
"{",
"$",
"this",
"->",
"runScript",
"(",
"'after'",
")",
";",
"}",
"$",
"this",
"->",
"afterRunAction",
"(",
")",
";",
"$",
"this",
"->",
"finalize",
"(",
")",
";",
"/* delete unziped files */",
"$",
"this",
"->",
"deletePackageFiles",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getManifestParam",
"(",
"'skipBackup'",
")",
")",
"{",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"removeInDir",
"(",
"[",
"$",
"this",
"->",
"getPath",
"(",
"'backupPath'",
")",
",",
"self",
"::",
"FILES",
"]",
")",
";",
"}",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'Installation process ['",
".",
"$",
"processId",
".",
"']: end run.'",
")",
";",
"$",
"this",
"->",
"clearCache",
"(",
")",
";",
"}"
] | Main installation process
@param string $processId Upgrade/Extension ID, gotten in upload stage
@return bool | [
"Main",
"installation",
"process"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Upgrades/Actions/Base/Install.php#L42-L128 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Schema/Schema.php | Schema.initRebuildActions | protected function initRebuildActions($currentSchema = null, $metadataSchema = null)
{
$methods = array('beforeRebuild', 'afterRebuild');
$this->getClassParser()->setAllowedMethods($methods);
$rebuildActions = $this->getClassParser()->getData($this->rebuildActionsPath);
$classes = array();
foreach ($rebuildActions as $actionName => $actionClass) {
$rebuildActionClass = new $actionClass($this->metadata, $this->config, $this->entityManager);
if (isset($currentSchema)) {
$rebuildActionClass->setCurrentSchema($currentSchema);
}
if (isset($metadataSchema)) {
$rebuildActionClass->setMetadataSchema($metadataSchema);
}
foreach ($methods as $methodName) {
if (method_exists($rebuildActionClass, $methodName)) {
$classes[$methodName][] = $rebuildActionClass;
}
}
}
$this->rebuildActionClasses = $classes;
} | php | protected function initRebuildActions($currentSchema = null, $metadataSchema = null)
{
$methods = array('beforeRebuild', 'afterRebuild');
$this->getClassParser()->setAllowedMethods($methods);
$rebuildActions = $this->getClassParser()->getData($this->rebuildActionsPath);
$classes = array();
foreach ($rebuildActions as $actionName => $actionClass) {
$rebuildActionClass = new $actionClass($this->metadata, $this->config, $this->entityManager);
if (isset($currentSchema)) {
$rebuildActionClass->setCurrentSchema($currentSchema);
}
if (isset($metadataSchema)) {
$rebuildActionClass->setMetadataSchema($metadataSchema);
}
foreach ($methods as $methodName) {
if (method_exists($rebuildActionClass, $methodName)) {
$classes[$methodName][] = $rebuildActionClass;
}
}
}
$this->rebuildActionClasses = $classes;
} | [
"protected",
"function",
"initRebuildActions",
"(",
"$",
"currentSchema",
"=",
"null",
",",
"$",
"metadataSchema",
"=",
"null",
")",
"{",
"$",
"methods",
"=",
"array",
"(",
"'beforeRebuild'",
",",
"'afterRebuild'",
")",
";",
"$",
"this",
"->",
"getClassParser",
"(",
")",
"->",
"setAllowedMethods",
"(",
"$",
"methods",
")",
";",
"$",
"rebuildActions",
"=",
"$",
"this",
"->",
"getClassParser",
"(",
")",
"->",
"getData",
"(",
"$",
"this",
"->",
"rebuildActionsPath",
")",
";",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rebuildActions",
"as",
"$",
"actionName",
"=>",
"$",
"actionClass",
")",
"{",
"$",
"rebuildActionClass",
"=",
"new",
"$",
"actionClass",
"(",
"$",
"this",
"->",
"metadata",
",",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"entityManager",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"currentSchema",
")",
")",
"{",
"$",
"rebuildActionClass",
"->",
"setCurrentSchema",
"(",
"$",
"currentSchema",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"metadataSchema",
")",
")",
"{",
"$",
"rebuildActionClass",
"->",
"setMetadataSchema",
"(",
"$",
"metadataSchema",
")",
";",
"}",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"methodName",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"rebuildActionClass",
",",
"$",
"methodName",
")",
")",
"{",
"$",
"classes",
"[",
"$",
"methodName",
"]",
"[",
"]",
"=",
"$",
"rebuildActionClass",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"rebuildActionClasses",
"=",
"$",
"classes",
";",
"}"
] | Init Rebuild Actions, get all classes and create them
@return void | [
"Init",
"Rebuild",
"Actions",
"get",
"all",
"classes",
"and",
"create",
"them"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Schema/Schema.php#L247-L272 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Schema/Schema.php | Schema.executeRebuildActions | protected function executeRebuildActions($action = 'beforeRebuild')
{
if (!isset($this->rebuildActionClasses)) {
$this->initRebuildActions();
}
if (isset($this->rebuildActionClasses[$action])) {
foreach ($this->rebuildActionClasses[$action] as $rebuildActionClass) {
$rebuildActionClass->$action();
}
}
} | php | protected function executeRebuildActions($action = 'beforeRebuild')
{
if (!isset($this->rebuildActionClasses)) {
$this->initRebuildActions();
}
if (isset($this->rebuildActionClasses[$action])) {
foreach ($this->rebuildActionClasses[$action] as $rebuildActionClass) {
$rebuildActionClass->$action();
}
}
} | [
"protected",
"function",
"executeRebuildActions",
"(",
"$",
"action",
"=",
"'beforeRebuild'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rebuildActionClasses",
")",
")",
"{",
"$",
"this",
"->",
"initRebuildActions",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rebuildActionClasses",
"[",
"$",
"action",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rebuildActionClasses",
"[",
"$",
"action",
"]",
"as",
"$",
"rebuildActionClass",
")",
"{",
"$",
"rebuildActionClass",
"->",
"$",
"action",
"(",
")",
";",
"}",
"}",
"}"
] | Execute actions for RebuildAction classes
@param string $action action name, possible values 'beforeRebuild' | 'afterRebuild'
@return void | [
"Execute",
"actions",
"for",
"RebuildAction",
"classes"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Schema/Schema.php#L279-L290 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Schema/Converter.php | Converter.prepareManyMany | protected function prepareManyMany($entityName, $relationParams, $tables)
{
$tableName = Util::toUnderScore($relationParams['relationName']);
if ($this->getSchema()->hasTable($tableName)) {
$GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.');
return $this->getSchema()->getTable($tableName);
}
$table = $this->getSchema()->createTable($tableName);
$table->addColumn('id', 'int', $this->getDbFieldParams(array(
'type' => 'id',
'len' => $this->defaultLength['int'],
'autoincrement' => true,
)));
//add midKeys to a schema
$uniqueIndex = array();
foreach($relationParams['midKeys'] as $index => $midKey) {
$columnName = Util::toUnderScore($midKey);
$table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array(
'type' => 'foreignId',
'len' => $this->idParams['len'],
)));
$table->addIndex(array($columnName));
$uniqueIndex[] = $columnName;
}
//END: add midKeys to a schema
//add additionalColumns
if (!empty($relationParams['additionalColumns'])) {
foreach($relationParams['additionalColumns'] as $fieldName => $fieldParams) {
if (!isset($fieldParams['type'])) {
$fieldParams = array_merge($fieldParams, array(
'type' => 'varchar',
'len' => $this->defaultLength['varchar'],
));
}
$table->addColumn(Util::toUnderScore($fieldName), $fieldParams['type'], $this->getDbFieldParams($fieldParams));
}
} //END: add additionalColumns
//add unique indexes
if (!empty($relationParams['conditions'])) {
foreach ($relationParams['conditions'] as $fieldName => $fieldParams) {
$uniqueIndex[] = Util::toUnderScore($fieldName);
}
}
if (!empty($uniqueIndex)) {
$table->addUniqueIndex($uniqueIndex);
}
//END: add unique indexes
$table->addColumn('deleted', 'bool', $this->getDbFieldParams(array(
'type' => 'bool',
'default' => false,
)));
$table->setPrimaryKey(array("id"));
return $table;
} | php | protected function prepareManyMany($entityName, $relationParams, $tables)
{
$tableName = Util::toUnderScore($relationParams['relationName']);
if ($this->getSchema()->hasTable($tableName)) {
$GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.');
return $this->getSchema()->getTable($tableName);
}
$table = $this->getSchema()->createTable($tableName);
$table->addColumn('id', 'int', $this->getDbFieldParams(array(
'type' => 'id',
'len' => $this->defaultLength['int'],
'autoincrement' => true,
)));
//add midKeys to a schema
$uniqueIndex = array();
foreach($relationParams['midKeys'] as $index => $midKey) {
$columnName = Util::toUnderScore($midKey);
$table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array(
'type' => 'foreignId',
'len' => $this->idParams['len'],
)));
$table->addIndex(array($columnName));
$uniqueIndex[] = $columnName;
}
//END: add midKeys to a schema
//add additionalColumns
if (!empty($relationParams['additionalColumns'])) {
foreach($relationParams['additionalColumns'] as $fieldName => $fieldParams) {
if (!isset($fieldParams['type'])) {
$fieldParams = array_merge($fieldParams, array(
'type' => 'varchar',
'len' => $this->defaultLength['varchar'],
));
}
$table->addColumn(Util::toUnderScore($fieldName), $fieldParams['type'], $this->getDbFieldParams($fieldParams));
}
} //END: add additionalColumns
//add unique indexes
if (!empty($relationParams['conditions'])) {
foreach ($relationParams['conditions'] as $fieldName => $fieldParams) {
$uniqueIndex[] = Util::toUnderScore($fieldName);
}
}
if (!empty($uniqueIndex)) {
$table->addUniqueIndex($uniqueIndex);
}
//END: add unique indexes
$table->addColumn('deleted', 'bool', $this->getDbFieldParams(array(
'type' => 'bool',
'default' => false,
)));
$table->setPrimaryKey(array("id"));
return $table;
} | [
"protected",
"function",
"prepareManyMany",
"(",
"$",
"entityName",
",",
"$",
"relationParams",
",",
"$",
"tables",
")",
"{",
"$",
"tableName",
"=",
"Util",
"::",
"toUnderScore",
"(",
"$",
"relationParams",
"[",
"'relationName'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"hasTable",
"(",
"$",
"tableName",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"debug",
"(",
"'DBAL: Table ['",
".",
"$",
"tableName",
".",
"'] exists.'",
")",
";",
"return",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getTable",
"(",
"$",
"tableName",
")",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"createTable",
"(",
"$",
"tableName",
")",
";",
"$",
"table",
"->",
"addColumn",
"(",
"'id'",
",",
"'int'",
",",
"$",
"this",
"->",
"getDbFieldParams",
"(",
"array",
"(",
"'type'",
"=>",
"'id'",
",",
"'len'",
"=>",
"$",
"this",
"->",
"defaultLength",
"[",
"'int'",
"]",
",",
"'autoincrement'",
"=>",
"true",
",",
")",
")",
")",
";",
"//add midKeys to a schema",
"$",
"uniqueIndex",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"relationParams",
"[",
"'midKeys'",
"]",
"as",
"$",
"index",
"=>",
"$",
"midKey",
")",
"{",
"$",
"columnName",
"=",
"Util",
"::",
"toUnderScore",
"(",
"$",
"midKey",
")",
";",
"$",
"table",
"->",
"addColumn",
"(",
"$",
"columnName",
",",
"$",
"this",
"->",
"idParams",
"[",
"'dbType'",
"]",
",",
"$",
"this",
"->",
"getDbFieldParams",
"(",
"array",
"(",
"'type'",
"=>",
"'foreignId'",
",",
"'len'",
"=>",
"$",
"this",
"->",
"idParams",
"[",
"'len'",
"]",
",",
")",
")",
")",
";",
"$",
"table",
"->",
"addIndex",
"(",
"array",
"(",
"$",
"columnName",
")",
")",
";",
"$",
"uniqueIndex",
"[",
"]",
"=",
"$",
"columnName",
";",
"}",
"//END: add midKeys to a schema",
"//add additionalColumns",
"if",
"(",
"!",
"empty",
"(",
"$",
"relationParams",
"[",
"'additionalColumns'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"relationParams",
"[",
"'additionalColumns'",
"]",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldParams",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldParams",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"fieldParams",
"=",
"array_merge",
"(",
"$",
"fieldParams",
",",
"array",
"(",
"'type'",
"=>",
"'varchar'",
",",
"'len'",
"=>",
"$",
"this",
"->",
"defaultLength",
"[",
"'varchar'",
"]",
",",
")",
")",
";",
"}",
"$",
"table",
"->",
"addColumn",
"(",
"Util",
"::",
"toUnderScore",
"(",
"$",
"fieldName",
")",
",",
"$",
"fieldParams",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"getDbFieldParams",
"(",
"$",
"fieldParams",
")",
")",
";",
"}",
"}",
"//END: add additionalColumns",
"//add unique indexes",
"if",
"(",
"!",
"empty",
"(",
"$",
"relationParams",
"[",
"'conditions'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"relationParams",
"[",
"'conditions'",
"]",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldParams",
")",
"{",
"$",
"uniqueIndex",
"[",
"]",
"=",
"Util",
"::",
"toUnderScore",
"(",
"$",
"fieldName",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"uniqueIndex",
")",
")",
"{",
"$",
"table",
"->",
"addUniqueIndex",
"(",
"$",
"uniqueIndex",
")",
";",
"}",
"//END: add unique indexes",
"$",
"table",
"->",
"addColumn",
"(",
"'deleted'",
",",
"'bool'",
",",
"$",
"this",
"->",
"getDbFieldParams",
"(",
"array",
"(",
"'type'",
"=>",
"'bool'",
",",
"'default'",
"=>",
"false",
",",
")",
")",
")",
";",
"$",
"table",
"->",
"setPrimaryKey",
"(",
"array",
"(",
"\"id\"",
")",
")",
";",
"return",
"$",
"table",
";",
"}"
] | Prepare a relation table for the manyMany relation
@param string $entityName
@param array $relationParams
@param array $tables
@return \Doctrine\DBAL\Schema\Table | [
"Prepare",
"a",
"relation",
"table",
"for",
"the",
"manyMany",
"relation"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Schema/Converter.php#L298-L364 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.toCamelCase | public static function toCamelCase($name, $symbol = '_', $capitaliseFirstChar = false)
{
if (is_array($name)) {
foreach ($name as &$value) {
$value = static::toCamelCase($value, $symbol, $capitaliseFirstChar);
}
return $name;
}
$name = lcfirst($name);
if ($capitaliseFirstChar) {
$name = ucfirst($name);
}
return preg_replace_callback('/'.$symbol.'([a-zA-Z])/', 'static::toCamelCaseConversion', $name);
} | php | public static function toCamelCase($name, $symbol = '_', $capitaliseFirstChar = false)
{
if (is_array($name)) {
foreach ($name as &$value) {
$value = static::toCamelCase($value, $symbol, $capitaliseFirstChar);
}
return $name;
}
$name = lcfirst($name);
if ($capitaliseFirstChar) {
$name = ucfirst($name);
}
return preg_replace_callback('/'.$symbol.'([a-zA-Z])/', 'static::toCamelCaseConversion', $name);
} | [
"public",
"static",
"function",
"toCamelCase",
"(",
"$",
"name",
",",
"$",
"symbol",
"=",
"'_'",
",",
"$",
"capitaliseFirstChar",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"toCamelCase",
"(",
"$",
"value",
",",
"$",
"symbol",
",",
"$",
"capitaliseFirstChar",
")",
";",
"}",
"return",
"$",
"name",
";",
"}",
"$",
"name",
"=",
"lcfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"capitaliseFirstChar",
")",
"{",
"$",
"name",
"=",
"ucfirst",
"(",
"$",
"name",
")",
";",
"}",
"return",
"preg_replace_callback",
"(",
"'/'",
".",
"$",
"symbol",
".",
"'([a-zA-Z])/'",
",",
"'static::toCamelCaseConversion'",
",",
"$",
"name",
")",
";",
"}"
] | Convert name to Camel Case format, ex. camel_case to camelCase
@param string $name
@param string | array $symbol
@param boolean $capitaliseFirstChar
@return string | [
"Convert",
"name",
"to",
"Camel",
"Case",
"format",
"ex",
".",
"camel_case",
"to",
"camelCase"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L89-L105 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.fromCamelCase | public static function fromCamelCase($name, $symbol = '_')
{
if (is_array($name)) {
foreach ($name as &$value) {
$value = static::fromCamelCase($value, $symbol);
}
return $name;
}
$name[0] = strtolower($name[0]);
return preg_replace_callback('/([A-Z])/', function ($matches) use ($symbol) {
return $symbol . strtolower($matches[1]);
}, $name);
} | php | public static function fromCamelCase($name, $symbol = '_')
{
if (is_array($name)) {
foreach ($name as &$value) {
$value = static::fromCamelCase($value, $symbol);
}
return $name;
}
$name[0] = strtolower($name[0]);
return preg_replace_callback('/([A-Z])/', function ($matches) use ($symbol) {
return $symbol . strtolower($matches[1]);
}, $name);
} | [
"public",
"static",
"function",
"fromCamelCase",
"(",
"$",
"name",
",",
"$",
"symbol",
"=",
"'_'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"fromCamelCase",
"(",
"$",
"value",
",",
"$",
"symbol",
")",
";",
"}",
"return",
"$",
"name",
";",
"}",
"$",
"name",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"name",
"[",
"0",
"]",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"symbol",
")",
"{",
"return",
"$",
"symbol",
".",
"strtolower",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
",",
"$",
"name",
")",
";",
"}"
] | Convert name from Camel Case format.
ex. camelCase to camel-case
@param string | array $name
@return string | [
"Convert",
"name",
"from",
"Camel",
"Case",
"format",
".",
"ex",
".",
"camelCase",
"to",
"camel",
"-",
"case"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L120-L134 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.unsetInArrayByValue | public static function unsetInArrayByValue($needle, array $haystack, $reIndex = true)
{
$doReindex = false;
foreach($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = static::unsetInArrayByValue($needle, $value);
} else if ($needle === $value) {
unset($haystack[$key]);
if ($reIndex) {
$doReindex = true;
}
}
}
if ($doReindex) {
$haystack = array_values($haystack);
}
return $haystack;
} | php | public static function unsetInArrayByValue($needle, array $haystack, $reIndex = true)
{
$doReindex = false;
foreach($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = static::unsetInArrayByValue($needle, $value);
} else if ($needle === $value) {
unset($haystack[$key]);
if ($reIndex) {
$doReindex = true;
}
}
}
if ($doReindex) {
$haystack = array_values($haystack);
}
return $haystack;
} | [
"public",
"static",
"function",
"unsetInArrayByValue",
"(",
"$",
"needle",
",",
"array",
"$",
"haystack",
",",
"$",
"reIndex",
"=",
"true",
")",
"{",
"$",
"doReindex",
"=",
"false",
";",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"haystack",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"unsetInArrayByValue",
"(",
"$",
"needle",
",",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"needle",
"===",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"haystack",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"reIndex",
")",
"{",
"$",
"doReindex",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"doReindex",
")",
"{",
"$",
"haystack",
"=",
"array_values",
"(",
"$",
"haystack",
")",
";",
"}",
"return",
"$",
"haystack",
";",
"}"
] | Unset a value in array recursively
@param string $needle
@param array $haystack
@param bool $reIndex
@return array | [
"Unset",
"a",
"value",
"in",
"array",
"recursively"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L203-L225 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.concatPath | public static function concatPath($folderPath, $filePath = null)
{
if (is_array($folderPath)) {
$fullPath = '';
foreach ($folderPath as $path) {
$fullPath = static::concatPath($fullPath, $path);
}
return static::fixPath($fullPath);
}
if (empty($filePath)) {
return static::fixPath($folderPath);
}
if (empty($folderPath)) {
return static::fixPath($filePath);
}
if (substr($folderPath, -1) == static::getSeparator() || substr($folderPath, -1) == '/') {
return static::fixPath($folderPath . $filePath);
}
return $folderPath . static::getSeparator() . $filePath;
} | php | public static function concatPath($folderPath, $filePath = null)
{
if (is_array($folderPath)) {
$fullPath = '';
foreach ($folderPath as $path) {
$fullPath = static::concatPath($fullPath, $path);
}
return static::fixPath($fullPath);
}
if (empty($filePath)) {
return static::fixPath($folderPath);
}
if (empty($folderPath)) {
return static::fixPath($filePath);
}
if (substr($folderPath, -1) == static::getSeparator() || substr($folderPath, -1) == '/') {
return static::fixPath($folderPath . $filePath);
}
return $folderPath . static::getSeparator() . $filePath;
} | [
"public",
"static",
"function",
"concatPath",
"(",
"$",
"folderPath",
",",
"$",
"filePath",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"folderPath",
")",
")",
"{",
"$",
"fullPath",
"=",
"''",
";",
"foreach",
"(",
"$",
"folderPath",
"as",
"$",
"path",
")",
"{",
"$",
"fullPath",
"=",
"static",
"::",
"concatPath",
"(",
"$",
"fullPath",
",",
"$",
"path",
")",
";",
"}",
"return",
"static",
"::",
"fixPath",
"(",
"$",
"fullPath",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"filePath",
")",
")",
"{",
"return",
"static",
"::",
"fixPath",
"(",
"$",
"folderPath",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"folderPath",
")",
")",
"{",
"return",
"static",
"::",
"fixPath",
"(",
"$",
"filePath",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"folderPath",
",",
"-",
"1",
")",
"==",
"static",
"::",
"getSeparator",
"(",
")",
"||",
"substr",
"(",
"$",
"folderPath",
",",
"-",
"1",
")",
"==",
"'/'",
")",
"{",
"return",
"static",
"::",
"fixPath",
"(",
"$",
"folderPath",
".",
"$",
"filePath",
")",
";",
"}",
"return",
"$",
"folderPath",
".",
"static",
"::",
"getSeparator",
"(",
")",
".",
"$",
"filePath",
";",
"}"
] | Get a full path of the file
@param string | array $folderPath - Folder path, Ex. myfolder
@param string $filePath - File path, Ex. file.json
@return string | [
"Get",
"a",
"full",
"path",
"of",
"the",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L235-L256 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.objectToArray | public static function objectToArray($object)
{
if (is_object($object)) {
$object = (array) $object;
}
return is_array($object) ? array_map("static::objectToArray", $object) : $object;
} | php | public static function objectToArray($object)
{
if (is_object($object)) {
$object = (array) $object;
}
return is_array($object) ? array_map("static::objectToArray", $object) : $object;
} | [
"public",
"static",
"function",
"objectToArray",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"$",
"object",
"=",
"(",
"array",
")",
"$",
"object",
";",
"}",
"return",
"is_array",
"(",
"$",
"object",
")",
"?",
"array_map",
"(",
"\"static::objectToArray\"",
",",
"$",
"object",
")",
":",
"$",
"object",
";",
"}"
] | Convert object to array format recursively
@param object $object
@return array | [
"Convert",
"object",
"to",
"array",
"format",
"recursively"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L290-L297 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.