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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
concrete5/concrete5 | concrete/src/Csv/Import/AbstractImporter.php | AbstractImporter.setCategory | protected function setCategory(CategoryInterface $category)
{
$this->category = $category;
$this->attributeKeysAndControllers = null;
$this->csvHeader = null;
return $this;
} | php | protected function setCategory(CategoryInterface $category)
{
$this->category = $category;
$this->attributeKeysAndControllers = null;
$this->csvHeader = null;
return $this;
} | [
"protected",
"function",
"setCategory",
"(",
"CategoryInterface",
"$",
"category",
")",
"{",
"$",
"this",
"->",
"category",
"=",
"$",
"category",
";",
"$",
"this",
"->",
"attributeKeysAndControllers",
"=",
"null",
";",
"$",
"this",
"->",
"csvHeader",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] | Set the attribute category to be used to export the data.
@param CategoryInterface $category
@return $this | [
"Set",
"the",
"attribute",
"category",
"to",
"be",
"used",
"to",
"export",
"the",
"data",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Csv/Import/AbstractImporter.php#L303-L310 | train |
concrete5/concrete5 | concrete/src/Csv/Import/AbstractImporter.php | AbstractImporter.getAttributeKeysAndControllers | protected function getAttributeKeysAndControllers()
{
if ($this->attributeKeysAndControllers === null) {
$list = [];
foreach ($this->category->getList() as $attributeKey) {
$list[] = [$attributeKey, $attributeKey->getController()];
}
$this->attributeKeysAndControllers = $list;
}
return $this->attributeKeysAndControllers;
} | php | protected function getAttributeKeysAndControllers()
{
if ($this->attributeKeysAndControllers === null) {
$list = [];
foreach ($this->category->getList() as $attributeKey) {
$list[] = [$attributeKey, $attributeKey->getController()];
}
$this->attributeKeysAndControllers = $list;
}
return $this->attributeKeysAndControllers;
} | [
"protected",
"function",
"getAttributeKeysAndControllers",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attributeKeysAndControllers",
"===",
"null",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"category",
"->",
"getList",
"(",
")",
"as",
"$",
"attributeKey",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"[",
"$",
"attributeKey",
",",
"$",
"attributeKey",
"->",
"getController",
"(",
")",
"]",
";",
"}",
"$",
"this",
"->",
"attributeKeysAndControllers",
"=",
"$",
"list",
";",
"}",
"return",
"$",
"this",
"->",
"attributeKeysAndControllers",
";",
"}"
] | Get a list the attribute keys and controllers for the current category.
@return array | [
"Get",
"a",
"list",
"the",
"attribute",
"keys",
"and",
"controllers",
"for",
"the",
"current",
"category",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Csv/Import/AbstractImporter.php#L349-L360 | train |
concrete5/concrete5 | concrete/src/Csv/Import/AbstractImporter.php | AbstractImporter.convertCsvDataForAttributeController | private function convertCsvDataForAttributeController(AttributeController $attributeController, $csvData)
{
$result = $csvData;
if ($attributeController instanceof MulticolumnTextExportableAttributeInterface) {
$attributeHeaders = $attributeController->getAttributeTextRepresentationHeaders();
$result = array_pad([], count($attributeHeaders), '');
foreach ($attributeHeaders as $attributeHeaderIndex => $attributeHeaderName) {
if (isset($csvData[$attributeHeaderName])) {
$result[$attributeHeaderIndex] = $csvData[$attributeHeaderName];
}
}
}
return $result;
} | php | private function convertCsvDataForAttributeController(AttributeController $attributeController, $csvData)
{
$result = $csvData;
if ($attributeController instanceof MulticolumnTextExportableAttributeInterface) {
$attributeHeaders = $attributeController->getAttributeTextRepresentationHeaders();
$result = array_pad([], count($attributeHeaders), '');
foreach ($attributeHeaders as $attributeHeaderIndex => $attributeHeaderName) {
if (isset($csvData[$attributeHeaderName])) {
$result[$attributeHeaderIndex] = $csvData[$attributeHeaderName];
}
}
}
return $result;
} | [
"private",
"function",
"convertCsvDataForAttributeController",
"(",
"AttributeController",
"$",
"attributeController",
",",
"$",
"csvData",
")",
"{",
"$",
"result",
"=",
"$",
"csvData",
";",
"if",
"(",
"$",
"attributeController",
"instanceof",
"MulticolumnTextExportableAttributeInterface",
")",
"{",
"$",
"attributeHeaders",
"=",
"$",
"attributeController",
"->",
"getAttributeTextRepresentationHeaders",
"(",
")",
";",
"$",
"result",
"=",
"array_pad",
"(",
"[",
"]",
",",
"count",
"(",
"$",
"attributeHeaders",
")",
",",
"''",
")",
";",
"foreach",
"(",
"$",
"attributeHeaders",
"as",
"$",
"attributeHeaderIndex",
"=>",
"$",
"attributeHeaderName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"csvData",
"[",
"$",
"attributeHeaderName",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"attributeHeaderIndex",
"]",
"=",
"$",
"csvData",
"[",
"$",
"attributeHeaderName",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Convert the data read from CSV to be passed to the attribute controller.
@param AttributeController $controller
@param string|array $csvData
@param AttributeController $attributeController
@return string|string[] | [
"Convert",
"the",
"data",
"read",
"from",
"CSV",
"to",
"be",
"passed",
"to",
"the",
"attribute",
"controller",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Csv/Import/AbstractImporter.php#L421-L435 | train |
concrete5/concrete5 | concrete/src/Session/SessionValidator.php | SessionValidator.hasActiveSession | public function hasActiveSession()
{
$cookie = $this->app['cookie'];
return $cookie->has($this->config->get('concrete.session.name')) || $cookie->has('ccmAuthUserHash');
} | php | public function hasActiveSession()
{
$cookie = $this->app['cookie'];
return $cookie->has($this->config->get('concrete.session.name')) || $cookie->has('ccmAuthUserHash');
} | [
"public",
"function",
"hasActiveSession",
"(",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"app",
"[",
"'cookie'",
"]",
";",
"return",
"$",
"cookie",
"->",
"has",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'concrete.session.name'",
")",
")",
"||",
"$",
"cookie",
"->",
"has",
"(",
"'ccmAuthUserHash'",
")",
";",
"}"
] | Check if there is an active session.
@return bool | [
"Check",
"if",
"there",
"is",
"an",
"active",
"session",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionValidator.php#L165-L170 | train |
concrete5/concrete5 | concrete/src/Error/ErrorList/ErrorList.php | ErrorList.containsField | public function containsField($field)
{
$identifier = $field instanceof FieldInterface ? $field->getFieldElementName() : $field;
foreach ($this->getList() as $error) {
$field = $error->getField();
if (is_object($field) && $field->getFieldElementName() == $identifier) {
return true;
}
}
return false;
} | php | public function containsField($field)
{
$identifier = $field instanceof FieldInterface ? $field->getFieldElementName() : $field;
foreach ($this->getList() as $error) {
$field = $error->getField();
if (is_object($field) && $field->getFieldElementName() == $identifier) {
return true;
}
}
return false;
} | [
"public",
"function",
"containsField",
"(",
"$",
"field",
")",
"{",
"$",
"identifier",
"=",
"$",
"field",
"instanceof",
"FieldInterface",
"?",
"$",
"field",
"->",
"getFieldElementName",
"(",
")",
":",
"$",
"field",
";",
"foreach",
"(",
"$",
"this",
"->",
"getList",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"field",
"=",
"$",
"error",
"->",
"getField",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"field",
")",
"&&",
"$",
"field",
"->",
"getFieldElementName",
"(",
")",
"==",
"$",
"identifier",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Does this list contain error associated to a field?
@param \Concrete\Core\Error\ErrorList\Field\FieldInterface|string $field
@return bool | [
"Does",
"this",
"list",
"contain",
"error",
"associated",
"to",
"a",
"field?"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/ErrorList/ErrorList.php#L234-L245 | train |
concrete5/concrete5 | concrete/src/Service/Detector/HTTP/NginxDetector.php | NginxDetector.detectFromServer | private function detectFromServer($value)
{
$result = null;
if (is_string($value) && preg_match('/\bnginx\/(\d+(\.\d+)+)/i', $value, $m)) {
$result = $m[1];
}
return $result;
} | php | private function detectFromServer($value)
{
$result = null;
if (is_string($value) && preg_match('/\bnginx\/(\d+(\.\d+)+)/i', $value, $m)) {
$result = $m[1];
}
return $result;
} | [
"private",
"function",
"detectFromServer",
"(",
"$",
"value",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"preg_match",
"(",
"'/\\bnginx\\/(\\d+(\\.\\d+)+)/i'",
",",
"$",
"value",
",",
"$",
"m",
")",
")",
"{",
"$",
"result",
"=",
"$",
"m",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Detect from the SERVER_SOFTWARE key of the superglobal server array.
@param string $value
@return null|string | [
"Detect",
"from",
"the",
"SERVER_SOFTWARE",
"key",
"of",
"the",
"superglobal",
"server",
"array",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Detector/HTTP/NginxDetector.php#L56-L64 | train |
concrete5/concrete5 | concrete/src/Notification/View/UserDeactivatedListView.php | UserDeactivatedListView.getActionDescription | public function getActionDescription()
{
$entityManager = $this->getApplication()->make(EntityManagerInterface::class);
/** @var User $user */
$user = $entityManager->find(User::class, $this->notification->getUserID());
$actor = null;
$actorID = $this->notification->getActorID();
if ($actorID) {
/** @var User $actor */
$actor = $entityManager->find(User::class, $actorID);
}
if ($actorID) {
return t(
'%s has been manually deactivated by %s',
$this->getUserLink($user),
$this->getUserLink($actor));
}
return t('%s has been automatically deactivated.', $this->getUserLink($user));
} | php | public function getActionDescription()
{
$entityManager = $this->getApplication()->make(EntityManagerInterface::class);
/** @var User $user */
$user = $entityManager->find(User::class, $this->notification->getUserID());
$actor = null;
$actorID = $this->notification->getActorID();
if ($actorID) {
/** @var User $actor */
$actor = $entityManager->find(User::class, $actorID);
}
if ($actorID) {
return t(
'%s has been manually deactivated by %s',
$this->getUserLink($user),
$this->getUserLink($actor));
}
return t('%s has been automatically deactivated.', $this->getUserLink($user));
} | [
"public",
"function",
"getActionDescription",
"(",
")",
"{",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"/** @var User $user */",
"$",
"user",
"=",
"$",
"entityManager",
"->",
"find",
"(",
"User",
"::",
"class",
",",
"$",
"this",
"->",
"notification",
"->",
"getUserID",
"(",
")",
")",
";",
"$",
"actor",
"=",
"null",
";",
"$",
"actorID",
"=",
"$",
"this",
"->",
"notification",
"->",
"getActorID",
"(",
")",
";",
"if",
"(",
"$",
"actorID",
")",
"{",
"/** @var User $actor */",
"$",
"actor",
"=",
"$",
"entityManager",
"->",
"find",
"(",
"User",
"::",
"class",
",",
"$",
"actorID",
")",
";",
"}",
"if",
"(",
"$",
"actorID",
")",
"{",
"return",
"t",
"(",
"'%s has been manually deactivated by %s'",
",",
"$",
"this",
"->",
"getUserLink",
"(",
"$",
"user",
")",
",",
"$",
"this",
"->",
"getUserLink",
"(",
"$",
"actor",
")",
")",
";",
"}",
"return",
"t",
"(",
"'%s has been automatically deactivated.'",
",",
"$",
"this",
"->",
"getUserLink",
"(",
"$",
"user",
")",
")",
";",
"}"
] | Build the description for this notification
@return string | [
"Build",
"the",
"description",
"for",
"this",
"notification"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Notification/View/UserDeactivatedListView.php#L42-L64 | train |
concrete5/concrete5 | concrete/src/Notification/View/UserDeactivatedListView.php | UserDeactivatedListView.getUrlResolver | protected function getUrlResolver()
{
if (!$this->resolver) {
$this->resolver = $this->getApplication()->make(ResolverManagerInterface::class);
}
return $this->resolver;
} | php | protected function getUrlResolver()
{
if (!$this->resolver) {
$this->resolver = $this->getApplication()->make(ResolverManagerInterface::class);
}
return $this->resolver;
} | [
"protected",
"function",
"getUrlResolver",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"resolver",
")",
"{",
"$",
"this",
"->",
"resolver",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"make",
"(",
"ResolverManagerInterface",
"::",
"class",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolver",
";",
"}"
] | Resolve the url resolver instance
@return \Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface | [
"Resolve",
"the",
"url",
"resolver",
"instance"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Notification/View/UserDeactivatedListView.php#L109-L116 | train |
concrete5/concrete5 | concrete/src/Database/DatabaseStructureManager.php | DatabaseStructureManager.refreshEntities | public function refreshEntities()
{
$metadatas = $this->clearCacheAndProxies();
// Finally, we update the schema
$tool = new SchemaTool($this->entityManager);
$tool->updateSchema($metadatas, true);
} | php | public function refreshEntities()
{
$metadatas = $this->clearCacheAndProxies();
// Finally, we update the schema
$tool = new SchemaTool($this->entityManager);
$tool->updateSchema($metadatas, true);
} | [
"public",
"function",
"refreshEntities",
"(",
")",
"{",
"$",
"metadatas",
"=",
"$",
"this",
"->",
"clearCacheAndProxies",
"(",
")",
";",
"// Finally, we update the schema",
"$",
"tool",
"=",
"new",
"SchemaTool",
"(",
"$",
"this",
"->",
"entityManager",
")",
";",
"$",
"tool",
"->",
"updateSchema",
"(",
"$",
"metadatas",
",",
"true",
")",
";",
"}"
] | Clears cache, regenerates all proxy classes, and updates metadatas in all entity managers | [
"Clears",
"cache",
"regenerates",
"all",
"proxy",
"classes",
"and",
"updates",
"metadatas",
"in",
"all",
"entity",
"managers"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/DatabaseStructureManager.php#L402-L410 | train |
concrete5/concrete5 | concrete/src/Error/ErrorList/Formatter/TextFormatter.php | TextFormatter.getText | public function getText()
{
$lines = [];
if ($this->error->has()) {
foreach ($this->error->getList() as $error) {
if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) {
$lines[] = strip_tags((string) $error);
} else {
$lines[] = (string) $error;
}
}
}
return implode("\n", $lines);
} | php | public function getText()
{
$lines = [];
if ($this->error->has()) {
foreach ($this->error->getList() as $error) {
if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) {
$lines[] = strip_tags((string) $error);
} else {
$lines[] = (string) $error;
}
}
}
return implode("\n", $lines);
} | [
"public",
"function",
"getText",
"(",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"error",
"->",
"has",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"error",
"->",
"getList",
"(",
")",
"as",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"error",
"instanceof",
"HtmlAwareErrorInterface",
"&&",
"$",
"error",
"->",
"messageContainsHtml",
"(",
")",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"strip_tags",
"(",
"(",
"string",
")",
"$",
"error",
")",
";",
"}",
"else",
"{",
"$",
"lines",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"error",
";",
"}",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Build an plain text string describing the errors.
@return string | [
"Build",
"an",
"plain",
"text",
"string",
"describing",
"the",
"errors",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/ErrorList/Formatter/TextFormatter.php#L24-L38 | train |
concrete5/concrete5 | concrete/src/Updater/Archive.php | Archive.uploadZipToTemp | protected function uploadZipToTemp($file)
{
if (!file_exists($file)) {
throw new Exception(t('Could not transfer to temp directory - file not found.'));
} else {
$dir = time();
copy($file, $this->f->getTemporaryDirectory() . '/'. $dir . '.zip');
return $dir;
}
} | php | protected function uploadZipToTemp($file)
{
if (!file_exists($file)) {
throw new Exception(t('Could not transfer to temp directory - file not found.'));
} else {
$dir = time();
copy($file, $this->f->getTemporaryDirectory() . '/'. $dir . '.zip');
return $dir;
}
} | [
"protected",
"function",
"uploadZipToTemp",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Could not transfer to temp directory - file not found.'",
")",
")",
";",
"}",
"else",
"{",
"$",
"dir",
"=",
"time",
"(",
")",
";",
"copy",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"f",
"->",
"getTemporaryDirectory",
"(",
")",
".",
"'/'",
".",
"$",
"dir",
".",
"'.zip'",
")",
";",
"return",
"$",
"dir",
";",
"}",
"}"
] | Moves an uploaded file to the tmp directory.
@param string $file The full path of the file to copy
@return string Return the base name of the file copied to the temporary directory. | [
"Moves",
"an",
"uploaded",
"file",
"to",
"the",
"tmp",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Updater/Archive.php#L35-L45 | train |
concrete5/concrete5 | concrete/src/Updater/Archive.php | Archive.install | protected function install($file, $inplace = false)
{
if (!$inplace) {
$directory = $this->uploadZipToTemp($file);
} else {
$directory = $file;
}
$dir = $this->unzip($directory);
$dirFull = $this->getArchiveDirectory($dir);
$dirFull = str_replace(DIRECTORY_SEPARATOR, '/', $dirFull);
$dirBase = substr(strrchr($dirFull, '/'), 1);
if (file_exists($this->targetDirectory . '/' . $dirBase)) {
throw new Exception(t('The directory %s already exists. Perhaps this item has already been installed.', $this->targetDirectory . '/' . $dirBase));
} else {
$this->f->copyAll($dirFull, $this->targetDirectory . '/' . $dirBase);
if (!is_dir($this->targetDirectory . '/' . $dirBase)) {
throw new Exception(t('Unable to copy directory %s to %s. Perhaps permissions are set incorrectly or the target directory does not exist.', $dirBase, $this->targetDirectory));
}
}
return $dirBase;
} | php | protected function install($file, $inplace = false)
{
if (!$inplace) {
$directory = $this->uploadZipToTemp($file);
} else {
$directory = $file;
}
$dir = $this->unzip($directory);
$dirFull = $this->getArchiveDirectory($dir);
$dirFull = str_replace(DIRECTORY_SEPARATOR, '/', $dirFull);
$dirBase = substr(strrchr($dirFull, '/'), 1);
if (file_exists($this->targetDirectory . '/' . $dirBase)) {
throw new Exception(t('The directory %s already exists. Perhaps this item has already been installed.', $this->targetDirectory . '/' . $dirBase));
} else {
$this->f->copyAll($dirFull, $this->targetDirectory . '/' . $dirBase);
if (!is_dir($this->targetDirectory . '/' . $dirBase)) {
throw new Exception(t('Unable to copy directory %s to %s. Perhaps permissions are set incorrectly or the target directory does not exist.', $dirBase, $this->targetDirectory));
}
}
return $dirBase;
} | [
"protected",
"function",
"install",
"(",
"$",
"file",
",",
"$",
"inplace",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"inplace",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"uploadZipToTemp",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"directory",
"=",
"$",
"file",
";",
"}",
"$",
"dir",
"=",
"$",
"this",
"->",
"unzip",
"(",
"$",
"directory",
")",
";",
"$",
"dirFull",
"=",
"$",
"this",
"->",
"getArchiveDirectory",
"(",
"$",
"dir",
")",
";",
"$",
"dirFull",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"dirFull",
")",
";",
"$",
"dirBase",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"dirFull",
",",
"'/'",
")",
",",
"1",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"targetDirectory",
".",
"'/'",
".",
"$",
"dirBase",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'The directory %s already exists. Perhaps this item has already been installed.'",
",",
"$",
"this",
"->",
"targetDirectory",
".",
"'/'",
".",
"$",
"dirBase",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"f",
"->",
"copyAll",
"(",
"$",
"dirFull",
",",
"$",
"this",
"->",
"targetDirectory",
".",
"'/'",
".",
"$",
"dirBase",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"targetDirectory",
".",
"'/'",
".",
"$",
"dirBase",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unable to copy directory %s to %s. Perhaps permissions are set incorrectly or the target directory does not exist.'",
",",
"$",
"dirBase",
",",
"$",
"this",
"->",
"targetDirectory",
")",
")",
";",
"}",
"}",
"return",
"$",
"dirBase",
";",
"}"
] | Installs a zip file from the passed directory.
@todo This is theme-specific - it really ought to be moved to the page_theme_archive class, at least most it.
@param string $zipfile
@param bool $inplace Set to false if $file should be moved to the temporary directory before working on it, set to true if it's already in the temp directory.
@return string Returns the base directory into which the zipfile was unzipped | [
"Installs",
"a",
"zip",
"file",
"from",
"the",
"passed",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Updater/Archive.php#L100-L121 | train |
concrete5/concrete5 | concrete/src/Attribute/Key/Key.php | Key.load | public function load($akID)
{
$em = $this->getFacadeApplication()->make('Doctrine\ORM\EntityManager');
$this->legacyAttributeKey = $em->find('Concrete\Core\Entity\Attribute\Key\LegacyKey', $akID);
} | php | public function load($akID)
{
$em = $this->getFacadeApplication()->make('Doctrine\ORM\EntityManager');
$this->legacyAttributeKey = $em->find('Concrete\Core\Entity\Attribute\Key\LegacyKey', $akID);
} | [
"public",
"function",
"load",
"(",
"$",
"akID",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getFacadeApplication",
"(",
")",
"->",
"make",
"(",
"'Doctrine\\ORM\\EntityManager'",
")",
";",
"$",
"this",
"->",
"legacyAttributeKey",
"=",
"$",
"em",
"->",
"find",
"(",
"'Concrete\\Core\\Entity\\Attribute\\Key\\LegacyKey'",
",",
"$",
"akID",
")",
";",
"}"
] | In 5.7 and earlier, if a subclassed Key object called load, it was loading the
core data of an attribute key. we're going to load that data into an internal
legacy key object that we can keep around to pass calls to for attribute keys that
incorrectly subclass this Key object.
@deprecated | [
"In",
"5",
".",
"7",
"and",
"earlier",
"if",
"a",
"subclassed",
"Key",
"object",
"called",
"load",
"it",
"was",
"loading",
"the",
"core",
"data",
"of",
"an",
"attribute",
"key",
".",
"we",
"re",
"going",
"to",
"load",
"that",
"data",
"into",
"an",
"internal",
"legacy",
"key",
"object",
"that",
"we",
"can",
"keep",
"around",
"to",
"pass",
"calls",
"to",
"for",
"attribute",
"keys",
"that",
"incorrectly",
"subclass",
"this",
"Key",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Key/Key.php#L128-L132 | train |
concrete5/concrete5 | concrete/src/Foundation/Repetition/AbstractRepetition.php | AbstractRepetition.dateDiffNoDST | protected function dateDiffNoDST(\DateTime $from, \DateTime $to)
{
$fromUTC = new \DateTime($from->format('Y-m-d\TH:i:s+00:00'));
$toUTC = new \DateTime($to->format('Y-m-d\TH:i:s+00:00'));
return $fromUTC->diff($toUTC);
} | php | protected function dateDiffNoDST(\DateTime $from, \DateTime $to)
{
$fromUTC = new \DateTime($from->format('Y-m-d\TH:i:s+00:00'));
$toUTC = new \DateTime($to->format('Y-m-d\TH:i:s+00:00'));
return $fromUTC->diff($toUTC);
} | [
"protected",
"function",
"dateDiffNoDST",
"(",
"\\",
"DateTime",
"$",
"from",
",",
"\\",
"DateTime",
"$",
"to",
")",
"{",
"$",
"fromUTC",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"from",
"->",
"format",
"(",
"'Y-m-d\\TH:i:s+00:00'",
")",
")",
";",
"$",
"toUTC",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"to",
"->",
"format",
"(",
"'Y-m-d\\TH:i:s+00:00'",
")",
")",
";",
"return",
"$",
"fromUTC",
"->",
"diff",
"(",
"$",
"toUTC",
")",
";",
"}"
] | Returns the difference between two DateTime objects without considering DST changes.
@param \DateTime $from
@param \DateTime $to
@return \DateInterval | [
"Returns",
"the",
"difference",
"between",
"two",
"DateTime",
"objects",
"without",
"considering",
"DST",
"changes",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Repetition/AbstractRepetition.php#L903-L909 | train |
concrete5/concrete5 | concrete/src/Attribute/Category/AbstractCategory.php | AbstractCategory.add | public function add($type, $key, $settings = null, $pkg = null)
{
if (is_string($type)) {
$typeFactory = $this->application->make(TypeFactory::class);
/* @var TypeFactory $typeFactory */
$type = $typeFactory->getByHandle($type);
}
// Legacy array support for $key
$asID = false;
if (is_array($key)) {
$handle = $key['akHandle'];
$name = $key['akName'];
if (isset($key['asID'])) {
$asID = $key['asID'];
}
$key = $this->createAttributeKey();
$key->setAttributeKeyHandle($handle);
$key->setAttributeKeyName($name);
}
// Legacy support for third parameter which used to be package
if ($settings instanceof Package || $settings instanceof \Concrete\Core\Package\Package) {
$pkg = $settings;
$settings = null;
}
if (!$settings) {
$settings = $type->getController()->getAttributeKeySettings();
}
$key->setAttributeType($type);
$this->entityManager->persist($key);
$this->entityManager->flush();
$settings->setAttributeKey($key);
$key->setAttributeKeySettings($settings);
$this->entityManager->persist($settings);
$this->entityManager->flush();
if (is_object($pkg)) {
$key->setPackage($pkg);
}
// Modify the category's search indexer.
$indexer = $this->getSearchIndexer();
if (is_object($indexer)) {
$indexer->updateRepositoryColumns($this, $key);
}
$this->entityManager->persist($key);
$this->entityManager->flush();
/* legacy support, attribute set */
if ($asID) {
$manager = $this->getSetManager();
$factory = new SetFactory($this->entityManager);
$set = $factory->getByID($asID);
if ($set !== null) {
$manager->addKey($set, $key);
}
}
return $key;
} | php | public function add($type, $key, $settings = null, $pkg = null)
{
if (is_string($type)) {
$typeFactory = $this->application->make(TypeFactory::class);
/* @var TypeFactory $typeFactory */
$type = $typeFactory->getByHandle($type);
}
// Legacy array support for $key
$asID = false;
if (is_array($key)) {
$handle = $key['akHandle'];
$name = $key['akName'];
if (isset($key['asID'])) {
$asID = $key['asID'];
}
$key = $this->createAttributeKey();
$key->setAttributeKeyHandle($handle);
$key->setAttributeKeyName($name);
}
// Legacy support for third parameter which used to be package
if ($settings instanceof Package || $settings instanceof \Concrete\Core\Package\Package) {
$pkg = $settings;
$settings = null;
}
if (!$settings) {
$settings = $type->getController()->getAttributeKeySettings();
}
$key->setAttributeType($type);
$this->entityManager->persist($key);
$this->entityManager->flush();
$settings->setAttributeKey($key);
$key->setAttributeKeySettings($settings);
$this->entityManager->persist($settings);
$this->entityManager->flush();
if (is_object($pkg)) {
$key->setPackage($pkg);
}
// Modify the category's search indexer.
$indexer = $this->getSearchIndexer();
if (is_object($indexer)) {
$indexer->updateRepositoryColumns($this, $key);
}
$this->entityManager->persist($key);
$this->entityManager->flush();
/* legacy support, attribute set */
if ($asID) {
$manager = $this->getSetManager();
$factory = new SetFactory($this->entityManager);
$set = $factory->getByID($asID);
if ($set !== null) {
$manager->addKey($set, $key);
}
}
return $key;
} | [
"public",
"function",
"add",
"(",
"$",
"type",
",",
"$",
"key",
",",
"$",
"settings",
"=",
"null",
",",
"$",
"pkg",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"$",
"typeFactory",
"=",
"$",
"this",
"->",
"application",
"->",
"make",
"(",
"TypeFactory",
"::",
"class",
")",
";",
"/* @var TypeFactory $typeFactory */",
"$",
"type",
"=",
"$",
"typeFactory",
"->",
"getByHandle",
"(",
"$",
"type",
")",
";",
"}",
"// Legacy array support for $key",
"$",
"asID",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"handle",
"=",
"$",
"key",
"[",
"'akHandle'",
"]",
";",
"$",
"name",
"=",
"$",
"key",
"[",
"'akName'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"key",
"[",
"'asID'",
"]",
")",
")",
"{",
"$",
"asID",
"=",
"$",
"key",
"[",
"'asID'",
"]",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"createAttributeKey",
"(",
")",
";",
"$",
"key",
"->",
"setAttributeKeyHandle",
"(",
"$",
"handle",
")",
";",
"$",
"key",
"->",
"setAttributeKeyName",
"(",
"$",
"name",
")",
";",
"}",
"// Legacy support for third parameter which used to be package",
"if",
"(",
"$",
"settings",
"instanceof",
"Package",
"||",
"$",
"settings",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Package",
"\\",
"Package",
")",
"{",
"$",
"pkg",
"=",
"$",
"settings",
";",
"$",
"settings",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"settings",
")",
"{",
"$",
"settings",
"=",
"$",
"type",
"->",
"getController",
"(",
")",
"->",
"getAttributeKeySettings",
"(",
")",
";",
"}",
"$",
"key",
"->",
"setAttributeType",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"$",
"settings",
"->",
"setAttributeKey",
"(",
"$",
"key",
")",
";",
"$",
"key",
"->",
"setAttributeKeySettings",
"(",
"$",
"settings",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"settings",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"pkg",
")",
")",
"{",
"$",
"key",
"->",
"setPackage",
"(",
"$",
"pkg",
")",
";",
"}",
"// Modify the category's search indexer.",
"$",
"indexer",
"=",
"$",
"this",
"->",
"getSearchIndexer",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"indexer",
")",
")",
"{",
"$",
"indexer",
"->",
"updateRepositoryColumns",
"(",
"$",
"this",
",",
"$",
"key",
")",
";",
"}",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"/* legacy support, attribute set */",
"if",
"(",
"$",
"asID",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getSetManager",
"(",
")",
";",
"$",
"factory",
"=",
"new",
"SetFactory",
"(",
"$",
"this",
"->",
"entityManager",
")",
";",
"$",
"set",
"=",
"$",
"factory",
"->",
"getByID",
"(",
"$",
"asID",
")",
";",
"if",
"(",
"$",
"set",
"!==",
"null",
")",
"{",
"$",
"manager",
"->",
"addKey",
"(",
"$",
"set",
",",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"key",
";",
"}"
] | Add a new attribute key.
@param \Concrete\Core\Entity\Attribute\Type|string $type the attribute type (or its handle)
@param \Concrete\Core\Entity\Attribute\Key\Key|array $key an empty attribute key, or an array with keys 'akHandle' (the attribute key handle), 'akName' (the attribute key name) and optionally 'asID' (the ID of the attribute set)
@param \Concrete\Core\Entity\Attribute\Key\Settings\Settings|null $settings the attribute key settings (if not specified, a new settings instance will be created)
@param \Concrete\Core\Entity\Package|null $pkg the entity of the package that's creating the attribute key
@return \Concrete\Core\Entity\Attribute\Key\Key | [
"Add",
"a",
"new",
"attribute",
"key",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/AbstractCategory.php#L208-L274 | train |
concrete5/concrete5 | concrete/src/Attribute/Category/AbstractCategory.php | AbstractCategory.import | public function import(AttributeType $type, SimpleXMLElement $element, Package $package = null)
{
$key = $this->createAttributeKey();
$loader = $this->getImportLoader();
$loader->load($key, $element);
$controller = $type->getController();
$settings = $controller->importKey($element);
if (!is_object($settings)) {
$settings = $controller->getAttributeKeySettings();
}
return $this->add($type, $key, $settings, $package);
} | php | public function import(AttributeType $type, SimpleXMLElement $element, Package $package = null)
{
$key = $this->createAttributeKey();
$loader = $this->getImportLoader();
$loader->load($key, $element);
$controller = $type->getController();
$settings = $controller->importKey($element);
if (!is_object($settings)) {
$settings = $controller->getAttributeKeySettings();
}
return $this->add($type, $key, $settings, $package);
} | [
"public",
"function",
"import",
"(",
"AttributeType",
"$",
"type",
",",
"SimpleXMLElement",
"$",
"element",
",",
"Package",
"$",
"package",
"=",
"null",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"createAttributeKey",
"(",
")",
";",
"$",
"loader",
"=",
"$",
"this",
"->",
"getImportLoader",
"(",
")",
";",
"$",
"loader",
"->",
"load",
"(",
"$",
"key",
",",
"$",
"element",
")",
";",
"$",
"controller",
"=",
"$",
"type",
"->",
"getController",
"(",
")",
";",
"$",
"settings",
"=",
"$",
"controller",
"->",
"importKey",
"(",
"$",
"element",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"settings",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"controller",
"->",
"getAttributeKeySettings",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"type",
",",
"$",
"key",
",",
"$",
"settings",
",",
"$",
"package",
")",
";",
"}"
] | Import a new attribute key from a SimpleXMLElement instance.
@param AttributeType $type the type of the attribute key to be created
@param SimpleXMLElement $element the SimpleXMLElement instance containing the data of the attribute key to be created
@param Package|null $package the entity of the package that's creating the attribute key (if applicable)
@return \Concrete\Core\Entity\Attribute\Key\Key | [
"Import",
"a",
"new",
"attribute",
"key",
"from",
"a",
"SimpleXMLElement",
"instance",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/AbstractCategory.php#L312-L325 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.shutdown | public function shutdown($options = [])
{
\Events::dispatch('on_shutdown');
if ($this->isInstalled()) {
if (!isset($options['jobs']) || $options['jobs'] == false) {
$this->handleScheduledJobs();
}
foreach (\Database::getConnections() as $connection) {
$connection->close();
}
}
exit;
} | php | public function shutdown($options = [])
{
\Events::dispatch('on_shutdown');
if ($this->isInstalled()) {
if (!isset($options['jobs']) || $options['jobs'] == false) {
$this->handleScheduledJobs();
}
foreach (\Database::getConnections() as $connection) {
$connection->close();
}
}
exit;
} | [
"public",
"function",
"shutdown",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"\\",
"Events",
"::",
"dispatch",
"(",
"'on_shutdown'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isInstalled",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'jobs'",
"]",
")",
"||",
"$",
"options",
"[",
"'jobs'",
"]",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"handleScheduledJobs",
"(",
")",
";",
"}",
"foreach",
"(",
"\\",
"Database",
"::",
"getConnections",
"(",
")",
"as",
"$",
"connection",
")",
"{",
"$",
"connection",
"->",
"close",
"(",
")",
";",
"}",
"}",
"exit",
";",
"}"
] | Turns off the lights.
@param array $options Array of options for disabling certain things during shutdown
Add `'jobs' => true` to disable scheduled jobs
Add `'log_queries' => true` to disable query logging | [
"Turns",
"off",
"the",
"lights",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L55-L69 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.handleScheduledJobs | protected function handleScheduledJobs()
{
$config = $this['config'];
if ($config->get('concrete.jobs.enable_scheduling')) {
$c = Page::getCurrentPage();
if ($c instanceof Page && !$c->isAdminArea()) {
// check for non dashboard page
$jobs = Job::getList(true);
$auth = Job::generateAuth();
$url = '';
// jobs
if (count($jobs)) {
foreach ($jobs as $j) {
if ($j->isScheduledForNow()) {
$url = View::url(
'/ccm/system/jobs/run_single?auth=' . $auth . '&jID=' . $j->getJobID(
)
);
break;
}
}
}
// job sets
if (!strlen($url)) {
$jSets = JobSet::getList(true);
if (is_array($jSets) && count($jSets)) {
foreach ($jSets as $set) {
if ($set->isScheduledForNow()) {
$url = View::url(
'/ccm/system/jobs?auth=' . $auth . '&jsID=' . $set->getJobSetID(
)
);
break;
}
}
}
}
if (strlen($url)) {
try {
$this->make('http/client')->setUri($url)->send();
} catch (Exception $x) {
}
}
}
}
} | php | protected function handleScheduledJobs()
{
$config = $this['config'];
if ($config->get('concrete.jobs.enable_scheduling')) {
$c = Page::getCurrentPage();
if ($c instanceof Page && !$c->isAdminArea()) {
// check for non dashboard page
$jobs = Job::getList(true);
$auth = Job::generateAuth();
$url = '';
// jobs
if (count($jobs)) {
foreach ($jobs as $j) {
if ($j->isScheduledForNow()) {
$url = View::url(
'/ccm/system/jobs/run_single?auth=' . $auth . '&jID=' . $j->getJobID(
)
);
break;
}
}
}
// job sets
if (!strlen($url)) {
$jSets = JobSet::getList(true);
if (is_array($jSets) && count($jSets)) {
foreach ($jSets as $set) {
if ($set->isScheduledForNow()) {
$url = View::url(
'/ccm/system/jobs?auth=' . $auth . '&jsID=' . $set->getJobSetID(
)
);
break;
}
}
}
}
if (strlen($url)) {
try {
$this->make('http/client')->setUri($url)->send();
} catch (Exception $x) {
}
}
}
}
} | [
"protected",
"function",
"handleScheduledJobs",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"[",
"'config'",
"]",
";",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.jobs.enable_scheduling'",
")",
")",
"{",
"$",
"c",
"=",
"Page",
"::",
"getCurrentPage",
"(",
")",
";",
"if",
"(",
"$",
"c",
"instanceof",
"Page",
"&&",
"!",
"$",
"c",
"->",
"isAdminArea",
"(",
")",
")",
"{",
"// check for non dashboard page",
"$",
"jobs",
"=",
"Job",
"::",
"getList",
"(",
"true",
")",
";",
"$",
"auth",
"=",
"Job",
"::",
"generateAuth",
"(",
")",
";",
"$",
"url",
"=",
"''",
";",
"// jobs",
"if",
"(",
"count",
"(",
"$",
"jobs",
")",
")",
"{",
"foreach",
"(",
"$",
"jobs",
"as",
"$",
"j",
")",
"{",
"if",
"(",
"$",
"j",
"->",
"isScheduledForNow",
"(",
")",
")",
"{",
"$",
"url",
"=",
"View",
"::",
"url",
"(",
"'/ccm/system/jobs/run_single?auth='",
".",
"$",
"auth",
".",
"'&jID='",
".",
"$",
"j",
"->",
"getJobID",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"// job sets",
"if",
"(",
"!",
"strlen",
"(",
"$",
"url",
")",
")",
"{",
"$",
"jSets",
"=",
"JobSet",
"::",
"getList",
"(",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"jSets",
")",
"&&",
"count",
"(",
"$",
"jSets",
")",
")",
"{",
"foreach",
"(",
"$",
"jSets",
"as",
"$",
"set",
")",
"{",
"if",
"(",
"$",
"set",
"->",
"isScheduledForNow",
"(",
")",
")",
"{",
"$",
"url",
"=",
"View",
"::",
"url",
"(",
"'/ccm/system/jobs?auth='",
".",
"$",
"auth",
".",
"'&jsID='",
".",
"$",
"set",
"->",
"getJobSetID",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"strlen",
"(",
"$",
"url",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"make",
"(",
"'http/client'",
")",
"->",
"setUri",
"(",
"$",
"url",
")",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"}",
"}",
"}",
"}",
"}"
] | If we have job scheduling running through the site, we check to see if it's time to go for it. | [
"If",
"we",
"have",
"job",
"scheduling",
"running",
"through",
"the",
"site",
"we",
"check",
"to",
"see",
"if",
"it",
"s",
"time",
"to",
"go",
"for",
"it",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L95-L143 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.isInstalled | public function isInstalled()
{
if ($this->installed === null) {
if (!$this->isShared('config')) {
throw new Exception('Attempting to check install status before application initialization.');
}
$this->installed = $this->make('config')->get('concrete.installed');
}
return $this->installed;
} | php | public function isInstalled()
{
if ($this->installed === null) {
if (!$this->isShared('config')) {
throw new Exception('Attempting to check install status before application initialization.');
}
$this->installed = $this->make('config')->get('concrete.installed');
}
return $this->installed;
} | [
"public",
"function",
"isInstalled",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"installed",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isShared",
"(",
"'config'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Attempting to check install status before application initialization.'",
")",
";",
"}",
"$",
"this",
"->",
"installed",
"=",
"$",
"this",
"->",
"make",
"(",
"'config'",
")",
"->",
"get",
"(",
"'concrete.installed'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"installed",
";",
"}"
] | Returns true if concrete5 is installed, false if it has not yet been. | [
"Returns",
"true",
"if",
"concrete5",
"is",
"installed",
"false",
"if",
"it",
"has",
"not",
"yet",
"been",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L148-L159 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.checkPageCache | public function checkPageCache(\Concrete\Core\Http\Request $request)
{
$library = PageCache::getLibrary();
if ($library->shouldCheckCache($request)) {
$record = $library->getRecord($request);
if ($record instanceof PageCacheRecord) {
if ($record->validate($request)) {
return $library->deliver($record);
}
}
}
return false;
} | php | public function checkPageCache(\Concrete\Core\Http\Request $request)
{
$library = PageCache::getLibrary();
if ($library->shouldCheckCache($request)) {
$record = $library->getRecord($request);
if ($record instanceof PageCacheRecord) {
if ($record->validate($request)) {
return $library->deliver($record);
}
}
}
return false;
} | [
"public",
"function",
"checkPageCache",
"(",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Http",
"\\",
"Request",
"$",
"request",
")",
"{",
"$",
"library",
"=",
"PageCache",
"::",
"getLibrary",
"(",
")",
";",
"if",
"(",
"$",
"library",
"->",
"shouldCheckCache",
"(",
"$",
"request",
")",
")",
"{",
"$",
"record",
"=",
"$",
"library",
"->",
"getRecord",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"record",
"instanceof",
"PageCacheRecord",
")",
"{",
"if",
"(",
"$",
"record",
"->",
"validate",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"library",
"->",
"deliver",
"(",
"$",
"record",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks to see whether we should deliver a concrete5 response from the page cache. | [
"Checks",
"to",
"see",
"whether",
"we",
"should",
"deliver",
"a",
"concrete5",
"response",
"from",
"the",
"page",
"cache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L164-L177 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.handleAutomaticUpdates | public function handleAutomaticUpdates()
{
$config = $this['config'];
$installed = $config->get('concrete.version_db_installed');
$core = $config->get('concrete.version_db');
if ($installed < $core) {
$this->make(MutexInterface::class)->execute(Update::MUTEX_KEY, function () {
Update::updateToCurrentVersion();
});
}
} | php | public function handleAutomaticUpdates()
{
$config = $this['config'];
$installed = $config->get('concrete.version_db_installed');
$core = $config->get('concrete.version_db');
if ($installed < $core) {
$this->make(MutexInterface::class)->execute(Update::MUTEX_KEY, function () {
Update::updateToCurrentVersion();
});
}
} | [
"public",
"function",
"handleAutomaticUpdates",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"[",
"'config'",
"]",
";",
"$",
"installed",
"=",
"$",
"config",
"->",
"get",
"(",
"'concrete.version_db_installed'",
")",
";",
"$",
"core",
"=",
"$",
"config",
"->",
"get",
"(",
"'concrete.version_db'",
")",
";",
"if",
"(",
"$",
"installed",
"<",
"$",
"core",
")",
"{",
"$",
"this",
"->",
"make",
"(",
"MutexInterface",
"::",
"class",
")",
"->",
"execute",
"(",
"Update",
"::",
"MUTEX_KEY",
",",
"function",
"(",
")",
"{",
"Update",
"::",
"updateToCurrentVersion",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | Check if the core needs to be updated, and if so, updates it.
@throws \Concrete\Core\System\Mutex\MutexBusyException throws a MutexBusyException exception if there upgrade process is already running
@throws \Concrete\Core\Updater\Migrations\MigrationIncompleteException throws a MigrationIncompleteException exception if there's still some migration pending | [
"Check",
"if",
"the",
"core",
"needs",
"to",
"be",
"updated",
"and",
"if",
"so",
"updates",
"it",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L185-L195 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.setupPackageAutoloaders | public function setupPackageAutoloaders()
{
$pla = \Concrete\Core\Package\PackageList::get();
$pl = $pla->getPackages();
$cl = ClassLoader::getInstance();
/** @var \Package[] $pl */
foreach ($pl as $p) {
\Config::package($p);
if ($p->isPackageInstalled()) {
$pkg = $this->make('Concrete\Core\Package\PackageService')->getClass($p->getPackageHandle());
if (is_object($pkg) && (!$pkg instanceof \Concrete\Core\Package\BrokenPackage)) {
$cl->registerPackage($pkg);
$this->packages[] = $pkg;
}
}
}
} | php | public function setupPackageAutoloaders()
{
$pla = \Concrete\Core\Package\PackageList::get();
$pl = $pla->getPackages();
$cl = ClassLoader::getInstance();
/** @var \Package[] $pl */
foreach ($pl as $p) {
\Config::package($p);
if ($p->isPackageInstalled()) {
$pkg = $this->make('Concrete\Core\Package\PackageService')->getClass($p->getPackageHandle());
if (is_object($pkg) && (!$pkg instanceof \Concrete\Core\Package\BrokenPackage)) {
$cl->registerPackage($pkg);
$this->packages[] = $pkg;
}
}
}
} | [
"public",
"function",
"setupPackageAutoloaders",
"(",
")",
"{",
"$",
"pla",
"=",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Package",
"\\",
"PackageList",
"::",
"get",
"(",
")",
";",
"$",
"pl",
"=",
"$",
"pla",
"->",
"getPackages",
"(",
")",
";",
"$",
"cl",
"=",
"ClassLoader",
"::",
"getInstance",
"(",
")",
";",
"/** @var \\Package[] $pl */",
"foreach",
"(",
"$",
"pl",
"as",
"$",
"p",
")",
"{",
"\\",
"Config",
"::",
"package",
"(",
"$",
"p",
")",
";",
"if",
"(",
"$",
"p",
"->",
"isPackageInstalled",
"(",
")",
")",
"{",
"$",
"pkg",
"=",
"$",
"this",
"->",
"make",
"(",
"'Concrete\\Core\\Package\\PackageService'",
")",
"->",
"getClass",
"(",
"$",
"p",
"->",
"getPackageHandle",
"(",
")",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"pkg",
")",
"&&",
"(",
"!",
"$",
"pkg",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Package",
"\\",
"BrokenPackage",
")",
")",
"{",
"$",
"cl",
"->",
"registerPackage",
"(",
"$",
"pkg",
")",
";",
"$",
"this",
"->",
"packages",
"[",
"]",
"=",
"$",
"pkg",
";",
"}",
"}",
"}",
"}"
] | Register package autoloaders. Has to come BEFORE session calls. | [
"Register",
"package",
"autoloaders",
".",
"Has",
"to",
"come",
"BEFORE",
"session",
"calls",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L200-L216 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.setupPackages | public function setupPackages()
{
$config = $this['config'];
$loc = Localization::getInstance();
$entityManager = $this['Doctrine\ORM\EntityManager'];
$configUpdater = new EntityManagerConfigUpdater($entityManager);
foreach ($this->packages as $pkg) {
if ($config->get('concrete.updates.enable_auto_update_packages')) {
$dbPkg = \Package::getByHandle($pkg->getPackageHandle());
$pkgInstalledVersion = $dbPkg->getPackageVersion();
$pkgFileVersion = $pkg->getPackageVersion();
if (version_compare($pkgFileVersion, $pkgInstalledVersion, '>')) {
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
$dbPkg->upgradeCoreData();
$dbPkg->upgrade();
$loc->popActiveContext();
}
}
}
$packagesWithOnAfterStart = [];
$service = $this->make(PackageService::class);
foreach ($this->packages as $pkg) {
if (method_exists($pkg, 'on_start')) {
$pkg->on_start();
}
$service->bootPackageEntityManager($pkg);
if (method_exists($pkg, 'on_after_packages_start')) {
$packagesWithOnAfterStart[] = $pkg;
}
}
foreach ($packagesWithOnAfterStart as $pkg) {
$pkg->on_after_packages_start();
}
} | php | public function setupPackages()
{
$config = $this['config'];
$loc = Localization::getInstance();
$entityManager = $this['Doctrine\ORM\EntityManager'];
$configUpdater = new EntityManagerConfigUpdater($entityManager);
foreach ($this->packages as $pkg) {
if ($config->get('concrete.updates.enable_auto_update_packages')) {
$dbPkg = \Package::getByHandle($pkg->getPackageHandle());
$pkgInstalledVersion = $dbPkg->getPackageVersion();
$pkgFileVersion = $pkg->getPackageVersion();
if (version_compare($pkgFileVersion, $pkgInstalledVersion, '>')) {
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
$dbPkg->upgradeCoreData();
$dbPkg->upgrade();
$loc->popActiveContext();
}
}
}
$packagesWithOnAfterStart = [];
$service = $this->make(PackageService::class);
foreach ($this->packages as $pkg) {
if (method_exists($pkg, 'on_start')) {
$pkg->on_start();
}
$service->bootPackageEntityManager($pkg);
if (method_exists($pkg, 'on_after_packages_start')) {
$packagesWithOnAfterStart[] = $pkg;
}
}
foreach ($packagesWithOnAfterStart as $pkg) {
$pkg->on_after_packages_start();
}
} | [
"public",
"function",
"setupPackages",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"[",
"'config'",
"]",
";",
"$",
"loc",
"=",
"Localization",
"::",
"getInstance",
"(",
")",
";",
"$",
"entityManager",
"=",
"$",
"this",
"[",
"'Doctrine\\ORM\\EntityManager'",
"]",
";",
"$",
"configUpdater",
"=",
"new",
"EntityManagerConfigUpdater",
"(",
"$",
"entityManager",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"packages",
"as",
"$",
"pkg",
")",
"{",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.updates.enable_auto_update_packages'",
")",
")",
"{",
"$",
"dbPkg",
"=",
"\\",
"Package",
"::",
"getByHandle",
"(",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
")",
";",
"$",
"pkgInstalledVersion",
"=",
"$",
"dbPkg",
"->",
"getPackageVersion",
"(",
")",
";",
"$",
"pkgFileVersion",
"=",
"$",
"pkg",
"->",
"getPackageVersion",
"(",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"pkgFileVersion",
",",
"$",
"pkgInstalledVersion",
",",
"'>'",
")",
")",
"{",
"$",
"loc",
"->",
"pushActiveContext",
"(",
"Localization",
"::",
"CONTEXT_SYSTEM",
")",
";",
"$",
"dbPkg",
"->",
"upgradeCoreData",
"(",
")",
";",
"$",
"dbPkg",
"->",
"upgrade",
"(",
")",
";",
"$",
"loc",
"->",
"popActiveContext",
"(",
")",
";",
"}",
"}",
"}",
"$",
"packagesWithOnAfterStart",
"=",
"[",
"]",
";",
"$",
"service",
"=",
"$",
"this",
"->",
"make",
"(",
"PackageService",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"packages",
"as",
"$",
"pkg",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"pkg",
",",
"'on_start'",
")",
")",
"{",
"$",
"pkg",
"->",
"on_start",
"(",
")",
";",
"}",
"$",
"service",
"->",
"bootPackageEntityManager",
"(",
"$",
"pkg",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"pkg",
",",
"'on_after_packages_start'",
")",
")",
"{",
"$",
"packagesWithOnAfterStart",
"[",
"]",
"=",
"$",
"pkg",
";",
"}",
"}",
"foreach",
"(",
"$",
"packagesWithOnAfterStart",
"as",
"$",
"pkg",
")",
"{",
"$",
"pkg",
"->",
"on_after_packages_start",
"(",
")",
";",
"}",
"}"
] | Run startup and localization events on any installed packages. | [
"Run",
"startup",
"and",
"localization",
"events",
"on",
"any",
"installed",
"packages",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L221-L256 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.setupFilesystem | public function setupFilesystem()
{
$config = $this['config'];
if (!is_dir($config->get('concrete.cache.directory'))) {
@mkdir($config->get('concrete.cache.directory'), $config->get('concrete.filesystem.permissions.directory'));
@touch($config->get('concrete.cache.directory') . '/index.html', $config->get('concrete.filesystem.permissions.file'));
}
} | php | public function setupFilesystem()
{
$config = $this['config'];
if (!is_dir($config->get('concrete.cache.directory'))) {
@mkdir($config->get('concrete.cache.directory'), $config->get('concrete.filesystem.permissions.directory'));
@touch($config->get('concrete.cache.directory') . '/index.html', $config->get('concrete.filesystem.permissions.file'));
}
} | [
"public",
"function",
"setupFilesystem",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"[",
"'config'",
"]",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.cache.directory'",
")",
")",
")",
"{",
"@",
"mkdir",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.cache.directory'",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'concrete.filesystem.permissions.directory'",
")",
")",
";",
"@",
"touch",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.cache.directory'",
")",
".",
"'/index.html'",
",",
"$",
"config",
"->",
"get",
"(",
"'concrete.filesystem.permissions.file'",
")",
")",
";",
"}",
"}"
] | Ensure we have a cache directory. | [
"Ensure",
"we",
"have",
"a",
"cache",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L261-L269 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.handleURLSlashes | public function handleURLSlashes(SymfonyRequest $request, Site $site)
{
$path = $request->getPathInfo();
// If this isn't the homepage
if ($path && $path != '/') {
$config = $this->make('config');
$trailing_slashes = $config->get('concrete.seo.trailing_slash');
// If the trailing slash doesn't match the config, return a redirect response
if (($trailing_slashes && substr($path, -1) != '/') ||
(!$trailing_slashes && substr($path, -1) == '/')) {
$parsed_url = Url::createFromUrl($request->getUri(),
$trailing_slashes ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED);
$response = new RedirectResponse($parsed_url, 301);
$response->setRequest($request);
return $response;
}
}
} | php | public function handleURLSlashes(SymfonyRequest $request, Site $site)
{
$path = $request->getPathInfo();
// If this isn't the homepage
if ($path && $path != '/') {
$config = $this->make('config');
$trailing_slashes = $config->get('concrete.seo.trailing_slash');
// If the trailing slash doesn't match the config, return a redirect response
if (($trailing_slashes && substr($path, -1) != '/') ||
(!$trailing_slashes && substr($path, -1) == '/')) {
$parsed_url = Url::createFromUrl($request->getUri(),
$trailing_slashes ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED);
$response = new RedirectResponse($parsed_url, 301);
$response->setRequest($request);
return $response;
}
}
} | [
"public",
"function",
"handleURLSlashes",
"(",
"SymfonyRequest",
"$",
"request",
",",
"Site",
"$",
"site",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
";",
"// If this isn't the homepage",
"if",
"(",
"$",
"path",
"&&",
"$",
"path",
"!=",
"'/'",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"trailing_slashes",
"=",
"$",
"config",
"->",
"get",
"(",
"'concrete.seo.trailing_slash'",
")",
";",
"// If the trailing slash doesn't match the config, return a redirect response",
"if",
"(",
"(",
"$",
"trailing_slashes",
"&&",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"||",
"(",
"!",
"$",
"trailing_slashes",
"&&",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"==",
"'/'",
")",
")",
"{",
"$",
"parsed_url",
"=",
"Url",
"::",
"createFromUrl",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"$",
"trailing_slashes",
"?",
"Url",
"::",
"TRAILING_SLASHES_ENABLED",
":",
"Url",
"::",
"TRAILING_SLASHES_DISABLED",
")",
";",
"$",
"response",
"=",
"new",
"RedirectResponse",
"(",
"$",
"parsed_url",
",",
"301",
")",
";",
"$",
"response",
"->",
"setRequest",
"(",
"$",
"request",
")",
";",
"return",
"$",
"response",
";",
"}",
"}",
"}"
] | Using the configuration value, determines whether we need to redirect to a URL with
a trailing slash or not.
@return \Concrete\Core\Routing\RedirectResponse | [
"Using",
"the",
"configuration",
"value",
"determines",
"whether",
"we",
"need",
"to",
"redirect",
"to",
"a",
"URL",
"with",
"a",
"trailing",
"slash",
"or",
"not",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L285-L304 | train |
concrete5/concrete5 | concrete/src/Application/Application.php | Application.handleCanonicalURLRedirection | public function handleCanonicalURLRedirection(SymfonyRequest $r, Site $site)
{
$globalConfig = $this['config'];
$siteConfig = $site->getConfigRepository();
if ($globalConfig->get('concrete.seo.redirect_to_canonical_url') && $siteConfig->get('seo.canonical_url')) {
$requestUri = $r->getUri();
$path = parse_url($requestUri, PHP_URL_PATH);
$trailingSlash = substr($path, -1) === '/';
$url = UrlImmutable::createFromUrl($requestUri, $trailingSlash);
$mainCanonical = null;
foreach (['seo.canonical_url', 'seo.canonical_url_alternative'] as $key) {
$canonicalUrlString = $siteConfig->get($key);
if (!$canonicalUrlString) {
continue;
}
$canonicalUrl = UrlImmutable::createFromUrl(
$canonicalUrlString,
(bool) $globalConfig->get('concrete.seo.trailing_slash')
);
// Set the parts of the current URL that are specified in the canonical URL, including host,
// scheme, port. Set scheme first so that our port can use the magic "set if necessary" method.
$canonical = $url
->setScheme($canonicalUrl->getScheme()->get())
->setHost($canonicalUrl->getHost()->get())
->setPort($canonicalUrl->getPort()->get())
;
// Now we have our current url, swapped out with the important parts of the canonical URL.
// If it matches, we're good.
if ($canonical == $url) {
return null;
}
if ($mainCanonical === null) {
$mainCanonical = $canonical;
}
}
$response = new RedirectResponse($mainCanonical, '301');
return $response;
}
} | php | public function handleCanonicalURLRedirection(SymfonyRequest $r, Site $site)
{
$globalConfig = $this['config'];
$siteConfig = $site->getConfigRepository();
if ($globalConfig->get('concrete.seo.redirect_to_canonical_url') && $siteConfig->get('seo.canonical_url')) {
$requestUri = $r->getUri();
$path = parse_url($requestUri, PHP_URL_PATH);
$trailingSlash = substr($path, -1) === '/';
$url = UrlImmutable::createFromUrl($requestUri, $trailingSlash);
$mainCanonical = null;
foreach (['seo.canonical_url', 'seo.canonical_url_alternative'] as $key) {
$canonicalUrlString = $siteConfig->get($key);
if (!$canonicalUrlString) {
continue;
}
$canonicalUrl = UrlImmutable::createFromUrl(
$canonicalUrlString,
(bool) $globalConfig->get('concrete.seo.trailing_slash')
);
// Set the parts of the current URL that are specified in the canonical URL, including host,
// scheme, port. Set scheme first so that our port can use the magic "set if necessary" method.
$canonical = $url
->setScheme($canonicalUrl->getScheme()->get())
->setHost($canonicalUrl->getHost()->get())
->setPort($canonicalUrl->getPort()->get())
;
// Now we have our current url, swapped out with the important parts of the canonical URL.
// If it matches, we're good.
if ($canonical == $url) {
return null;
}
if ($mainCanonical === null) {
$mainCanonical = $canonical;
}
}
$response = new RedirectResponse($mainCanonical, '301');
return $response;
}
} | [
"public",
"function",
"handleCanonicalURLRedirection",
"(",
"SymfonyRequest",
"$",
"r",
",",
"Site",
"$",
"site",
")",
"{",
"$",
"globalConfig",
"=",
"$",
"this",
"[",
"'config'",
"]",
";",
"$",
"siteConfig",
"=",
"$",
"site",
"->",
"getConfigRepository",
"(",
")",
";",
"if",
"(",
"$",
"globalConfig",
"->",
"get",
"(",
"'concrete.seo.redirect_to_canonical_url'",
")",
"&&",
"$",
"siteConfig",
"->",
"get",
"(",
"'seo.canonical_url'",
")",
")",
"{",
"$",
"requestUri",
"=",
"$",
"r",
"->",
"getUri",
"(",
")",
";",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"requestUri",
",",
"PHP_URL_PATH",
")",
";",
"$",
"trailingSlash",
"=",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"===",
"'/'",
";",
"$",
"url",
"=",
"UrlImmutable",
"::",
"createFromUrl",
"(",
"$",
"requestUri",
",",
"$",
"trailingSlash",
")",
";",
"$",
"mainCanonical",
"=",
"null",
";",
"foreach",
"(",
"[",
"'seo.canonical_url'",
",",
"'seo.canonical_url_alternative'",
"]",
"as",
"$",
"key",
")",
"{",
"$",
"canonicalUrlString",
"=",
"$",
"siteConfig",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"canonicalUrlString",
")",
"{",
"continue",
";",
"}",
"$",
"canonicalUrl",
"=",
"UrlImmutable",
"::",
"createFromUrl",
"(",
"$",
"canonicalUrlString",
",",
"(",
"bool",
")",
"$",
"globalConfig",
"->",
"get",
"(",
"'concrete.seo.trailing_slash'",
")",
")",
";",
"// Set the parts of the current URL that are specified in the canonical URL, including host,",
"// scheme, port. Set scheme first so that our port can use the magic \"set if necessary\" method.",
"$",
"canonical",
"=",
"$",
"url",
"->",
"setScheme",
"(",
"$",
"canonicalUrl",
"->",
"getScheme",
"(",
")",
"->",
"get",
"(",
")",
")",
"->",
"setHost",
"(",
"$",
"canonicalUrl",
"->",
"getHost",
"(",
")",
"->",
"get",
"(",
")",
")",
"->",
"setPort",
"(",
"$",
"canonicalUrl",
"->",
"getPort",
"(",
")",
"->",
"get",
"(",
")",
")",
";",
"// Now we have our current url, swapped out with the important parts of the canonical URL.",
"// If it matches, we're good.",
"if",
"(",
"$",
"canonical",
"==",
"$",
"url",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"mainCanonical",
"===",
"null",
")",
"{",
"$",
"mainCanonical",
"=",
"$",
"canonical",
";",
"}",
"}",
"$",
"response",
"=",
"new",
"RedirectResponse",
"(",
"$",
"mainCanonical",
",",
"'301'",
")",
";",
"return",
"$",
"response",
";",
"}",
"}"
] | If we have redirect to canonical host enabled, we need to honor it here.
@return \Concrete\Core\Routing\RedirectResponse|null | [
"If",
"we",
"have",
"redirect",
"to",
"canonical",
"host",
"enabled",
"we",
"need",
"to",
"honor",
"it",
"here",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Application.php#L311-L355 | train |
concrete5/concrete5 | concrete/src/Page/Stack/Stack.php | Stack.getLocalizedStack | public function getLocalizedStack(Section $section, $cvID = 'RECENT')
{
$result = null;
$mySectionID = $this->getMultilingualSectionID();
if ($mySectionID !== 0 && $section->getCollectionID() == $mySectionID) {
$result = $this;
} else {
$neutralID = ($mySectionID === 0) ? $this->getCollectionID() : $this->getNeutralStackID();
$db = Database::connection();
$localizedID = $db->fetchColumn(
'
select
Stacks.cID
from
Stacks
inner join Pages on Stacks.cID = Pages.cID
where
Pages.cParentID = ? and Stacks.stMultilingualSection = ?
limit 1
',
[$neutralID, $section->getCollectionID()]
);
if ($localizedID) {
$localized = static::getByID($localizedID, $cvID);
if ($localized) {
$result = $localized;
}
}
}
return $result;
} | php | public function getLocalizedStack(Section $section, $cvID = 'RECENT')
{
$result = null;
$mySectionID = $this->getMultilingualSectionID();
if ($mySectionID !== 0 && $section->getCollectionID() == $mySectionID) {
$result = $this;
} else {
$neutralID = ($mySectionID === 0) ? $this->getCollectionID() : $this->getNeutralStackID();
$db = Database::connection();
$localizedID = $db->fetchColumn(
'
select
Stacks.cID
from
Stacks
inner join Pages on Stacks.cID = Pages.cID
where
Pages.cParentID = ? and Stacks.stMultilingualSection = ?
limit 1
',
[$neutralID, $section->getCollectionID()]
);
if ($localizedID) {
$localized = static::getByID($localizedID, $cvID);
if ($localized) {
$result = $localized;
}
}
}
return $result;
} | [
"public",
"function",
"getLocalizedStack",
"(",
"Section",
"$",
"section",
",",
"$",
"cvID",
"=",
"'RECENT'",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"mySectionID",
"=",
"$",
"this",
"->",
"getMultilingualSectionID",
"(",
")",
";",
"if",
"(",
"$",
"mySectionID",
"!==",
"0",
"&&",
"$",
"section",
"->",
"getCollectionID",
"(",
")",
"==",
"$",
"mySectionID",
")",
"{",
"$",
"result",
"=",
"$",
"this",
";",
"}",
"else",
"{",
"$",
"neutralID",
"=",
"(",
"$",
"mySectionID",
"===",
"0",
")",
"?",
"$",
"this",
"->",
"getCollectionID",
"(",
")",
":",
"$",
"this",
"->",
"getNeutralStackID",
"(",
")",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"localizedID",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'\n select\n \t Stacks.cID\n from\n \t Stacks\n \t inner join Pages on Stacks.cID = Pages.cID\n where\n \t Pages.cParentID = ? and Stacks.stMultilingualSection = ?\n limit 1\n '",
",",
"[",
"$",
"neutralID",
",",
"$",
"section",
"->",
"getCollectionID",
"(",
")",
"]",
")",
";",
"if",
"(",
"$",
"localizedID",
")",
"{",
"$",
"localized",
"=",
"static",
"::",
"getByID",
"(",
"$",
"localizedID",
",",
"$",
"cvID",
")",
";",
"if",
"(",
"$",
"localized",
")",
"{",
"$",
"result",
"=",
"$",
"localized",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the localized version of this stack.
@param \Concrete\Core\Multilingual\Page\Section\Section $section
@param string|int $cvID
@return self|null | [
"Returns",
"the",
"localized",
"version",
"of",
"this",
"stack",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Stack/Stack.php#L442-L473 | train |
concrete5/concrete5 | concrete/src/Console/Command.php | Command.writeError | protected function writeError(OutputInterface $output, $error)
{
$result = [trim($error->getMessage())];
// If the output is verbose, add file and location
if ($output->isVerbose()) {
$file = $error->getFile();
if ($file) {
$result[] = "File: {$file}" . ($error->getLine() ? ':' . $error->getLine() : '');
}
}
// If the output is very verbose, add stacktrace
if ($output->isVeryVerbose()) {
$trace = $error->getTraceAsString();
$result[] = 'Trace:';
$result[] = $trace;
}
$this->output->error($result);
} | php | protected function writeError(OutputInterface $output, $error)
{
$result = [trim($error->getMessage())];
// If the output is verbose, add file and location
if ($output->isVerbose()) {
$file = $error->getFile();
if ($file) {
$result[] = "File: {$file}" . ($error->getLine() ? ':' . $error->getLine() : '');
}
}
// If the output is very verbose, add stacktrace
if ($output->isVeryVerbose()) {
$trace = $error->getTraceAsString();
$result[] = 'Trace:';
$result[] = $trace;
}
$this->output->error($result);
} | [
"protected",
"function",
"writeError",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"error",
")",
"{",
"$",
"result",
"=",
"[",
"trim",
"(",
"$",
"error",
"->",
"getMessage",
"(",
")",
")",
"]",
";",
"// If the output is verbose, add file and location",
"if",
"(",
"$",
"output",
"->",
"isVerbose",
"(",
")",
")",
"{",
"$",
"file",
"=",
"$",
"error",
"->",
"getFile",
"(",
")",
";",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"\"File: {$file}\"",
".",
"(",
"$",
"error",
"->",
"getLine",
"(",
")",
"?",
"':'",
".",
"$",
"error",
"->",
"getLine",
"(",
")",
":",
"''",
")",
";",
"}",
"}",
"// If the output is very verbose, add stacktrace",
"if",
"(",
"$",
"output",
"->",
"isVeryVerbose",
"(",
")",
")",
"{",
"$",
"trace",
"=",
"$",
"error",
"->",
"getTraceAsString",
"(",
")",
";",
"$",
"result",
"[",
"]",
"=",
"'Trace:'",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"trace",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"error",
"(",
"$",
"result",
")",
";",
"}"
] | Write an exception.
@param OutputInterface $output
@param Exception|Throwable $error
@deprecated Use $this->output to manage your output
@see OutputStyle::error() | [
"Write",
"an",
"exception",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command.php#L209-L229 | train |
concrete5/concrete5 | concrete/src/Console/Command.php | Command.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
if (!method_exists($this, 'handle')) {
throw new LogicException('You must define the public handle() method in the command implementation.');
}
return $this->getApplication()->getConcrete5()->call([$this, 'handle']);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
if (!method_exists($this, 'handle')) {
throw new LogicException('You must define the public handle() method in the command implementation.');
}
return $this->getApplication()->getConcrete5()->call([$this, 'handle']);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"'handle'",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'You must define the public handle() method in the command implementation.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getConcrete5",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'handle'",
"]",
")",
";",
"}"
] | This method is overridden to pipe execution to the handle method hiding input and output
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return mixed | [
"This",
"method",
"is",
"overridden",
"to",
"pipe",
"execution",
"to",
"the",
"handle",
"method",
"hiding",
"input",
"and",
"output"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command.php#L322-L329 | train |
concrete5/concrete5 | concrete/src/Console/Command.php | Command.table | public function table(array $headers, array $rows, $tableStyle = 'default', array $columnStyles = [])
{
$this->output->table($headers, $rows, $tableStyle, $columnStyles);
} | php | public function table(array $headers, array $rows, $tableStyle = 'default', array $columnStyles = [])
{
$this->output->table($headers, $rows, $tableStyle, $columnStyles);
} | [
"public",
"function",
"table",
"(",
"array",
"$",
"headers",
",",
"array",
"$",
"rows",
",",
"$",
"tableStyle",
"=",
"'default'",
",",
"array",
"$",
"columnStyles",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"table",
"(",
"$",
"headers",
",",
"$",
"rows",
",",
"$",
"tableStyle",
",",
"$",
"columnStyles",
")",
";",
"}"
] | Format input to textual table.
@param array $headers
@param \Illuminate\Contracts\Support\Arrayable|array $rows
@param string $tableStyle
@param array $columnStyles
@return void | [
"Format",
"input",
"to",
"textual",
"table",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command.php#L506-L509 | train |
concrete5/concrete5 | concrete/authentication/community/controller.php | Controller.getConcrete5ProfileURL | public function getConcrete5ProfileURL($user)
{
$result = null;
$binding = $this->getBindingForUser($user);
if ($binding !== null) {
$concrete5UserID = (int) $binding;
if ($concrete5UserID !== 0) {
$result = "https://www.concrete5.org/profile/-/view/$concrete5UserID/";
}
}
return $result;
} | php | public function getConcrete5ProfileURL($user)
{
$result = null;
$binding = $this->getBindingForUser($user);
if ($binding !== null) {
$concrete5UserID = (int) $binding;
if ($concrete5UserID !== 0) {
$result = "https://www.concrete5.org/profile/-/view/$concrete5UserID/";
}
}
return $result;
} | [
"public",
"function",
"getConcrete5ProfileURL",
"(",
"$",
"user",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"binding",
"=",
"$",
"this",
"->",
"getBindingForUser",
"(",
"$",
"user",
")",
";",
"if",
"(",
"$",
"binding",
"!==",
"null",
")",
"{",
"$",
"concrete5UserID",
"=",
"(",
"int",
")",
"$",
"binding",
";",
"if",
"(",
"$",
"concrete5UserID",
"!==",
"0",
")",
"{",
"$",
"result",
"=",
"\"https://www.concrete5.org/profile/-/view/$concrete5UserID/\"",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the URL of the concrete5 account associated to a user.
@param \Concrete\Core\User\User|\Concrete\Core\User\UserInfo|\Concrete\Core\Entity\User\User|int $user
@return string|null Returns null if the user is not bound to a concrete5 account. | [
"Get",
"the",
"URL",
"of",
"the",
"concrete5",
"account",
"associated",
"to",
"a",
"user",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/authentication/community/controller.php#L98-L110 | train |
concrete5/concrete5 | concrete/src/Console/Command/InstallCommand.php | InstallCommand.getQuestion | private function getQuestion($row, InputInterface $input)
{
$definition = $this->getDefinition();
// Define default values
$row = (array) $row;
$default = null;
$mutator = null;
// Grab the key which is always first
$key = array_shift($row);
// If there's more stuff, this is probably the default value
if ($row) {
$default = array_shift($row);
}
// If the default value is callable, it's probably actually the mutator
if (is_callable($default)) {
$mutator = $default;
$default = array_shift($row);
if (is_callable($default)) {
$default = $default($input);
}
} elseif ($row) { // Otherwise if there's still items, the mutator is last.
$mutator = array_shift($row);
}
// If a value is provided already, use that as the default
if ($provided = $input->getOption($key)) {
$default = $provided;
}
// If we don't have a default, use the default from the InputOption
$option = $definition->getOption($key);
if (!$default) {
$default = $option->getDefault();
}
// Create the new question deriving the question from the info we have
$question = new Question($this->getQuestionString($option, $default), $default);
// If we have a callable mutator, lets let it modify or replace the question
if (is_callable($mutator)) {
$question = $mutator($question, $input, $option);
}
return $question;
} | php | private function getQuestion($row, InputInterface $input)
{
$definition = $this->getDefinition();
// Define default values
$row = (array) $row;
$default = null;
$mutator = null;
// Grab the key which is always first
$key = array_shift($row);
// If there's more stuff, this is probably the default value
if ($row) {
$default = array_shift($row);
}
// If the default value is callable, it's probably actually the mutator
if (is_callable($default)) {
$mutator = $default;
$default = array_shift($row);
if (is_callable($default)) {
$default = $default($input);
}
} elseif ($row) { // Otherwise if there's still items, the mutator is last.
$mutator = array_shift($row);
}
// If a value is provided already, use that as the default
if ($provided = $input->getOption($key)) {
$default = $provided;
}
// If we don't have a default, use the default from the InputOption
$option = $definition->getOption($key);
if (!$default) {
$default = $option->getDefault();
}
// Create the new question deriving the question from the info we have
$question = new Question($this->getQuestionString($option, $default), $default);
// If we have a callable mutator, lets let it modify or replace the question
if (is_callable($mutator)) {
$question = $mutator($question, $input, $option);
}
return $question;
} | [
"private",
"function",
"getQuestion",
"(",
"$",
"row",
",",
"InputInterface",
"$",
"input",
")",
"{",
"$",
"definition",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
")",
";",
"// Define default values",
"$",
"row",
"=",
"(",
"array",
")",
"$",
"row",
";",
"$",
"default",
"=",
"null",
";",
"$",
"mutator",
"=",
"null",
";",
"// Grab the key which is always first",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"row",
")",
";",
"// If there's more stuff, this is probably the default value",
"if",
"(",
"$",
"row",
")",
"{",
"$",
"default",
"=",
"array_shift",
"(",
"$",
"row",
")",
";",
"}",
"// If the default value is callable, it's probably actually the mutator",
"if",
"(",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"$",
"mutator",
"=",
"$",
"default",
";",
"$",
"default",
"=",
"array_shift",
"(",
"$",
"row",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"$",
"default",
"(",
"$",
"input",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"row",
")",
"{",
"// Otherwise if there's still items, the mutator is last.",
"$",
"mutator",
"=",
"array_shift",
"(",
"$",
"row",
")",
";",
"}",
"// If a value is provided already, use that as the default",
"if",
"(",
"$",
"provided",
"=",
"$",
"input",
"->",
"getOption",
"(",
"$",
"key",
")",
")",
"{",
"$",
"default",
"=",
"$",
"provided",
";",
"}",
"// If we don't have a default, use the default from the InputOption",
"$",
"option",
"=",
"$",
"definition",
"->",
"getOption",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"default",
")",
"{",
"$",
"default",
"=",
"$",
"option",
"->",
"getDefault",
"(",
")",
";",
"}",
"// Create the new question deriving the question from the info we have",
"$",
"question",
"=",
"new",
"Question",
"(",
"$",
"this",
"->",
"getQuestionString",
"(",
"$",
"option",
",",
"$",
"default",
")",
",",
"$",
"default",
")",
";",
"// If we have a callable mutator, lets let it modify or replace the question",
"if",
"(",
"is_callable",
"(",
"$",
"mutator",
")",
")",
"{",
"$",
"question",
"=",
"$",
"mutator",
"(",
"$",
"question",
",",
"$",
"input",
",",
"$",
"option",
")",
";",
"}",
"return",
"$",
"question",
";",
"}"
] | Do some procedural work to a row in the wizard step list to turn it into a proper question.
@param $row
@param \Symfony\Component\Console\Input\InputInterface $input
@return \Symfony\Component\Console\Question\Question | [
"Do",
"some",
"procedural",
"work",
"to",
"a",
"row",
"in",
"the",
"wizard",
"step",
"list",
"to",
"turn",
"it",
"into",
"a",
"proper",
"question",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command/InstallCommand.php#L319-L367 | train |
concrete5/concrete5 | concrete/src/Console/Command/InstallCommand.php | InstallCommand.getWizard | private function getWizard(InputInterface $input, OutputInterface $output, $firstKey = null)
{
$questions = $this->wizardSteps();
$tryAgain = false;
$result = null;
// Loop over the questions, parse them, then yield them out
foreach ($questions as $question) {
if (!$firstKey && $question instanceof \Closure) {
$result = $question($input, $output, $this);
if ($result === false || is_string($result)) {
$tryAgain = true;
break;
}
continue;
}
$question = (array) $question;
if ($firstKey && $question[0] !== $firstKey) {
continue;
}
// If we still have a firstKey set, that means we've hit the first key. Unset so that we don't test again
if ($firstKey) {
$firstKey = null;
}
if (in_array($question[0], ['demo-password', 'demo-email'], true) && '' === (string) $input->getOption('demo-username')) {
continue;
}
yield $question[0] => $this->getQuestion($question, $input);
}
if ($tryAgain) {
// Try again, passing the result as the first next item. This allows us to use this like a goto
foreach ($this->getWizard($input, $output, $result) as $key => $value) {
yield $key => $value;
}
}
} | php | private function getWizard(InputInterface $input, OutputInterface $output, $firstKey = null)
{
$questions = $this->wizardSteps();
$tryAgain = false;
$result = null;
// Loop over the questions, parse them, then yield them out
foreach ($questions as $question) {
if (!$firstKey && $question instanceof \Closure) {
$result = $question($input, $output, $this);
if ($result === false || is_string($result)) {
$tryAgain = true;
break;
}
continue;
}
$question = (array) $question;
if ($firstKey && $question[0] !== $firstKey) {
continue;
}
// If we still have a firstKey set, that means we've hit the first key. Unset so that we don't test again
if ($firstKey) {
$firstKey = null;
}
if (in_array($question[0], ['demo-password', 'demo-email'], true) && '' === (string) $input->getOption('demo-username')) {
continue;
}
yield $question[0] => $this->getQuestion($question, $input);
}
if ($tryAgain) {
// Try again, passing the result as the first next item. This allows us to use this like a goto
foreach ($this->getWizard($input, $output, $result) as $key => $value) {
yield $key => $value;
}
}
} | [
"private",
"function",
"getWizard",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"firstKey",
"=",
"null",
")",
"{",
"$",
"questions",
"=",
"$",
"this",
"->",
"wizardSteps",
"(",
")",
";",
"$",
"tryAgain",
"=",
"false",
";",
"$",
"result",
"=",
"null",
";",
"// Loop over the questions, parse them, then yield them out",
"foreach",
"(",
"$",
"questions",
"as",
"$",
"question",
")",
"{",
"if",
"(",
"!",
"$",
"firstKey",
"&&",
"$",
"question",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"result",
"=",
"$",
"question",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
"||",
"is_string",
"(",
"$",
"result",
")",
")",
"{",
"$",
"tryAgain",
"=",
"true",
";",
"break",
";",
"}",
"continue",
";",
"}",
"$",
"question",
"=",
"(",
"array",
")",
"$",
"question",
";",
"if",
"(",
"$",
"firstKey",
"&&",
"$",
"question",
"[",
"0",
"]",
"!==",
"$",
"firstKey",
")",
"{",
"continue",
";",
"}",
"// If we still have a firstKey set, that means we've hit the first key. Unset so that we don't test again",
"if",
"(",
"$",
"firstKey",
")",
"{",
"$",
"firstKey",
"=",
"null",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"question",
"[",
"0",
"]",
",",
"[",
"'demo-password'",
",",
"'demo-email'",
"]",
",",
"true",
")",
"&&",
"''",
"===",
"(",
"string",
")",
"$",
"input",
"->",
"getOption",
"(",
"'demo-username'",
")",
")",
"{",
"continue",
";",
"}",
"yield",
"$",
"question",
"[",
"0",
"]",
"=>",
"$",
"this",
"->",
"getQuestion",
"(",
"$",
"question",
",",
"$",
"input",
")",
";",
"}",
"if",
"(",
"$",
"tryAgain",
")",
"{",
"// Try again, passing the result as the first next item. This allows us to use this like a goto",
"foreach",
"(",
"$",
"this",
"->",
"getWizard",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"result",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"yield",
"$",
"key",
"=>",
"$",
"value",
";",
"}",
"}",
"}"
] | A wizard generator.
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@param null $firstKey
@return \Generator|\Symfony\Component\Console\Question\Question[] | [
"A",
"wizard",
"generator",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command/InstallCommand.php#L378-L420 | train |
concrete5/concrete5 | concrete/src/Console/Command/InstallCommand.php | InstallCommand.getQuestionString | private function getQuestionString(InputOption $option, $default)
{
if ('' !== (string) $default) {
if (stripos($option->getName(), 'password') !== false) {
return sprintf('%s? [<options=bold>HIDDEN</>]: ', $option->getDescription(), $default);
}
return sprintf('%s? [<options=bold>%s</>]: ', $option->getDescription(), $default);
}
return sprintf('%s?: ', $option->getDescription());
} | php | private function getQuestionString(InputOption $option, $default)
{
if ('' !== (string) $default) {
if (stripos($option->getName(), 'password') !== false) {
return sprintf('%s? [<options=bold>HIDDEN</>]: ', $option->getDescription(), $default);
}
return sprintf('%s? [<options=bold>%s</>]: ', $option->getDescription(), $default);
}
return sprintf('%s?: ', $option->getDescription());
} | [
"private",
"function",
"getQuestionString",
"(",
"InputOption",
"$",
"option",
",",
"$",
"default",
")",
"{",
"if",
"(",
"''",
"!==",
"(",
"string",
")",
"$",
"default",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"option",
"->",
"getName",
"(",
")",
",",
"'password'",
")",
"!==",
"false",
")",
"{",
"return",
"sprintf",
"(",
"'%s? [<options=bold>HIDDEN</>]: '",
",",
"$",
"option",
"->",
"getDescription",
"(",
")",
",",
"$",
"default",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s? [<options=bold>%s</>]: '",
",",
"$",
"option",
"->",
"getDescription",
"(",
")",
",",
"$",
"default",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s?: '",
",",
"$",
"option",
"->",
"getDescription",
"(",
")",
")",
";",
"}"
] | Take an option and return a question string.
@param \Symfony\Component\Console\Input\InputOption $option
@param $default
@return string | [
"Take",
"an",
"option",
"and",
"return",
"a",
"question",
"string",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command/InstallCommand.php#L430-L441 | train |
concrete5/concrete5 | concrete/src/Api/OAuth/Client/ClientFactory.php | ClientFactory.createClient | public function createClient($name, $redirect, array $scopes, $key, $secret)
{
$client = $this->app->make(Client::class);
$client->setName($name);
$client->setRedirectUri($redirect);
// @TODO support scopes
//$client->setScopes($scopes);
$client->setClientKey($key);
$client->setClientSecret($secret);
// Apply a new UUID to the client
$id = $this->generator->generate($this->entityManager, $client);
$client->setIdentifier($id);
return $client;
} | php | public function createClient($name, $redirect, array $scopes, $key, $secret)
{
$client = $this->app->make(Client::class);
$client->setName($name);
$client->setRedirectUri($redirect);
// @TODO support scopes
//$client->setScopes($scopes);
$client->setClientKey($key);
$client->setClientSecret($secret);
// Apply a new UUID to the client
$id = $this->generator->generate($this->entityManager, $client);
$client->setIdentifier($id);
return $client;
} | [
"public",
"function",
"createClient",
"(",
"$",
"name",
",",
"$",
"redirect",
",",
"array",
"$",
"scopes",
",",
"$",
"key",
",",
"$",
"secret",
")",
"{",
"$",
"client",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Client",
"::",
"class",
")",
";",
"$",
"client",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"client",
"->",
"setRedirectUri",
"(",
"$",
"redirect",
")",
";",
"// @TODO support scopes",
"//$client->setScopes($scopes);",
"$",
"client",
"->",
"setClientKey",
"(",
"$",
"key",
")",
";",
"$",
"client",
"->",
"setClientSecret",
"(",
"$",
"secret",
")",
";",
"// Apply a new UUID to the client",
"$",
"id",
"=",
"$",
"this",
"->",
"generator",
"->",
"generate",
"(",
"$",
"this",
"->",
"entityManager",
",",
"$",
"client",
")",
";",
"$",
"client",
"->",
"setIdentifier",
"(",
"$",
"id",
")",
";",
"return",
"$",
"client",
";",
"}"
] | Create a new OAuth client object and provide it a proper UUID
@param string $name The client name
@param string $redirect The redirect url
@param string[] $scopes The scopes this client is allowed to interact with
@param string $key The client's api key
@param string $secret This secret should be properly hashed with something like `password_hash`
@return \Concrete\Core\Entity\OAuth\Client | [
"Create",
"a",
"new",
"OAuth",
"client",
"object",
"and",
"provide",
"it",
"a",
"proper",
"UUID"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Api/OAuth/Client/ClientFactory.php#L44-L59 | train |
concrete5/concrete5 | concrete/src/Api/OAuth/Client/ClientFactory.php | ClientFactory.generateString | protected function generateString($length)
{
$bytes = ceil($length / 2);
$string = bin2hex(random_bytes($bytes));
return substr($string, 0, $length);
} | php | protected function generateString($length)
{
$bytes = ceil($length / 2);
$string = bin2hex(random_bytes($bytes));
return substr($string, 0, $length);
} | [
"protected",
"function",
"generateString",
"(",
"$",
"length",
")",
"{",
"$",
"bytes",
"=",
"ceil",
"(",
"$",
"length",
"/",
"2",
")",
";",
"$",
"string",
"=",
"bin2hex",
"(",
"random_bytes",
"(",
"$",
"bytes",
")",
")",
";",
"return",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] | Generate a cryptographically secure strig
@param $length
@return bool|string | [
"Generate",
"a",
"cryptographically",
"secure",
"strig"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Api/OAuth/Client/ClientFactory.php#L94-L100 | train |
concrete5/concrete5 | concrete/src/Entity/Page/Feed.php | Feed.getOutput | public function getOutput($request = null)
{
$pl = $this->getPageListObject();
$link = false;
if ($this->cParentID) {
$parent = Page::getByID($this->cParentID);
$link = $parent->getCollectionLink();
} else {
$link = \URL::to('/');
}
$pagination = $pl->getPagination();
$results = $pagination->getCurrentPageResults();
if (count($results)) {
$writer = new \Zend\Feed\Writer\Feed();
$writer->setTitle($this->getTitle());
$writer->setDescription($this->getDescription());
if ($this->getIconFileID()) {
$f = \File::getByID($this->getIconFileID());
if (is_object($f)) {
$data = [
'uri' => $f->getURL(),
'title' => $f->getTitle(),
'link' => (string) $link,
];
$writer->setImage($data);
}
}
$writer->setLink((string) $link);
foreach ($results as $p) {
$entry = $writer->createEntry();
$entry->setTitle($p->getCollectionName());
$entry->setDateCreated(strtotime($p->getCollectionDatePublic()));
$content = $this->getPageFeedContent($p);
if (!$content) {
$content = t('No Content.');
}
$entry->setDescription($content);
$entry->setLink((string) $p->getCollectionLink(true));
$writer->addEntry($entry);
}
$ev = new FeedEvent();
if (isset($parent)) {
$ev->setPageObject($parent);
}
$ev->setFeedObject($this);
$ev->setWriterObject($writer);
$ev->setRequest($request);
$ev = \Events::dispatch('on_page_feed_output', $ev);
$writer = $ev->getWriterObject();
return $writer->export('rss');
}
} | php | public function getOutput($request = null)
{
$pl = $this->getPageListObject();
$link = false;
if ($this->cParentID) {
$parent = Page::getByID($this->cParentID);
$link = $parent->getCollectionLink();
} else {
$link = \URL::to('/');
}
$pagination = $pl->getPagination();
$results = $pagination->getCurrentPageResults();
if (count($results)) {
$writer = new \Zend\Feed\Writer\Feed();
$writer->setTitle($this->getTitle());
$writer->setDescription($this->getDescription());
if ($this->getIconFileID()) {
$f = \File::getByID($this->getIconFileID());
if (is_object($f)) {
$data = [
'uri' => $f->getURL(),
'title' => $f->getTitle(),
'link' => (string) $link,
];
$writer->setImage($data);
}
}
$writer->setLink((string) $link);
foreach ($results as $p) {
$entry = $writer->createEntry();
$entry->setTitle($p->getCollectionName());
$entry->setDateCreated(strtotime($p->getCollectionDatePublic()));
$content = $this->getPageFeedContent($p);
if (!$content) {
$content = t('No Content.');
}
$entry->setDescription($content);
$entry->setLink((string) $p->getCollectionLink(true));
$writer->addEntry($entry);
}
$ev = new FeedEvent();
if (isset($parent)) {
$ev->setPageObject($parent);
}
$ev->setFeedObject($this);
$ev->setWriterObject($writer);
$ev->setRequest($request);
$ev = \Events::dispatch('on_page_feed_output', $ev);
$writer = $ev->getWriterObject();
return $writer->export('rss');
}
} | [
"public",
"function",
"getOutput",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"pl",
"=",
"$",
"this",
"->",
"getPageListObject",
"(",
")",
";",
"$",
"link",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"cParentID",
")",
"{",
"$",
"parent",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"this",
"->",
"cParentID",
")",
";",
"$",
"link",
"=",
"$",
"parent",
"->",
"getCollectionLink",
"(",
")",
";",
"}",
"else",
"{",
"$",
"link",
"=",
"\\",
"URL",
"::",
"to",
"(",
"'/'",
")",
";",
"}",
"$",
"pagination",
"=",
"$",
"pl",
"->",
"getPagination",
"(",
")",
";",
"$",
"results",
"=",
"$",
"pagination",
"->",
"getCurrentPageResults",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
")",
"{",
"$",
"writer",
"=",
"new",
"\\",
"Zend",
"\\",
"Feed",
"\\",
"Writer",
"\\",
"Feed",
"(",
")",
";",
"$",
"writer",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"getTitle",
"(",
")",
")",
";",
"$",
"writer",
"->",
"setDescription",
"(",
"$",
"this",
"->",
"getDescription",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getIconFileID",
"(",
")",
")",
"{",
"$",
"f",
"=",
"\\",
"File",
"::",
"getByID",
"(",
"$",
"this",
"->",
"getIconFileID",
"(",
")",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"f",
")",
")",
"{",
"$",
"data",
"=",
"[",
"'uri'",
"=>",
"$",
"f",
"->",
"getURL",
"(",
")",
",",
"'title'",
"=>",
"$",
"f",
"->",
"getTitle",
"(",
")",
",",
"'link'",
"=>",
"(",
"string",
")",
"$",
"link",
",",
"]",
";",
"$",
"writer",
"->",
"setImage",
"(",
"$",
"data",
")",
";",
"}",
"}",
"$",
"writer",
"->",
"setLink",
"(",
"(",
"string",
")",
"$",
"link",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"p",
")",
"{",
"$",
"entry",
"=",
"$",
"writer",
"->",
"createEntry",
"(",
")",
";",
"$",
"entry",
"->",
"setTitle",
"(",
"$",
"p",
"->",
"getCollectionName",
"(",
")",
")",
";",
"$",
"entry",
"->",
"setDateCreated",
"(",
"strtotime",
"(",
"$",
"p",
"->",
"getCollectionDatePublic",
"(",
")",
")",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"getPageFeedContent",
"(",
"$",
"p",
")",
";",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"t",
"(",
"'No Content.'",
")",
";",
"}",
"$",
"entry",
"->",
"setDescription",
"(",
"$",
"content",
")",
";",
"$",
"entry",
"->",
"setLink",
"(",
"(",
"string",
")",
"$",
"p",
"->",
"getCollectionLink",
"(",
"true",
")",
")",
";",
"$",
"writer",
"->",
"addEntry",
"(",
"$",
"entry",
")",
";",
"}",
"$",
"ev",
"=",
"new",
"FeedEvent",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"ev",
"->",
"setPageObject",
"(",
"$",
"parent",
")",
";",
"}",
"$",
"ev",
"->",
"setFeedObject",
"(",
"$",
"this",
")",
";",
"$",
"ev",
"->",
"setWriterObject",
"(",
"$",
"writer",
")",
";",
"$",
"ev",
"->",
"setRequest",
"(",
"$",
"request",
")",
";",
"$",
"ev",
"=",
"\\",
"Events",
"::",
"dispatch",
"(",
"'on_page_feed_output'",
",",
"$",
"ev",
")",
";",
"$",
"writer",
"=",
"$",
"ev",
"->",
"getWriterObject",
"(",
")",
";",
"return",
"$",
"writer",
"->",
"export",
"(",
"'rss'",
")",
";",
"}",
"}"
] | Get the feed output in RSS form given a Request object.
@param Request|null $request
@return string|null The full RSS output as a string | [
"Get",
"the",
"feed",
"output",
"in",
"RSS",
"form",
"given",
"a",
"Request",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Page/Feed.php#L437-L493 | train |
concrete5/concrete5 | concrete/src/Workflow/Request/DeleteUserRequest.php | DeleteUserRequest.cancel | public function cancel(Progress $wp)
{
$ui = UserInfo::getByID($this->getRequestedUserID());
$wpr = parent::cancel($wp);
$wpr->message = t("User deletion request has been cancelled.");
return $wpr;
} | php | public function cancel(Progress $wp)
{
$ui = UserInfo::getByID($this->getRequestedUserID());
$wpr = parent::cancel($wp);
$wpr->message = t("User deletion request has been cancelled.");
return $wpr;
} | [
"public",
"function",
"cancel",
"(",
"Progress",
"$",
"wp",
")",
"{",
"$",
"ui",
"=",
"UserInfo",
"::",
"getByID",
"(",
"$",
"this",
"->",
"getRequestedUserID",
"(",
")",
")",
";",
"$",
"wpr",
"=",
"parent",
"::",
"cancel",
"(",
"$",
"wp",
")",
";",
"$",
"wpr",
"->",
"message",
"=",
"t",
"(",
"\"User deletion request has been cancelled.\"",
")",
";",
"return",
"$",
"wpr",
";",
"}"
] | After canceling delete request, do nothing | [
"After",
"canceling",
"delete",
"request",
"do",
"nothing"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Workflow/Request/DeleteUserRequest.php#L67-L74 | train |
concrete5/concrete5 | concrete/src/Foundation/Runtime/Run/DefaultRunner.php | DefaultRunner.initializeLegacyURLDefinitions | protected function initializeLegacyURLDefinitions()
{
if (!defined('BASE_URL')) {
$resolver = $this->getUrlResolver();
try {
$url = rtrim((string) $resolver->resolve([]), '/');
define('BASE_URL', $url);
} catch (Exception $x) {
return Response::create($x->getMessage(), 500);
}
}
} | php | protected function initializeLegacyURLDefinitions()
{
if (!defined('BASE_URL')) {
$resolver = $this->getUrlResolver();
try {
$url = rtrim((string) $resolver->resolve([]), '/');
define('BASE_URL', $url);
} catch (Exception $x) {
return Response::create($x->getMessage(), 500);
}
}
} | [
"protected",
"function",
"initializeLegacyURLDefinitions",
"(",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'BASE_URL'",
")",
")",
"{",
"$",
"resolver",
"=",
"$",
"this",
"->",
"getUrlResolver",
"(",
")",
";",
"try",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"(",
"string",
")",
"$",
"resolver",
"->",
"resolve",
"(",
"[",
"]",
")",
",",
"'/'",
")",
";",
"define",
"(",
"'BASE_URL'",
",",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"return",
"Response",
"::",
"create",
"(",
"$",
"x",
"->",
"getMessage",
"(",
")",
",",
"500",
")",
";",
"}",
"}",
"}"
] | Define the base url if not defined
This will define `BASE_URL` to whatever is resolved from the resolver.
@deprecated In a future major version this will be part of HTTP middleware
@return Response|void Returns a response if an error occurs | [
"Define",
"the",
"base",
"url",
"if",
"not",
"defined",
"This",
"will",
"define",
"BASE_URL",
"to",
"whatever",
"is",
"resolved",
"from",
"the",
"resolver",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/Run/DefaultRunner.php#L134-L146 | train |
concrete5/concrete5 | concrete/src/Foundation/Runtime/Run/DefaultRunner.php | DefaultRunner.setSystemLocale | protected function setSystemLocale()
{
$u = new User();
$lan = $u->getUserLanguageToDisplay();
$loc = Localization::getInstance();
$loc->setContextLocale(Localization::CONTEXT_UI, $lan);
} | php | protected function setSystemLocale()
{
$u = new User();
$lan = $u->getUserLanguageToDisplay();
$loc = Localization::getInstance();
$loc->setContextLocale(Localization::CONTEXT_UI, $lan);
} | [
"protected",
"function",
"setSystemLocale",
"(",
")",
"{",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"$",
"lan",
"=",
"$",
"u",
"->",
"getUserLanguageToDisplay",
"(",
")",
";",
"$",
"loc",
"=",
"Localization",
"::",
"getInstance",
"(",
")",
";",
"$",
"loc",
"->",
"setContextLocale",
"(",
"Localization",
"::",
"CONTEXT_UI",
",",
"$",
"lan",
")",
";",
"}"
] | Initialize localization.
@deprecated In a future major version this will be part of HTTP middleware | [
"Initialize",
"localization",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/Run/DefaultRunner.php#L182-L188 | train |
concrete5/concrete5 | concrete/src/Foundation/Runtime/Run/DefaultRunner.php | DefaultRunner.registerLegacyConfigValues | protected function registerLegacyConfigValues()
{
$config = $this->getConfig();
$name = $this->getSiteService()->getSite()->getSiteName();
$config->set('concrete.site', $name);
} | php | protected function registerLegacyConfigValues()
{
$config = $this->getConfig();
$name = $this->getSiteService()->getSite()->getSiteName();
$config->set('concrete.site', $name);
} | [
"protected",
"function",
"registerLegacyConfigValues",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getSiteService",
"(",
")",
"->",
"getSite",
"(",
")",
"->",
"getSiteName",
"(",
")",
";",
"$",
"config",
"->",
"set",
"(",
"'concrete.site'",
",",
"$",
"name",
")",
";",
"}"
] | Set legacy config values
This sets `concrete.site` to the current site's sitename.
@deprecated In a future major version this will be part of HTTP middleware
@return Response|void Returns a response if an error occurs | [
"Set",
"legacy",
"config",
"values",
"This",
"sets",
"concrete",
".",
"site",
"to",
"the",
"current",
"site",
"s",
"sitename",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/Run/DefaultRunner.php#L198-L204 | train |
concrete5/concrete5 | concrete/src/Foundation/Runtime/Run/DefaultRunner.php | DefaultRunner.handleUpdates | protected function handleUpdates()
{
$config = $this->app->make('config');
if (!$config->get('concrete.maintenance_mode')) {
try {
$this->app->handleAutomaticUpdates();
} catch (MutexBusyException $x) {
if ($x->getMutexKey() !== Update::MUTEX_KEY) {
throw $x;
}
$config->set('concrete.maintenance_mode', true);
}
catch (MigrationIncompleteException $x) {
$request = Request::getInstance();
$requestUri = $request->getUri();
$rf = $this->app->make(ResponseFactoryInterface::class);
return $rf->redirect($requestUri, Response::HTTP_FOUND);
}
}
} | php | protected function handleUpdates()
{
$config = $this->app->make('config');
if (!$config->get('concrete.maintenance_mode')) {
try {
$this->app->handleAutomaticUpdates();
} catch (MutexBusyException $x) {
if ($x->getMutexKey() !== Update::MUTEX_KEY) {
throw $x;
}
$config->set('concrete.maintenance_mode', true);
}
catch (MigrationIncompleteException $x) {
$request = Request::getInstance();
$requestUri = $request->getUri();
$rf = $this->app->make(ResponseFactoryInterface::class);
return $rf->redirect($requestUri, Response::HTTP_FOUND);
}
}
} | [
"protected",
"function",
"handleUpdates",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"if",
"(",
"!",
"$",
"config",
"->",
"get",
"(",
"'concrete.maintenance_mode'",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"app",
"->",
"handleAutomaticUpdates",
"(",
")",
";",
"}",
"catch",
"(",
"MutexBusyException",
"$",
"x",
")",
"{",
"if",
"(",
"$",
"x",
"->",
"getMutexKey",
"(",
")",
"!==",
"Update",
"::",
"MUTEX_KEY",
")",
"{",
"throw",
"$",
"x",
";",
"}",
"$",
"config",
"->",
"set",
"(",
"'concrete.maintenance_mode'",
",",
"true",
")",
";",
"}",
"catch",
"(",
"MigrationIncompleteException",
"$",
"x",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"getInstance",
"(",
")",
";",
"$",
"requestUri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"rf",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"ResponseFactoryInterface",
"::",
"class",
")",
";",
"return",
"$",
"rf",
"->",
"redirect",
"(",
"$",
"requestUri",
",",
"Response",
"::",
"HTTP_FOUND",
")",
";",
"}",
"}",
"}"
] | Update automatically.
@deprecated In a future major version this will be part of HTTP middleware
@return Response|void Returns a response if an error occurs | [
"Update",
"automatically",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/Run/DefaultRunner.php#L275-L294 | train |
concrete5/concrete5 | concrete/src/Foundation/Runtime/Run/DefaultRunner.php | DefaultRunner.trySteps | protected function trySteps(array $steps)
{
foreach ($steps as $step) {
// Run each step and return if there's a result
if ($result = $this->$step()) {
return $result;
}
}
return null;
} | php | protected function trySteps(array $steps)
{
foreach ($steps as $step) {
// Run each step and return if there's a result
if ($result = $this->$step()) {
return $result;
}
}
return null;
} | [
"protected",
"function",
"trySteps",
"(",
"array",
"$",
"steps",
")",
"{",
"foreach",
"(",
"$",
"steps",
"as",
"$",
"step",
")",
"{",
"// Run each step and return if there's a result",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"$",
"step",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Try a list of steps. If a response is returned, halt progression and return the response;.
@param string[] $steps
@return Response|null | [
"Try",
"a",
"list",
"of",
"steps",
".",
"If",
"a",
"response",
"is",
"returned",
"halt",
"progression",
"and",
"return",
"the",
"response",
";",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/Run/DefaultRunner.php#L328-L338 | train |
concrete5/concrete5 | concrete/src/Permission/Key/ConversationKey.php | ConversationKey.getPermissionAssignmentObject | public function getPermissionAssignmentObject()
{
$targ = Core::make('\Concrete\Core\Permission\Assignment\ConversationAssignment');
if (is_object($this->permissionObject)) {
$targ->setPermissionObject($this->permissionObject);
}
$targ->setPermissionKeyObject($this);
return $targ;
} | php | public function getPermissionAssignmentObject()
{
$targ = Core::make('\Concrete\Core\Permission\Assignment\ConversationAssignment');
if (is_object($this->permissionObject)) {
$targ->setPermissionObject($this->permissionObject);
}
$targ->setPermissionKeyObject($this);
return $targ;
} | [
"public",
"function",
"getPermissionAssignmentObject",
"(",
")",
"{",
"$",
"targ",
"=",
"Core",
"::",
"make",
"(",
"'\\Concrete\\Core\\Permission\\Assignment\\ConversationAssignment'",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"permissionObject",
")",
")",
"{",
"$",
"targ",
"->",
"setPermissionObject",
"(",
"$",
"this",
"->",
"permissionObject",
")",
";",
"}",
"$",
"targ",
"->",
"setPermissionKeyObject",
"(",
"$",
"this",
")",
";",
"return",
"$",
"targ",
";",
"}"
] | We need this because we don't always have a permission object | [
"We",
"need",
"this",
"because",
"we",
"don",
"t",
"always",
"have",
"a",
"permission",
"object"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/ConversationKey.php#L11-L20 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getMySets | public static function getMySets($user = false)
{
$app = Facade::getFacadeApplication();
if ($user === false) {
$user = $app->make(User::class);
}
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$fileSets = array();
$queryBuilder = $database->createQueryBuilder();
$results = $queryBuilder->select('*')->from('FileSets')->where(
$queryBuilder->expr()->eq('fsType', self::TYPE_PUBLIC)
)->orWhere(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->in('fsType',[self::TYPE_PRIVATE, self::TYPE_STARRED, self::TYPE_PUBLIC]),
$queryBuilder->expr()->eq('uID', $user->getUserID())
)
)->orderBy('fsName', 'ASC')->execute();
while ($row = $results->fetch()) {
$fileSet = new static();
$fileSet = array_to_object($fileSet, $row);
$fileSets[] = $fileSet;
}
return $fileSets;
} | php | public static function getMySets($user = false)
{
$app = Facade::getFacadeApplication();
if ($user === false) {
$user = $app->make(User::class);
}
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$fileSets = array();
$queryBuilder = $database->createQueryBuilder();
$results = $queryBuilder->select('*')->from('FileSets')->where(
$queryBuilder->expr()->eq('fsType', self::TYPE_PUBLIC)
)->orWhere(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->in('fsType',[self::TYPE_PRIVATE, self::TYPE_STARRED, self::TYPE_PUBLIC]),
$queryBuilder->expr()->eq('uID', $user->getUserID())
)
)->orderBy('fsName', 'ASC')->execute();
while ($row = $results->fetch()) {
$fileSet = new static();
$fileSet = array_to_object($fileSet, $row);
$fileSets[] = $fileSet;
}
return $fileSets;
} | [
"public",
"static",
"function",
"getMySets",
"(",
"$",
"user",
"=",
"false",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"if",
"(",
"$",
"user",
"===",
"false",
")",
"{",
"$",
"user",
"=",
"$",
"app",
"->",
"make",
"(",
"User",
"::",
"class",
")",
";",
"}",
"/** @var $database \\Concrete\\Core\\Database\\Connection\\Connection */",
"$",
"database",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"fileSets",
"=",
"array",
"(",
")",
";",
"$",
"queryBuilder",
"=",
"$",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"results",
"=",
"$",
"queryBuilder",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"'FileSets'",
")",
"->",
"where",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'fsType'",
",",
"self",
"::",
"TYPE_PUBLIC",
")",
")",
"->",
"orWhere",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'fsType'",
",",
"[",
"self",
"::",
"TYPE_PRIVATE",
",",
"self",
"::",
"TYPE_STARRED",
",",
"self",
"::",
"TYPE_PUBLIC",
"]",
")",
",",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'uID'",
",",
"$",
"user",
"->",
"getUserID",
"(",
")",
")",
")",
")",
"->",
"orderBy",
"(",
"'fsName'",
",",
"'ASC'",
")",
"->",
"execute",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"results",
"->",
"fetch",
"(",
")",
")",
"{",
"$",
"fileSet",
"=",
"new",
"static",
"(",
")",
";",
"$",
"fileSet",
"=",
"array_to_object",
"(",
"$",
"fileSet",
",",
"$",
"row",
")",
";",
"$",
"fileSets",
"[",
"]",
"=",
"$",
"fileSet",
";",
"}",
"return",
"$",
"fileSets",
";",
"}"
] | Returns all sets currently available to the User
@param bool|User|\Concrete\Core\User\UserInfo $user
@return static[] | [
"Returns",
"all",
"sets",
"currently",
"available",
"to",
"the",
"User"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L86-L116 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.createAndGetSet | public static function createAndGetSet($fs_name, $fs_type, $fs_uid = false)
{
if ($fs_uid === false) {
$u = new User();
$fs_uid = $u->uID;
}
$db = Database::connection();
$criteria = array($fs_name, $fs_type, $fs_uid);
$fsID = $db->fetchColumn('SELECT fsID FROM FileSets WHERE fsName=? AND fsType=? AND uID=?', $criteria);
if ($fsID > 0) {
return static::getByID($fsID);
} else {
$fs = static::create($fs_name, 0, $fs_uid, $fs_type);
return $fs;
}
} | php | public static function createAndGetSet($fs_name, $fs_type, $fs_uid = false)
{
if ($fs_uid === false) {
$u = new User();
$fs_uid = $u->uID;
}
$db = Database::connection();
$criteria = array($fs_name, $fs_type, $fs_uid);
$fsID = $db->fetchColumn('SELECT fsID FROM FileSets WHERE fsName=? AND fsType=? AND uID=?', $criteria);
if ($fsID > 0) {
return static::getByID($fsID);
} else {
$fs = static::create($fs_name, 0, $fs_uid, $fs_type);
return $fs;
}
} | [
"public",
"static",
"function",
"createAndGetSet",
"(",
"$",
"fs_name",
",",
"$",
"fs_type",
",",
"$",
"fs_uid",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"fs_uid",
"===",
"false",
")",
"{",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"$",
"fs_uid",
"=",
"$",
"u",
"->",
"uID",
";",
"}",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"criteria",
"=",
"array",
"(",
"$",
"fs_name",
",",
"$",
"fs_type",
",",
"$",
"fs_uid",
")",
";",
"$",
"fsID",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'SELECT fsID FROM FileSets WHERE fsName=? AND fsType=? AND uID=?'",
",",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"fsID",
">",
"0",
")",
"{",
"return",
"static",
"::",
"getByID",
"(",
"$",
"fsID",
")",
";",
"}",
"else",
"{",
"$",
"fs",
"=",
"static",
"::",
"create",
"(",
"$",
"fs_name",
",",
"0",
",",
"$",
"fs_uid",
",",
"$",
"fs_type",
")",
";",
"return",
"$",
"fs",
";",
"}",
"}"
] | Creats a new fileset if set doesn't exists.
If we find a multiple groups with the same properties,
we return an array containing each group
@param string $fs_name
@param int $fs_type
@param int|bool $fs_uid
@return mixed
Dev Note: This will create duplicate sets with the same name if a set exists owned by another user!!! | [
"Creats",
"a",
"new",
"fileset",
"if",
"set",
"doesn",
"t",
"exists",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L168-L185 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getByID | public static function getByID($fsID)
{
$db = Database::connection();
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsID = ?', array($fsID));
if (is_array($row)) {
$fs = new static();
$fs = array_to_object($fs, $row);
if ($row['fsType'] == static::TYPE_SAVED_SEARCH) {
$row2 = $db->GetRow(
'SELECT fsSearchRequest, fsResultColumns FROM FileSetSavedSearches WHERE fsID = ?',
array($fsID));
$fs->fsSearchRequest = @unserialize($row2['fsSearchRequest']);
$fs->fsResultColumns = @unserialize($row2['fsResultColumns']);
}
return $fs;
}
} | php | public static function getByID($fsID)
{
$db = Database::connection();
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsID = ?', array($fsID));
if (is_array($row)) {
$fs = new static();
$fs = array_to_object($fs, $row);
if ($row['fsType'] == static::TYPE_SAVED_SEARCH) {
$row2 = $db->GetRow(
'SELECT fsSearchRequest, fsResultColumns FROM FileSetSavedSearches WHERE fsID = ?',
array($fsID));
$fs->fsSearchRequest = @unserialize($row2['fsSearchRequest']);
$fs->fsResultColumns = @unserialize($row2['fsResultColumns']);
}
return $fs;
}
} | [
"public",
"static",
"function",
"getByID",
"(",
"$",
"fsID",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"row",
"=",
"$",
"db",
"->",
"fetchAssoc",
"(",
"'SELECT * FROM FileSets WHERE fsID = ?'",
",",
"array",
"(",
"$",
"fsID",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"$",
"fs",
"=",
"new",
"static",
"(",
")",
";",
"$",
"fs",
"=",
"array_to_object",
"(",
"$",
"fs",
",",
"$",
"row",
")",
";",
"if",
"(",
"$",
"row",
"[",
"'fsType'",
"]",
"==",
"static",
"::",
"TYPE_SAVED_SEARCH",
")",
"{",
"$",
"row2",
"=",
"$",
"db",
"->",
"GetRow",
"(",
"'SELECT fsSearchRequest, fsResultColumns FROM FileSetSavedSearches WHERE fsID = ?'",
",",
"array",
"(",
"$",
"fsID",
")",
")",
";",
"$",
"fs",
"->",
"fsSearchRequest",
"=",
"@",
"unserialize",
"(",
"$",
"row2",
"[",
"'fsSearchRequest'",
"]",
")",
";",
"$",
"fs",
"->",
"fsResultColumns",
"=",
"@",
"unserialize",
"(",
"$",
"row2",
"[",
"'fsResultColumns'",
"]",
")",
";",
"}",
"return",
"$",
"fs",
";",
"}",
"}"
] | Get a file set object by a file set's id.
@param int $fsID
@return Set | [
"Get",
"a",
"file",
"set",
"object",
"by",
"a",
"file",
"set",
"s",
"id",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L194-L211 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.create | public static function create($setName, $fsOverrideGlobalPermissions = 0, $u = false, $type = self::TYPE_PUBLIC)
{
if (is_object($u) && $u->isRegistered()) {
$uID = $u->getUserID();
} else {
if ($u) {
$uID = $u;
} else {
$uID = 0;
}
}
$db = Database::connection();
$db->insert(
"FileSets",
array(
'fsType' => $type,
'uID' => $uID,
'fsName' => $setName,
)
);
$fsID = $db->lastInsertId();
$fs = static::getByID($fsID);
$fe = new \Concrete\Core\File\Event\FileSet($fs);
Events::dispatch('on_file_set_add', $fe);
return $fs;
} | php | public static function create($setName, $fsOverrideGlobalPermissions = 0, $u = false, $type = self::TYPE_PUBLIC)
{
if (is_object($u) && $u->isRegistered()) {
$uID = $u->getUserID();
} else {
if ($u) {
$uID = $u;
} else {
$uID = 0;
}
}
$db = Database::connection();
$db->insert(
"FileSets",
array(
'fsType' => $type,
'uID' => $uID,
'fsName' => $setName,
)
);
$fsID = $db->lastInsertId();
$fs = static::getByID($fsID);
$fe = new \Concrete\Core\File\Event\FileSet($fs);
Events::dispatch('on_file_set_add', $fe);
return $fs;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"setName",
",",
"$",
"fsOverrideGlobalPermissions",
"=",
"0",
",",
"$",
"u",
"=",
"false",
",",
"$",
"type",
"=",
"self",
"::",
"TYPE_PUBLIC",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"u",
")",
"&&",
"$",
"u",
"->",
"isRegistered",
"(",
")",
")",
"{",
"$",
"uID",
"=",
"$",
"u",
"->",
"getUserID",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"u",
")",
"{",
"$",
"uID",
"=",
"$",
"u",
";",
"}",
"else",
"{",
"$",
"uID",
"=",
"0",
";",
"}",
"}",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"db",
"->",
"insert",
"(",
"\"FileSets\"",
",",
"array",
"(",
"'fsType'",
"=>",
"$",
"type",
",",
"'uID'",
"=>",
"$",
"uID",
",",
"'fsName'",
"=>",
"$",
"setName",
",",
")",
")",
";",
"$",
"fsID",
"=",
"$",
"db",
"->",
"lastInsertId",
"(",
")",
";",
"$",
"fs",
"=",
"static",
"::",
"getByID",
"(",
"$",
"fsID",
")",
";",
"$",
"fe",
"=",
"new",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"File",
"\\",
"Event",
"\\",
"FileSet",
"(",
"$",
"fs",
")",
";",
"Events",
"::",
"dispatch",
"(",
"'on_file_set_add'",
",",
"$",
"fe",
")",
";",
"return",
"$",
"fs",
";",
"}"
] | Adds a File set.
@param string $setName
@param int $fsOverrideGlobalPermissions
@param bool|\User $u
@param int $type
@return Set | [
"Adds",
"a",
"File",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L231-L259 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getFilesBySetID | public static function getFilesBySetID($fsID)
{
if (intval($fsID) > 0) {
$fileset = self::getByID($fsID);
if ($fileset instanceof \Concrete\Core\File\Set\Set) {
return $fileset->getFiles();
}
}
} | php | public static function getFilesBySetID($fsID)
{
if (intval($fsID) > 0) {
$fileset = self::getByID($fsID);
if ($fileset instanceof \Concrete\Core\File\Set\Set) {
return $fileset->getFiles();
}
}
} | [
"public",
"static",
"function",
"getFilesBySetID",
"(",
"$",
"fsID",
")",
"{",
"if",
"(",
"intval",
"(",
"$",
"fsID",
")",
">",
"0",
")",
"{",
"$",
"fileset",
"=",
"self",
"::",
"getByID",
"(",
"$",
"fsID",
")",
";",
"if",
"(",
"$",
"fileset",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"File",
"\\",
"Set",
"\\",
"Set",
")",
"{",
"return",
"$",
"fileset",
"->",
"getFiles",
"(",
")",
";",
"}",
"}",
"}"
] | Static method to return an array of File objects by the set id.
@param int $fsID
@return array|void | [
"Static",
"method",
"to",
"return",
"an",
"array",
"of",
"File",
"objects",
"by",
"the",
"set",
"id",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L268-L276 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getFilesBySetName | public static function getFilesBySetName($fsName, $uID = false)
{
if (!empty($fsName)) {
$fileset = self::getByName($fsName, $uID);
if ($fileset instanceof \Concrete\Core\File\Set\Set) {
return $fileset->getFiles();
}
}
} | php | public static function getFilesBySetName($fsName, $uID = false)
{
if (!empty($fsName)) {
$fileset = self::getByName($fsName, $uID);
if ($fileset instanceof \Concrete\Core\File\Set\Set) {
return $fileset->getFiles();
}
}
} | [
"public",
"static",
"function",
"getFilesBySetName",
"(",
"$",
"fsName",
",",
"$",
"uID",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"fsName",
")",
")",
"{",
"$",
"fileset",
"=",
"self",
"::",
"getByName",
"(",
"$",
"fsName",
",",
"$",
"uID",
")",
";",
"if",
"(",
"$",
"fileset",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"File",
"\\",
"Set",
"\\",
"Set",
")",
"{",
"return",
"$",
"fileset",
"->",
"getFiles",
"(",
")",
";",
"}",
"}",
"}"
] | Static method to return an array of File objects by the set name.
@param string $fsName
@param int|bool $uID
@return array|void | [
"Static",
"method",
"to",
"return",
"an",
"array",
"of",
"File",
"objects",
"by",
"the",
"set",
"name",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L286-L294 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getByName | public static function getByName($fsName, $uID = false)
{
$db = Database::connection();
if ($uID !== false) {
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsName = ? AND uID = ?', array($fsName, $uID));
} else {
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsName = ?', array($fsName));
}
if (is_array($row) && count($row)) {
$fs = new static();
$fs = array_to_object($fs, $row);
return $fs;
}
} | php | public static function getByName($fsName, $uID = false)
{
$db = Database::connection();
if ($uID !== false) {
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsName = ? AND uID = ?', array($fsName, $uID));
} else {
$row = $db->fetchAssoc('SELECT * FROM FileSets WHERE fsName = ?', array($fsName));
}
if (is_array($row) && count($row)) {
$fs = new static();
$fs = array_to_object($fs, $row);
return $fs;
}
} | [
"public",
"static",
"function",
"getByName",
"(",
"$",
"fsName",
",",
"$",
"uID",
"=",
"false",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"if",
"(",
"$",
"uID",
"!==",
"false",
")",
"{",
"$",
"row",
"=",
"$",
"db",
"->",
"fetchAssoc",
"(",
"'SELECT * FROM FileSets WHERE fsName = ? AND uID = ?'",
",",
"array",
"(",
"$",
"fsName",
",",
"$",
"uID",
")",
")",
";",
"}",
"else",
"{",
"$",
"row",
"=",
"$",
"db",
"->",
"fetchAssoc",
"(",
"'SELECT * FROM FileSets WHERE fsName = ?'",
",",
"array",
"(",
"$",
"fsName",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
"&&",
"count",
"(",
"$",
"row",
")",
")",
"{",
"$",
"fs",
"=",
"new",
"static",
"(",
")",
";",
"$",
"fs",
"=",
"array_to_object",
"(",
"$",
"fs",
",",
"$",
"row",
")",
";",
"return",
"$",
"fs",
";",
"}",
"}"
] | Get a file set object by a file name.
@param string $fsName
@param int|bool $uID
@return Set | [
"Get",
"a",
"file",
"set",
"object",
"by",
"a",
"file",
"name",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L304-L318 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.getFiles | public function getFiles()
{
if (!$this->fileSetFiles) {
$this->populateFiles();
}
$files = array();
foreach ($this->fileSetFiles as $file) {
$files[] = ConcreteFile::getByID($file->fID);
}
return $files;
} | php | public function getFiles()
{
if (!$this->fileSetFiles) {
$this->populateFiles();
}
$files = array();
foreach ($this->fileSetFiles as $file) {
$files[] = ConcreteFile::getByID($file->fID);
}
return $files;
} | [
"public",
"function",
"getFiles",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"fileSetFiles",
")",
"{",
"$",
"this",
"->",
"populateFiles",
"(",
")",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fileSetFiles",
"as",
"$",
"file",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"ConcreteFile",
"::",
"getByID",
"(",
"$",
"file",
"->",
"fID",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Returns an array of File objects from the current set.
@return ConcreteFile[] | [
"Returns",
"an",
"array",
"of",
"File",
"objects",
"from",
"the",
"current",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L325-L336 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.update | public function update($setName)
{
$db = Database::connection();
$db->update(
'FileSets',
array('fsName' => $setName),
array('fsID' => $this->fsID)
);
return static::getByID($this->fsID);
} | php | public function update($setName)
{
$db = Database::connection();
$db->update(
'FileSets',
array('fsName' => $setName),
array('fsID' => $this->fsID)
);
return static::getByID($this->fsID);
} | [
"public",
"function",
"update",
"(",
"$",
"setName",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"db",
"->",
"update",
"(",
"'FileSets'",
",",
"array",
"(",
"'fsName'",
"=>",
"$",
"setName",
")",
",",
"array",
"(",
"'fsID'",
"=>",
"$",
"this",
"->",
"fsID",
")",
")",
";",
"return",
"static",
"::",
"getByID",
"(",
"$",
"this",
"->",
"fsID",
")",
";",
"}"
] | Updates a file set.
@return Set | [
"Updates",
"a",
"file",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L453-L463 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.addFileToSet | public function addFileToSet($f_id)
{
$app = Application::getFacadeApplication();
if (is_object($f_id)) {
$f = $f_id;
if ($f instanceof FileEntity) {
$file = $f;
$fileVersion = $file->getApprovedVersion();
} else {
$fileVersion = $f;
$file = $fileVersion->getFile();
}
$f_id = (int) $file->getFileID();
} else {
$f_id = (int) $f_id;
$em = $app->make(EntityManagerInterface::class);
$file = $em->find(FileEntity::class, $f_id);
$fileVersion = $file->getApprovedVersion();
}
if ($file === null) {
$result = null;
} else {
$file_set_file = File::createAndGetFile($f_id, $this->fsID);
$fe = new \Concrete\Core\File\Event\FileSetFile($file_set_file);
$director = $app->make(EventDispatcherInterface::class);
$director->dispatch('on_file_added_to_set', $fe);
if ($fileVersion !== null && $this->shouldRefreshFileThumbnails('add')) {
$fileVersion->refreshThumbnails(false);
}
$result = $file_set_file;
}
return $result;
} | php | public function addFileToSet($f_id)
{
$app = Application::getFacadeApplication();
if (is_object($f_id)) {
$f = $f_id;
if ($f instanceof FileEntity) {
$file = $f;
$fileVersion = $file->getApprovedVersion();
} else {
$fileVersion = $f;
$file = $fileVersion->getFile();
}
$f_id = (int) $file->getFileID();
} else {
$f_id = (int) $f_id;
$em = $app->make(EntityManagerInterface::class);
$file = $em->find(FileEntity::class, $f_id);
$fileVersion = $file->getApprovedVersion();
}
if ($file === null) {
$result = null;
} else {
$file_set_file = File::createAndGetFile($f_id, $this->fsID);
$fe = new \Concrete\Core\File\Event\FileSetFile($file_set_file);
$director = $app->make(EventDispatcherInterface::class);
$director->dispatch('on_file_added_to_set', $fe);
if ($fileVersion !== null && $this->shouldRefreshFileThumbnails('add')) {
$fileVersion->refreshThumbnails(false);
}
$result = $file_set_file;
}
return $result;
} | [
"public",
"function",
"addFileToSet",
"(",
"$",
"f_id",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"f_id",
")",
")",
"{",
"$",
"f",
"=",
"$",
"f_id",
";",
"if",
"(",
"$",
"f",
"instanceof",
"FileEntity",
")",
"{",
"$",
"file",
"=",
"$",
"f",
";",
"$",
"fileVersion",
"=",
"$",
"file",
"->",
"getApprovedVersion",
"(",
")",
";",
"}",
"else",
"{",
"$",
"fileVersion",
"=",
"$",
"f",
";",
"$",
"file",
"=",
"$",
"fileVersion",
"->",
"getFile",
"(",
")",
";",
"}",
"$",
"f_id",
"=",
"(",
"int",
")",
"$",
"file",
"->",
"getFileID",
"(",
")",
";",
"}",
"else",
"{",
"$",
"f_id",
"=",
"(",
"int",
")",
"$",
"f_id",
";",
"$",
"em",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"$",
"file",
"=",
"$",
"em",
"->",
"find",
"(",
"FileEntity",
"::",
"class",
",",
"$",
"f_id",
")",
";",
"$",
"fileVersion",
"=",
"$",
"file",
"->",
"getApprovedVersion",
"(",
")",
";",
"}",
"if",
"(",
"$",
"file",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"file_set_file",
"=",
"File",
"::",
"createAndGetFile",
"(",
"$",
"f_id",
",",
"$",
"this",
"->",
"fsID",
")",
";",
"$",
"fe",
"=",
"new",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"File",
"\\",
"Event",
"\\",
"FileSetFile",
"(",
"$",
"file_set_file",
")",
";",
"$",
"director",
"=",
"$",
"app",
"->",
"make",
"(",
"EventDispatcherInterface",
"::",
"class",
")",
";",
"$",
"director",
"->",
"dispatch",
"(",
"'on_file_added_to_set'",
",",
"$",
"fe",
")",
";",
"if",
"(",
"$",
"fileVersion",
"!==",
"null",
"&&",
"$",
"this",
"->",
"shouldRefreshFileThumbnails",
"(",
"'add'",
")",
")",
"{",
"$",
"fileVersion",
"->",
"refreshThumbnails",
"(",
"false",
")",
";",
"}",
"$",
"result",
"=",
"$",
"file_set_file",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Adds the file to the set.
@param int|FileEntity|FileVersionEntity $f_id
@return \Concrete\Core\File\Set\File|null returns NULL if the operation failed (for instance because $f_id is invalid), a \Concrete\Core\File\Set\File instance otherwise | [
"Adds",
"the",
"file",
"to",
"the",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L472-L505 | train |
concrete5/concrete5 | concrete/src/File/Set/Set.php | Set.shouldRefreshFileThumbnails | protected function shouldRefreshFileThumbnails($fileOperation)
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$qb = $em->createQueryBuilder();
$qb
->select('ft.ftTypeID')
->from(ThumbnailType::class, 'ft')
->innerJoin('ft.ftAssociatedFileSets', 'ftfs')
->andWhere($qb->expr()->eq('ftfs.ftfsFileSetID', ':fsID'))
->setParameter('fsID', $this->getFileSetID())
->andWhere($qb->expr()->eq('ft.ftLimitedToFileSets', ':limitedTo'))
->setParameter('limitedTo', $fileOperation === 'add')
->setMaxResults(1)
;
$query = $qb->getQuery();
return $query->getOneOrNullResult($query::HYDRATE_SINGLE_SCALAR) !== null;
} | php | protected function shouldRefreshFileThumbnails($fileOperation)
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$qb = $em->createQueryBuilder();
$qb
->select('ft.ftTypeID')
->from(ThumbnailType::class, 'ft')
->innerJoin('ft.ftAssociatedFileSets', 'ftfs')
->andWhere($qb->expr()->eq('ftfs.ftfsFileSetID', ':fsID'))
->setParameter('fsID', $this->getFileSetID())
->andWhere($qb->expr()->eq('ft.ftLimitedToFileSets', ':limitedTo'))
->setParameter('limitedTo', $fileOperation === 'add')
->setMaxResults(1)
;
$query = $qb->getQuery();
return $query->getOneOrNullResult($query::HYDRATE_SINGLE_SCALAR) !== null;
} | [
"protected",
"function",
"shouldRefreshFileThumbnails",
"(",
"$",
"fileOperation",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"em",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"$",
"qb",
"=",
"$",
"em",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"'ft.ftTypeID'",
")",
"->",
"from",
"(",
"ThumbnailType",
"::",
"class",
",",
"'ft'",
")",
"->",
"innerJoin",
"(",
"'ft.ftAssociatedFileSets'",
",",
"'ftfs'",
")",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'ftfs.ftfsFileSetID'",
",",
"':fsID'",
")",
")",
"->",
"setParameter",
"(",
"'fsID'",
",",
"$",
"this",
"->",
"getFileSetID",
"(",
")",
")",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'ft.ftLimitedToFileSets'",
",",
"':limitedTo'",
")",
")",
"->",
"setParameter",
"(",
"'limitedTo'",
",",
"$",
"fileOperation",
"===",
"'add'",
")",
"->",
"setMaxResults",
"(",
"1",
")",
";",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"return",
"$",
"query",
"->",
"getOneOrNullResult",
"(",
"$",
"query",
"::",
"HYDRATE_SINGLE_SCALAR",
")",
"!==",
"null",
";",
"}"
] | Check if we should build the thumbnails for files added or removed to this file set should.
@param string $fileOperation 'add' or 'remove'
@return bool | [
"Check",
"if",
"we",
"should",
"build",
"the",
"thumbnails",
"for",
"files",
"added",
"or",
"removed",
"to",
"this",
"file",
"set",
"should",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Set/Set.php#L691-L709 | train |
concrete5/concrete5 | concrete/src/Job/Job.php | Job.authenticateRequest | public static function authenticateRequest($auth)
{
// this is a little tricky. We have TWO ways of doing this
// 1. Does the security token for jobs md5 correctly? If so, good.
$val = \Core::make('config/database')->get('concrete.security.token.jobs') . ':' . DIRNAME_JOBS;
if (md5($val) == $auth) {
return true;
}
} | php | public static function authenticateRequest($auth)
{
// this is a little tricky. We have TWO ways of doing this
// 1. Does the security token for jobs md5 correctly? If so, good.
$val = \Core::make('config/database')->get('concrete.security.token.jobs') . ':' . DIRNAME_JOBS;
if (md5($val) == $auth) {
return true;
}
} | [
"public",
"static",
"function",
"authenticateRequest",
"(",
"$",
"auth",
")",
"{",
"// this is a little tricky. We have TWO ways of doing this",
"// 1. Does the security token for jobs md5 correctly? If so, good.",
"$",
"val",
"=",
"\\",
"Core",
"::",
"make",
"(",
"'config/database'",
")",
"->",
"get",
"(",
"'concrete.security.token.jobs'",
")",
".",
"':'",
".",
"DIRNAME_JOBS",
";",
"if",
"(",
"md5",
"(",
"$",
"val",
")",
"==",
"$",
"auth",
")",
"{",
"return",
"true",
";",
"}",
"}"
] | or from the dashboard | [
"or",
"from",
"the",
"dashboard"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Job/Job.php#L98-L107 | train |
concrete5/concrete5 | concrete/src/Job/Job.php | Job.getAvailableList | public static function getAvailableList($includeConcreteDirJobs = 1)
{
$jobObjs = array();
//get existing jobs
$existingJobHandles = array();
$existingJobs = static::getList();
foreach ($existingJobs as $j) {
$existingJobHandles[] = $j->getJobHandle();
}
if (!$includeConcreteDirJobs) {
$jobClassLocations = array(DIR_FILES_JOBS);
} else {
$jobClassLocations = static::jobClassLocations();
}
foreach ($jobClassLocations as $jobClassLocation) {
// Open a known directory, and proceed to read its contents
if (is_dir($jobClassLocation)) {
if ($dh = opendir($jobClassLocation)) {
while (($file = readdir($dh)) !== false) {
if (substr($file, strlen($file) - 4) != '.php') {
continue;
}
$alreadyInstalled = 0;
foreach ($existingJobHandles as $existingJobHandle) {
if (substr($file, 0, strlen($file) - 4) == $existingJobHandle) {
$alreadyInstalled = 1;
break;
}
}
if ($alreadyInstalled) {
continue;
}
$jHandle = substr($file, 0, strlen($file) - 4);
$className = static::getClassName($jHandle);
$jobObjs[$jHandle] = Core::make($className);
$jobObjs[$jHandle]->jHandle = $jHandle;
}
closedir($dh);
}
}
}
return $jobObjs;
} | php | public static function getAvailableList($includeConcreteDirJobs = 1)
{
$jobObjs = array();
//get existing jobs
$existingJobHandles = array();
$existingJobs = static::getList();
foreach ($existingJobs as $j) {
$existingJobHandles[] = $j->getJobHandle();
}
if (!$includeConcreteDirJobs) {
$jobClassLocations = array(DIR_FILES_JOBS);
} else {
$jobClassLocations = static::jobClassLocations();
}
foreach ($jobClassLocations as $jobClassLocation) {
// Open a known directory, and proceed to read its contents
if (is_dir($jobClassLocation)) {
if ($dh = opendir($jobClassLocation)) {
while (($file = readdir($dh)) !== false) {
if (substr($file, strlen($file) - 4) != '.php') {
continue;
}
$alreadyInstalled = 0;
foreach ($existingJobHandles as $existingJobHandle) {
if (substr($file, 0, strlen($file) - 4) == $existingJobHandle) {
$alreadyInstalled = 1;
break;
}
}
if ($alreadyInstalled) {
continue;
}
$jHandle = substr($file, 0, strlen($file) - 4);
$className = static::getClassName($jHandle);
$jobObjs[$jHandle] = Core::make($className);
$jobObjs[$jHandle]->jHandle = $jHandle;
}
closedir($dh);
}
}
}
return $jobObjs;
} | [
"public",
"static",
"function",
"getAvailableList",
"(",
"$",
"includeConcreteDirJobs",
"=",
"1",
")",
"{",
"$",
"jobObjs",
"=",
"array",
"(",
")",
";",
"//get existing jobs",
"$",
"existingJobHandles",
"=",
"array",
"(",
")",
";",
"$",
"existingJobs",
"=",
"static",
"::",
"getList",
"(",
")",
";",
"foreach",
"(",
"$",
"existingJobs",
"as",
"$",
"j",
")",
"{",
"$",
"existingJobHandles",
"[",
"]",
"=",
"$",
"j",
"->",
"getJobHandle",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"includeConcreteDirJobs",
")",
"{",
"$",
"jobClassLocations",
"=",
"array",
"(",
"DIR_FILES_JOBS",
")",
";",
"}",
"else",
"{",
"$",
"jobClassLocations",
"=",
"static",
"::",
"jobClassLocations",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"jobClassLocations",
"as",
"$",
"jobClassLocation",
")",
"{",
"// Open a known directory, and proceed to read its contents",
"if",
"(",
"is_dir",
"(",
"$",
"jobClassLocation",
")",
")",
"{",
"if",
"(",
"$",
"dh",
"=",
"opendir",
"(",
"$",
"jobClassLocation",
")",
")",
"{",
"while",
"(",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dh",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"strlen",
"(",
"$",
"file",
")",
"-",
"4",
")",
"!=",
"'.php'",
")",
"{",
"continue",
";",
"}",
"$",
"alreadyInstalled",
"=",
"0",
";",
"foreach",
"(",
"$",
"existingJobHandles",
"as",
"$",
"existingJobHandle",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"strlen",
"(",
"$",
"file",
")",
"-",
"4",
")",
"==",
"$",
"existingJobHandle",
")",
"{",
"$",
"alreadyInstalled",
"=",
"1",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"alreadyInstalled",
")",
"{",
"continue",
";",
"}",
"$",
"jHandle",
"=",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"strlen",
"(",
"$",
"file",
")",
"-",
"4",
")",
";",
"$",
"className",
"=",
"static",
"::",
"getClassName",
"(",
"$",
"jHandle",
")",
";",
"$",
"jobObjs",
"[",
"$",
"jHandle",
"]",
"=",
"Core",
"::",
"make",
"(",
"$",
"className",
")",
";",
"$",
"jobObjs",
"[",
"$",
"jHandle",
"]",
"->",
"jHandle",
"=",
"$",
"jHandle",
";",
"}",
"closedir",
"(",
"$",
"dh",
")",
";",
"}",
"}",
"}",
"return",
"$",
"jobObjs",
";",
"}"
] | Scan job directories for job classes | [
"Scan",
"job",
"directories",
"for",
"job",
"classes"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Job/Job.php#L275-L323 | train |
concrete5/concrete5 | concrete/src/Area/Layout/CustomLayout.php | CustomLayout.enableAreaLayoutCustomColumnWidths | public function enableAreaLayoutCustomColumnWidths()
{
$db = Loader::db();
$db->Execute('update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?', array(1, $this->arLayoutID));
$this->arLayoutIsCustom = true;
} | php | public function enableAreaLayoutCustomColumnWidths()
{
$db = Loader::db();
$db->Execute('update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?', array(1, $this->arLayoutID));
$this->arLayoutIsCustom = true;
} | [
"public",
"function",
"enableAreaLayoutCustomColumnWidths",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?'",
",",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"arLayoutID",
")",
")",
";",
"$",
"this",
"->",
"arLayoutIsCustom",
"=",
"true",
";",
"}"
] | Enable custom column widths on layouts. | [
"Enable",
"custom",
"column",
"widths",
"on",
"layouts",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Layout/CustomLayout.php#L96-L101 | train |
concrete5/concrete5 | concrete/src/Area/Layout/CustomLayout.php | CustomLayout.disableAreaLayoutCustomColumnWidths | public function disableAreaLayoutCustomColumnWidths()
{
$db = Loader::db();
$db->Execute('update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?', array(0, $this->arLayoutID));
$this->arLayoutIsCustom = false;
} | php | public function disableAreaLayoutCustomColumnWidths()
{
$db = Loader::db();
$db->Execute('update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?', array(0, $this->arLayoutID));
$this->arLayoutIsCustom = false;
} | [
"public",
"function",
"disableAreaLayoutCustomColumnWidths",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'update AreaLayouts set arLayoutIsCustom = ? where arLayoutID = ?'",
",",
"array",
"(",
"0",
",",
"$",
"this",
"->",
"arLayoutID",
")",
")",
";",
"$",
"this",
"->",
"arLayoutIsCustom",
"=",
"false",
";",
"}"
] | Disable custom column widths on layouts. | [
"Disable",
"custom",
"column",
"widths",
"on",
"layouts",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Layout/CustomLayout.php#L106-L111 | train |
concrete5/concrete5 | concrete/src/Foundation/Environment/FunctionInspector.php | FunctionInspector.functionAvailable | public function functionAvailable($functionName)
{
$result = false;
if (is_string($functionName)) {
$functionName = trim($functionName);
if ($functionName !== '') {
if (function_exists($functionName)) {
$disabledFunctions = $this->getDisabledFunctions();
if (!in_array(strtolower($functionName), $disabledFunctions, true)) {
$result = true;
}
}
}
}
return $result;
} | php | public function functionAvailable($functionName)
{
$result = false;
if (is_string($functionName)) {
$functionName = trim($functionName);
if ($functionName !== '') {
if (function_exists($functionName)) {
$disabledFunctions = $this->getDisabledFunctions();
if (!in_array(strtolower($functionName), $disabledFunctions, true)) {
$result = true;
}
}
}
}
return $result;
} | [
"public",
"function",
"functionAvailable",
"(",
"$",
"functionName",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"functionName",
")",
")",
"{",
"$",
"functionName",
"=",
"trim",
"(",
"$",
"functionName",
")",
";",
"if",
"(",
"$",
"functionName",
"!==",
"''",
")",
"{",
"if",
"(",
"function_exists",
"(",
"$",
"functionName",
")",
")",
"{",
"$",
"disabledFunctions",
"=",
"$",
"this",
"->",
"getDisabledFunctions",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"functionName",
")",
",",
"$",
"disabledFunctions",
",",
"true",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Check if a function exists and is not disabled.
@param string $functionName
@return bool | [
"Check",
"if",
"a",
"function",
"exists",
"and",
"is",
"not",
"disabled",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Environment/FunctionInspector.php#L62-L78 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.hasAddTemplate | public function hasAddTemplate()
{
$bv = new BlockView($this);
$path = $bv->getBlockPath(FILENAME_BLOCK_ADD);
if (file_exists($path . '/' . FILENAME_BLOCK_ADD)) {
return true;
}
return false;
} | php | public function hasAddTemplate()
{
$bv = new BlockView($this);
$path = $bv->getBlockPath(FILENAME_BLOCK_ADD);
if (file_exists($path . '/' . FILENAME_BLOCK_ADD)) {
return true;
}
return false;
} | [
"public",
"function",
"hasAddTemplate",
"(",
")",
"{",
"$",
"bv",
"=",
"new",
"BlockView",
"(",
"$",
"this",
")",
";",
"$",
"path",
"=",
"$",
"bv",
"->",
"getBlockPath",
"(",
"FILENAME_BLOCK_ADD",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"'/'",
".",
"FILENAME_BLOCK_ADD",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines if the block type has templates available.
@return bool | [
"Determines",
"if",
"the",
"block",
"type",
"has",
"templates",
"available",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L144-L153 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.getBlockTypeComposerTemplates | public function getBlockTypeComposerTemplates()
{
$btHandle = $this->getBlockTypeHandle();
$files = array();
$fh = Loader::helper('file');
$dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
foreach (PackageList::get()->getPackages() as $pkg) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (file_exists($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
$templates = array();
foreach (array_unique($files) as $file) {
$templates[] = new TemplateFile($this, $file);
}
return TemplateFile::sortTemplateFileList($templates);
} | php | public function getBlockTypeComposerTemplates()
{
$btHandle = $this->getBlockTypeHandle();
$files = array();
$fh = Loader::helper('file');
$dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
foreach (PackageList::get()->getPackages() as $pkg) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
if (file_exists($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
$templates = array();
foreach (array_unique($files) as $file) {
$templates[] = new TemplateFile($this, $file);
}
return TemplateFile::sortTemplateFileList($templates);
} | [
"public",
"function",
"getBlockTypeComposerTemplates",
"(",
")",
"{",
"$",
"btHandle",
"=",
"$",
"this",
"->",
"getBlockTypeHandle",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"fh",
"=",
"Loader",
"::",
"helper",
"(",
"'file'",
")",
";",
"$",
"dir",
"=",
"DIR_FILES_BLOCK_TYPES",
".",
"\"/{$btHandle}/\"",
".",
"DIRNAME_BLOCK_TEMPLATES_COMPOSER",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"foreach",
"(",
"PackageList",
"::",
"get",
"(",
")",
"->",
"getPackages",
"(",
")",
"as",
"$",
"pkg",
")",
"{",
"$",
"dir",
"=",
"(",
"is_dir",
"(",
"DIR_PACKAGES",
".",
"'/'",
".",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
")",
"?",
"DIR_PACKAGES",
":",
"DIR_PACKAGES_CORE",
")",
".",
"'/'",
".",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
".",
"'/'",
".",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"btHandle",
".",
"'/'",
".",
"DIRNAME_BLOCK_TEMPLATES_COMPOSER",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"}",
"$",
"dir",
"=",
"DIR_FILES_BLOCK_TYPES_CORE",
".",
"\"/{$btHandle}/\"",
".",
"DIRNAME_BLOCK_TEMPLATES_COMPOSER",
";",
"if",
"(",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_unique",
"(",
"$",
"files",
")",
"as",
"$",
"file",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"new",
"TemplateFile",
"(",
"$",
"this",
",",
"$",
"file",
")",
";",
"}",
"return",
"TemplateFile",
"::",
"sortTemplateFileList",
"(",
"$",
"templates",
")",
";",
"}"
] | gets the available composer templates
used for editing instances of the BlockType while in the composer ui in the dashboard.
@return TemplateFile[] | [
"gets",
"the",
"available",
"composer",
"templates",
"used",
"for",
"editing",
"instances",
"of",
"the",
"BlockType",
"while",
"in",
"the",
"composer",
"ui",
"in",
"the",
"dashboard",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L161-L188 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.getBlockTypeClass | public function getBlockTypeClass()
{
return \Concrete\Core\Block\BlockType\BlockType::getBlockTypeMappedClass($this->getBlockTypeHandle(), $this->getPackageHandle());
} | php | public function getBlockTypeClass()
{
return \Concrete\Core\Block\BlockType\BlockType::getBlockTypeMappedClass($this->getBlockTypeHandle(), $this->getPackageHandle());
} | [
"public",
"function",
"getBlockTypeClass",
"(",
")",
"{",
"return",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Block",
"\\",
"BlockType",
"\\",
"BlockType",
"::",
"getBlockTypeMappedClass",
"(",
"$",
"this",
"->",
"getBlockTypeHandle",
"(",
")",
",",
"$",
"this",
"->",
"getPackageHandle",
"(",
")",
")",
";",
"}"
] | Returns the class for the current block type. | [
"Returns",
"the",
"class",
"for",
"the",
"current",
"block",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L316-L319 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.getBlockTypeSets | public function getBlockTypeSets()
{
$db = Loader::db();
$list = array();
$r = $db->Execute(
'select btsID from BlockTypeSetBlockTypes where btID = ? order by displayOrder asc',
array($this->getBlockTypeID()));
while ($row = $r->FetchRow()) {
$list[] = BlockTypeSet::getByID($row['btsID']);
}
$r->Close();
return $list;
} | php | public function getBlockTypeSets()
{
$db = Loader::db();
$list = array();
$r = $db->Execute(
'select btsID from BlockTypeSetBlockTypes where btID = ? order by displayOrder asc',
array($this->getBlockTypeID()));
while ($row = $r->FetchRow()) {
$list[] = BlockTypeSet::getByID($row['btsID']);
}
$r->Close();
return $list;
} | [
"public",
"function",
"getBlockTypeSets",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"Execute",
"(",
"'select btsID from BlockTypeSetBlockTypes where btID = ? order by displayOrder asc'",
",",
"array",
"(",
"$",
"this",
"->",
"getBlockTypeID",
"(",
")",
")",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"r",
"->",
"FetchRow",
"(",
")",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"BlockTypeSet",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'btsID'",
"]",
")",
";",
"}",
"$",
"r",
"->",
"Close",
"(",
")",
";",
"return",
"$",
"list",
";",
"}"
] | Returns an array of all BlockTypeSet objects that this block is in.
@return BlockTypeSet[] | [
"Returns",
"an",
"array",
"of",
"all",
"BlockTypeSet",
"objects",
"that",
"this",
"block",
"is",
"in",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L336-L349 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.getCount | public function getCount($ignoreUnapprovedVersions = false)
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$now = $app->make('date')->getOverridableNow();
if ($ignoreUnapprovedVersions) {
$count = $db->GetOne(<<<'EOT'
SELECT
count(btID)
FROM
Blocks b
INNER JOIN CollectionVersionBlocks cvb
ON b.bID=cvb.bID
INNER JOIN CollectionVersions cv
ON cvb.cID=cv.cID AND cvb.cvID=cv.cvID AND cv.cvIsApproved=1 AND (cv.cvPublishDate IS NULL OR cv.cvPublishDate <= ?) AND (cv.cvPublishEndDate IS NULL OR cv.cvPublishEndDate >= ?)
WHERE
b.btID = ?
EOT
,
[$now, $now, $this->btID]
);
} else {
$count = $db->GetOne("SELECT count(btID) FROM Blocks WHERE btID = ?", array($this->btID));
}
return $count;
} | php | public function getCount($ignoreUnapprovedVersions = false)
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$now = $app->make('date')->getOverridableNow();
if ($ignoreUnapprovedVersions) {
$count = $db->GetOne(<<<'EOT'
SELECT
count(btID)
FROM
Blocks b
INNER JOIN CollectionVersionBlocks cvb
ON b.bID=cvb.bID
INNER JOIN CollectionVersions cv
ON cvb.cID=cv.cID AND cvb.cvID=cv.cvID AND cv.cvIsApproved=1 AND (cv.cvPublishDate IS NULL OR cv.cvPublishDate <= ?) AND (cv.cvPublishEndDate IS NULL OR cv.cvPublishEndDate >= ?)
WHERE
b.btID = ?
EOT
,
[$now, $now, $this->btID]
);
} else {
$count = $db->GetOne("SELECT count(btID) FROM Blocks WHERE btID = ?", array($this->btID));
}
return $count;
} | [
"public",
"function",
"getCount",
"(",
"$",
"ignoreUnapprovedVersions",
"=",
"false",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"db",
"=",
"$",
"app",
"->",
"make",
"(",
"Connection",
"::",
"class",
")",
";",
"$",
"now",
"=",
"$",
"app",
"->",
"make",
"(",
"'date'",
")",
"->",
"getOverridableNow",
"(",
")",
";",
"if",
"(",
"$",
"ignoreUnapprovedVersions",
")",
"{",
"$",
"count",
"=",
"$",
"db",
"->",
"GetOne",
"(",
"<<<'EOT'\nSELECT\n count(btID)\nFROM\n Blocks b\n INNER JOIN CollectionVersionBlocks cvb\n ON b.bID=cvb.bID\n INNER JOIN CollectionVersions cv\n ON cvb.cID=cv.cID AND cvb.cvID=cv.cvID AND cv.cvIsApproved=1 AND (cv.cvPublishDate IS NULL OR cv.cvPublishDate <= ?) AND (cv.cvPublishEndDate IS NULL OR cv.cvPublishEndDate >= ?)\nWHERE\n b.btID = ?\nEOT",
",",
"[",
"$",
"now",
",",
"$",
"now",
",",
"$",
"this",
"->",
"btID",
"]",
")",
";",
"}",
"else",
"{",
"$",
"count",
"=",
"$",
"db",
"->",
"GetOne",
"(",
"\"SELECT count(btID) FROM Blocks WHERE btID = ?\"",
",",
"array",
"(",
"$",
"this",
"->",
"btID",
")",
")",
";",
"}",
"return",
"$",
"count",
";",
"}"
] | Returns the number of unique instances of this block throughout the entire site
note - this count could include blocks in areas that are no longer rendered by the theme.
@param bool specify true if you only want to see the number of blocks in active pages
@return int | [
"Returns",
"the",
"number",
"of",
"unique",
"instances",
"of",
"this",
"block",
"throughout",
"the",
"entire",
"site",
"note",
"-",
"this",
"count",
"could",
"include",
"blocks",
"in",
"areas",
"that",
"are",
"no",
"longer",
"rendered",
"by",
"the",
"theme",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L367-L393 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.getBlockTypeCustomTemplates | public function getBlockTypeCustomTemplates(Block $b)
{
$btHandle = $this->getBlockTypeHandle();
$fh = Loader::helper('file');
$files = array();
$dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
// Next, check the current theme.
$c = $b->getBlockCollectionObject();
if (is_object($c)) {
$theme = $c->getCollectionThemeObject();
if (is_object($theme)) {
$dir = DIR_FILES_THEMES . "/" . $theme->getThemeHandle() . "/" . DIRNAME_BLOCKS . "/" . $btHandle . "/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
if ($theme->getPackageHandle()) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $theme->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $theme->getPackageHandle() . '/' . DIRNAME_THEMES . '/' . $theme->getThemeHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_THEMES_CORE . "/" . $theme->getThemeHandle() . "/" . DIRNAME_BLOCKS . "/" . $btHandle . "/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
}
// NOW, we check to see if this btHandle has any custom templates that have been installed as separate packages
foreach (PackageList::get()->getPackages() as $pkg) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
$templates = array();
foreach (array_unique($files) as $file) {
$templates[] = new TemplateFile($this, $file);
}
return TemplateFile::sortTemplateFileList($templates);
} | php | public function getBlockTypeCustomTemplates(Block $b)
{
$btHandle = $this->getBlockTypeHandle();
$fh = Loader::helper('file');
$files = array();
$dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
// Next, check the current theme.
$c = $b->getBlockCollectionObject();
if (is_object($c)) {
$theme = $c->getCollectionThemeObject();
if (is_object($theme)) {
$dir = DIR_FILES_THEMES . "/" . $theme->getThemeHandle() . "/" . DIRNAME_BLOCKS . "/" . $btHandle . "/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
if ($theme->getPackageHandle()) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $theme->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $theme->getPackageHandle() . '/' . DIRNAME_THEMES . '/' . $theme->getThemeHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_THEMES_CORE . "/" . $theme->getThemeHandle() . "/" . DIRNAME_BLOCKS . "/" . $btHandle . "/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
}
// NOW, we check to see if this btHandle has any custom templates that have been installed as separate packages
foreach (PackageList::get()->getPackages() as $pkg) {
$dir =
(is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
. '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
}
$dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES;
if (is_dir($dir)) {
$files = array_merge($files, $fh->getDirectoryContents($dir));
}
$templates = array();
foreach (array_unique($files) as $file) {
$templates[] = new TemplateFile($this, $file);
}
return TemplateFile::sortTemplateFileList($templates);
} | [
"public",
"function",
"getBlockTypeCustomTemplates",
"(",
"Block",
"$",
"b",
")",
"{",
"$",
"btHandle",
"=",
"$",
"this",
"->",
"getBlockTypeHandle",
"(",
")",
";",
"$",
"fh",
"=",
"Loader",
"::",
"helper",
"(",
"'file'",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"DIR_FILES_BLOCK_TYPES",
".",
"\"/{$btHandle}/\"",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"// Next, check the current theme.",
"$",
"c",
"=",
"$",
"b",
"->",
"getBlockCollectionObject",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"c",
")",
")",
"{",
"$",
"theme",
"=",
"$",
"c",
"->",
"getCollectionThemeObject",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"theme",
")",
")",
"{",
"$",
"dir",
"=",
"DIR_FILES_THEMES",
".",
"\"/\"",
".",
"$",
"theme",
"->",
"getThemeHandle",
"(",
")",
".",
"\"/\"",
".",
"DIRNAME_BLOCKS",
".",
"\"/\"",
".",
"$",
"btHandle",
".",
"\"/\"",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"if",
"(",
"$",
"theme",
"->",
"getPackageHandle",
"(",
")",
")",
"{",
"$",
"dir",
"=",
"(",
"is_dir",
"(",
"DIR_PACKAGES",
".",
"'/'",
".",
"$",
"theme",
"->",
"getPackageHandle",
"(",
")",
")",
"?",
"DIR_PACKAGES",
":",
"DIR_PACKAGES_CORE",
")",
".",
"'/'",
".",
"$",
"theme",
"->",
"getPackageHandle",
"(",
")",
".",
"'/'",
".",
"DIRNAME_THEMES",
".",
"'/'",
".",
"$",
"theme",
"->",
"getThemeHandle",
"(",
")",
".",
"'/'",
".",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"btHandle",
".",
"'/'",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"}",
"$",
"dir",
"=",
"DIR_FILES_THEMES_CORE",
".",
"\"/\"",
".",
"$",
"theme",
"->",
"getThemeHandle",
"(",
")",
".",
"\"/\"",
".",
"DIRNAME_BLOCKS",
".",
"\"/\"",
".",
"$",
"btHandle",
".",
"\"/\"",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"}",
"}",
"// NOW, we check to see if this btHandle has any custom templates that have been installed as separate packages",
"foreach",
"(",
"PackageList",
"::",
"get",
"(",
")",
"->",
"getPackages",
"(",
")",
"as",
"$",
"pkg",
")",
"{",
"$",
"dir",
"=",
"(",
"is_dir",
"(",
"DIR_PACKAGES",
".",
"'/'",
".",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
")",
"?",
"DIR_PACKAGES",
":",
"DIR_PACKAGES_CORE",
")",
".",
"'/'",
".",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
".",
"'/'",
".",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"btHandle",
".",
"'/'",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"}",
"$",
"dir",
"=",
"DIR_FILES_BLOCK_TYPES_CORE",
".",
"\"/{$btHandle}/\"",
".",
"DIRNAME_BLOCK_TEMPLATES",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
")",
")",
";",
"}",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_unique",
"(",
"$",
"files",
")",
"as",
"$",
"file",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"new",
"TemplateFile",
"(",
"$",
"this",
",",
"$",
"file",
")",
";",
"}",
"return",
"TemplateFile",
"::",
"sortTemplateFileList",
"(",
"$",
"templates",
")",
";",
"}"
] | Gets the custom templates available for the current BlockType.
@return TemplateFile[] | [
"Gets",
"the",
"custom",
"templates",
"available",
"for",
"the",
"current",
"BlockType",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L441-L495 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.refresh | public function refresh()
{
$app = Facade::getFacadeApplication();
$db = $app->make('database')->connection();
$pkgHandle = false;
if ($this->pkgID > 0) {
$pkgHandle = $this->getPackageHandle();
}
$class = \Concrete\Core\Block\BlockType\BlockType::getBlockTypeMappedClass($this->btHandle, $pkgHandle);
$bta = $app->build($class);
$this->loadFromController($bta);
$em = \ORM::entityManager();
$em->persist($this);
$em->flush();
$env = Environment::get();
$r = $env->getRecord(DIRNAME_BLOCKS . '/' . $this->btHandle . '/' . FILENAME_BLOCK_DB, $this->getPackageHandle());
if ($r->exists()) {
$parser = Schema::getSchemaParser(simplexml_load_file($r->file));
$parser->setIgnoreExistingTables(false);
$toSchema = $parser->parse($db);
$fromSchema = $db->getSchemaManager()->createSchema();
$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
$saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform());
foreach ($saveQueries as $query) {
$db->query($query);
}
}
} | php | public function refresh()
{
$app = Facade::getFacadeApplication();
$db = $app->make('database')->connection();
$pkgHandle = false;
if ($this->pkgID > 0) {
$pkgHandle = $this->getPackageHandle();
}
$class = \Concrete\Core\Block\BlockType\BlockType::getBlockTypeMappedClass($this->btHandle, $pkgHandle);
$bta = $app->build($class);
$this->loadFromController($bta);
$em = \ORM::entityManager();
$em->persist($this);
$em->flush();
$env = Environment::get();
$r = $env->getRecord(DIRNAME_BLOCKS . '/' . $this->btHandle . '/' . FILENAME_BLOCK_DB, $this->getPackageHandle());
if ($r->exists()) {
$parser = Schema::getSchemaParser(simplexml_load_file($r->file));
$parser->setIgnoreExistingTables(false);
$toSchema = $parser->parse($db);
$fromSchema = $db->getSchemaManager()->createSchema();
$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
$saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform());
foreach ($saveQueries as $query) {
$db->query($query);
}
}
} | [
"public",
"function",
"refresh",
"(",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"db",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"pkgHandle",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"pkgID",
">",
"0",
")",
"{",
"$",
"pkgHandle",
"=",
"$",
"this",
"->",
"getPackageHandle",
"(",
")",
";",
"}",
"$",
"class",
"=",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Block",
"\\",
"BlockType",
"\\",
"BlockType",
"::",
"getBlockTypeMappedClass",
"(",
"$",
"this",
"->",
"btHandle",
",",
"$",
"pkgHandle",
")",
";",
"$",
"bta",
"=",
"$",
"app",
"->",
"build",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"loadFromController",
"(",
"$",
"bta",
")",
";",
"$",
"em",
"=",
"\\",
"ORM",
"::",
"entityManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"this",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"env",
"=",
"Environment",
"::",
"get",
"(",
")",
";",
"$",
"r",
"=",
"$",
"env",
"->",
"getRecord",
"(",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"this",
"->",
"btHandle",
".",
"'/'",
".",
"FILENAME_BLOCK_DB",
",",
"$",
"this",
"->",
"getPackageHandle",
"(",
")",
")",
";",
"if",
"(",
"$",
"r",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"parser",
"=",
"Schema",
"::",
"getSchemaParser",
"(",
"simplexml_load_file",
"(",
"$",
"r",
"->",
"file",
")",
")",
";",
"$",
"parser",
"->",
"setIgnoreExistingTables",
"(",
"false",
")",
";",
"$",
"toSchema",
"=",
"$",
"parser",
"->",
"parse",
"(",
"$",
"db",
")",
";",
"$",
"fromSchema",
"=",
"$",
"db",
"->",
"getSchemaManager",
"(",
")",
"->",
"createSchema",
"(",
")",
";",
"$",
"comparator",
"=",
"new",
"\\",
"Doctrine",
"\\",
"DBAL",
"\\",
"Schema",
"\\",
"Comparator",
"(",
")",
";",
"$",
"schemaDiff",
"=",
"$",
"comparator",
"->",
"compare",
"(",
"$",
"fromSchema",
",",
"$",
"toSchema",
")",
";",
"$",
"saveQueries",
"=",
"$",
"schemaDiff",
"->",
"toSaveSql",
"(",
"$",
"db",
"->",
"getDatabasePlatform",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"saveQueries",
"as",
"$",
"query",
")",
"{",
"$",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"}",
"}",
"}"
] | refreshes the BlockType's database schema throws an Exception if error. | [
"refreshes",
"the",
"BlockType",
"s",
"database",
"schema",
"throws",
"an",
"Exception",
"if",
"error",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L539-L572 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.delete | public function delete()
{
$db = Loader::db();
$r = $db->Execute(
'select cID, cvID, b.bID, arHandle
from CollectionVersionBlocks cvb
inner join Blocks b on b.bID = cvb.bID
where btID = ?
union
select cID, cvID, cvb.bID, arHandle
from CollectionVersionBlocks cvb
inner join btCoreScrapbookDisplay btCSD on cvb.bID = btCSD.bID
inner join Blocks b on b.bID = btCSD.bOriginalID
where btID = ?',
array($this->getBlockTypeID(), $this->getBlockTypeID()));
while ($row = $r->FetchRow()) {
$nc = Page::getByID($row['cID'], $row['cvID']);
if (!is_object($nc) || $nc->isError()) {
continue;
}
$b = Block::getByID($row['bID'], $nc, $row['arHandle']);
if (is_object($b)) {
$b->deleteBlock();
}
}
$em = \ORM::entityManager();
$em->remove($this);
$em->flush();
//Remove gaps in display order numbering (to avoid future sorting errors)
BlockTypeList::resetBlockTypeDisplayOrder('btDisplayOrder');
} | php | public function delete()
{
$db = Loader::db();
$r = $db->Execute(
'select cID, cvID, b.bID, arHandle
from CollectionVersionBlocks cvb
inner join Blocks b on b.bID = cvb.bID
where btID = ?
union
select cID, cvID, cvb.bID, arHandle
from CollectionVersionBlocks cvb
inner join btCoreScrapbookDisplay btCSD on cvb.bID = btCSD.bID
inner join Blocks b on b.bID = btCSD.bOriginalID
where btID = ?',
array($this->getBlockTypeID(), $this->getBlockTypeID()));
while ($row = $r->FetchRow()) {
$nc = Page::getByID($row['cID'], $row['cvID']);
if (!is_object($nc) || $nc->isError()) {
continue;
}
$b = Block::getByID($row['bID'], $nc, $row['arHandle']);
if (is_object($b)) {
$b->deleteBlock();
}
}
$em = \ORM::entityManager();
$em->remove($this);
$em->flush();
//Remove gaps in display order numbering (to avoid future sorting errors)
BlockTypeList::resetBlockTypeDisplayOrder('btDisplayOrder');
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"Execute",
"(",
"'select cID, cvID, b.bID, arHandle\n from CollectionVersionBlocks cvb\n inner join Blocks b on b.bID = cvb.bID\n where btID = ?\n union\n select cID, cvID, cvb.bID, arHandle\n from CollectionVersionBlocks cvb\n inner join btCoreScrapbookDisplay btCSD on cvb.bID = btCSD.bID\n inner join Blocks b on b.bID = btCSD.bOriginalID\n where btID = ?'",
",",
"array",
"(",
"$",
"this",
"->",
"getBlockTypeID",
"(",
")",
",",
"$",
"this",
"->",
"getBlockTypeID",
"(",
")",
")",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"r",
"->",
"FetchRow",
"(",
")",
")",
"{",
"$",
"nc",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'cID'",
"]",
",",
"$",
"row",
"[",
"'cvID'",
"]",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"nc",
")",
"||",
"$",
"nc",
"->",
"isError",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"b",
"=",
"Block",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'bID'",
"]",
",",
"$",
"nc",
",",
"$",
"row",
"[",
"'arHandle'",
"]",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"b",
")",
")",
"{",
"$",
"b",
"->",
"deleteBlock",
"(",
")",
";",
"}",
"}",
"$",
"em",
"=",
"\\",
"ORM",
"::",
"entityManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"this",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"//Remove gaps in display order numbering (to avoid future sorting errors)",
"BlockTypeList",
"::",
"resetBlockTypeDisplayOrder",
"(",
"'btDisplayOrder'",
")",
";",
"}"
] | Removes the block type. Also removes instances of content. | [
"Removes",
"the",
"block",
"type",
".",
"Also",
"removes",
"instances",
"of",
"content",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L591-L623 | train |
concrete5/concrete5 | concrete/src/Entity/Block/BlockType/BlockType.php | BlockType.add | public function add($data, $c = false, $a = false)
{
$app = Facade::getFacadeApplication();
$db = $app->make('database')->connection();
$u = new User();
if (isset($data['uID'])) {
$uID = $data['uID'];
} else {
$uID = $u->getUserID();
}
$bName = '';
if (isset($data['bName'])) {
$bName = $data['bName'];
}
$btID = $this->btID;
$dh = $app->make('helper/date');
$bDate = $dh->getOverridableNow();
$bIsActive = (isset($this->btActiveWhenAdded) && $this->btActiveWhenAdded == 1) ? 1 : 0;
$v = array($bName, $bDate, $bDate, $bIsActive, $btID, $uID);
$q = "insert into Blocks (bName, bDateAdded, bDateModified, bIsActive, btID, uID) values (?, ?, ?, ?, ?, ?)";
$res = $db->executeQuery($q, $v);
// we get the block object for the block we just added
if ($res) {
$bIDnew = $db->lastInsertId();
$nb = Block::getByID($bIDnew);
if (is_object($c)) {
$nb->setBlockCollectionObject($c);
}
if (is_object($a)) {
$nb->setBlockAreaObject($a);
}
$class = $this->getBlockTypeClass();
$bc = $app->build($class, [$nb]);
$bc->save($data);
return Block::getByID($bIDnew);
}
} | php | public function add($data, $c = false, $a = false)
{
$app = Facade::getFacadeApplication();
$db = $app->make('database')->connection();
$u = new User();
if (isset($data['uID'])) {
$uID = $data['uID'];
} else {
$uID = $u->getUserID();
}
$bName = '';
if (isset($data['bName'])) {
$bName = $data['bName'];
}
$btID = $this->btID;
$dh = $app->make('helper/date');
$bDate = $dh->getOverridableNow();
$bIsActive = (isset($this->btActiveWhenAdded) && $this->btActiveWhenAdded == 1) ? 1 : 0;
$v = array($bName, $bDate, $bDate, $bIsActive, $btID, $uID);
$q = "insert into Blocks (bName, bDateAdded, bDateModified, bIsActive, btID, uID) values (?, ?, ?, ?, ?, ?)";
$res = $db->executeQuery($q, $v);
// we get the block object for the block we just added
if ($res) {
$bIDnew = $db->lastInsertId();
$nb = Block::getByID($bIDnew);
if (is_object($c)) {
$nb->setBlockCollectionObject($c);
}
if (is_object($a)) {
$nb->setBlockAreaObject($a);
}
$class = $this->getBlockTypeClass();
$bc = $app->build($class, [$nb]);
$bc->save($data);
return Block::getByID($bIDnew);
}
} | [
"public",
"function",
"add",
"(",
"$",
"data",
",",
"$",
"c",
"=",
"false",
",",
"$",
"a",
"=",
"false",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"db",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'uID'",
"]",
")",
")",
"{",
"$",
"uID",
"=",
"$",
"data",
"[",
"'uID'",
"]",
";",
"}",
"else",
"{",
"$",
"uID",
"=",
"$",
"u",
"->",
"getUserID",
"(",
")",
";",
"}",
"$",
"bName",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'bName'",
"]",
")",
")",
"{",
"$",
"bName",
"=",
"$",
"data",
"[",
"'bName'",
"]",
";",
"}",
"$",
"btID",
"=",
"$",
"this",
"->",
"btID",
";",
"$",
"dh",
"=",
"$",
"app",
"->",
"make",
"(",
"'helper/date'",
")",
";",
"$",
"bDate",
"=",
"$",
"dh",
"->",
"getOverridableNow",
"(",
")",
";",
"$",
"bIsActive",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"btActiveWhenAdded",
")",
"&&",
"$",
"this",
"->",
"btActiveWhenAdded",
"==",
"1",
")",
"?",
"1",
":",
"0",
";",
"$",
"v",
"=",
"array",
"(",
"$",
"bName",
",",
"$",
"bDate",
",",
"$",
"bDate",
",",
"$",
"bIsActive",
",",
"$",
"btID",
",",
"$",
"uID",
")",
";",
"$",
"q",
"=",
"\"insert into Blocks (bName, bDateAdded, bDateModified, bIsActive, btID, uID) values (?, ?, ?, ?, ?, ?)\"",
";",
"$",
"res",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"$",
"q",
",",
"$",
"v",
")",
";",
"// we get the block object for the block we just added",
"if",
"(",
"$",
"res",
")",
"{",
"$",
"bIDnew",
"=",
"$",
"db",
"->",
"lastInsertId",
"(",
")",
";",
"$",
"nb",
"=",
"Block",
"::",
"getByID",
"(",
"$",
"bIDnew",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"c",
")",
")",
"{",
"$",
"nb",
"->",
"setBlockCollectionObject",
"(",
"$",
"c",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"a",
")",
")",
"{",
"$",
"nb",
"->",
"setBlockAreaObject",
"(",
"$",
"a",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getBlockTypeClass",
"(",
")",
";",
"$",
"bc",
"=",
"$",
"app",
"->",
"build",
"(",
"$",
"class",
",",
"[",
"$",
"nb",
"]",
")",
";",
"$",
"bc",
"->",
"save",
"(",
"$",
"data",
")",
";",
"return",
"Block",
"::",
"getByID",
"(",
"$",
"bIDnew",
")",
";",
"}",
"}"
] | Adds a block to the system without adding it to a collection.
Passes page and area data along if it is available, however.
@param mixed $data
@param bool|\Collection $c
@param bool|\Area $a
@return bool|\Concrete\Core\Block\Block | [
"Adds",
"a",
"block",
"to",
"the",
"system",
"without",
"adding",
"it",
"to",
"a",
"collection",
".",
"Passes",
"page",
"and",
"area",
"data",
"along",
"if",
"it",
"is",
"available",
"however",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Block/BlockType/BlockType.php#L635-L678 | train |
concrete5/concrete5 | concrete/src/Http/ResponseAssetGroup.php | ResponseAssetGroup.addOutputAssetAt | protected function addOutputAssetAt($item, $position)
{
if (!isset($this->outputAssets[$position])) {
$this->outputAssets[$position] = [$item];
} elseif (!in_array($item, $this->outputAssets[$position])) {
$this->outputAssets[$position][] = $item;
}
} | php | protected function addOutputAssetAt($item, $position)
{
if (!isset($this->outputAssets[$position])) {
$this->outputAssets[$position] = [$item];
} elseif (!in_array($item, $this->outputAssets[$position])) {
$this->outputAssets[$position][] = $item;
}
} | [
"protected",
"function",
"addOutputAssetAt",
"(",
"$",
"item",
",",
"$",
"position",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"outputAssets",
"[",
"$",
"position",
"]",
")",
")",
"{",
"$",
"this",
"->",
"outputAssets",
"[",
"$",
"position",
"]",
"=",
"[",
"$",
"item",
"]",
";",
"}",
"elseif",
"(",
"!",
"in_array",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"outputAssets",
"[",
"$",
"position",
"]",
")",
")",
"{",
"$",
"this",
"->",
"outputAssets",
"[",
"$",
"position",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}"
] | Add an asset at a specific position.
@param \Concrete\Core\Asset\Asset $item
@param string $position Whether the asset should be loaded in the header or in the footer.
@see \Concrete\Core\Asset\AssetInterface::ASSET_POSITION_HEADER
@see \Concrete\Core\Asset\AssetInterface::ASSET_POSITION_FOOTER | [
"Add",
"an",
"asset",
"at",
"a",
"specific",
"position",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/ResponseAssetGroup.php#L92-L99 | train |
concrete5/concrete5 | concrete/src/Http/ResponseAssetGroup.php | ResponseAssetGroup.getAssetsToOutput | public function getAssetsToOutput()
{
$assets = $this->getRequiredAssetsToOutput();
foreach ($assets as $asset) {
$this->addOutputAsset($asset);
}
$outputAssetsPre = array();
$outputAssets = array();
// now we create temporary objects to store assets and their original key.
// Why? Because not all "assets" in here are instances of the Asset class. Sometimes they're just strings.
foreach ($this->outputAssets as $position => $assets) {
$outputAssetsPre[$position] = array();
foreach ($assets as $key => $asset) {
$o = new \stdClass();
$o->key = $key;
$o->asset = $asset;
$outputAssetsPre[$position][] = $o;
}
}
// now we iterate through the $outputAssetsPre array, maintaining position, and sorting all the stdClass
// objects within each array, keeping non-post-processed items first, and sorting by key.
foreach ($outputAssetsPre as $position => $assets) {
usort($assets, function ($o1, $o2) {
$a1 = $o1->asset;
$a2 = $o2->asset;
$k1 = $o1->key;
$k2 = $o2->key;
// This is a great idea but it's not working. We're going to ditch this attempt at
// intelligent grouping and just sort strictly by key.
if ($k1 > $k2) {
return 1;
} elseif ($k1 < $k2) {
return -1;
} else {
return 0;
}
/*
// o1 not an asset, o2 not an asset
if ((!($a1 instanceof Asset)) && (!($a2 instanceof Asset))) {
return sortByKey($k1, $k2);
}
// o1 an asset, doesn't support post processing, o2 not an asset
if ($a1 instanceof Asset && (!$a1->assetSupportsPostProcessing()) && (!($a2 instanceof Asset))) {
return -1; // always come before post processing.
}
// o1 an asset, supports post processing, o2 not an asset
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && (!($a2 instanceof Asset))) {
return 1; // asset 1 must ALWAYS come after asset 2
}
// o1 not an asset, o2 an asset, doesn't support post processing
if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {
return -1; // always come before post processing.
}
// o1 an asset, doesn't support post processing, o2 an asset, doesn't support post processing
if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && !$a2->assetSupportsPostProcessing()) {
return sortByKey($k1, $k2);
}
// o1 an asset, supports post processing, o2 an asset, doesn't support post processing
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {
return 1; // asset 1 must ALWAYS come after asset 2
}
// o1 not an asset, o2 an asset, supports post processing
if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && ($a2->assetSupportsPostProcessing())) {
return sortByKey($k1, $k2);
}
// o1 an asset, doesn't support post processing, o2 an asset, supports post processing
if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {
return -1;
}
// o1 an asset, supports post processing, o2 an asset, supports post processing
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {
return sortByKey($k1, $k2);
}
*/
});
foreach ($assets as $object) {
$outputAssets[$position][] = $object->asset;
}
}
return $outputAssets;
} | php | public function getAssetsToOutput()
{
$assets = $this->getRequiredAssetsToOutput();
foreach ($assets as $asset) {
$this->addOutputAsset($asset);
}
$outputAssetsPre = array();
$outputAssets = array();
// now we create temporary objects to store assets and their original key.
// Why? Because not all "assets" in here are instances of the Asset class. Sometimes they're just strings.
foreach ($this->outputAssets as $position => $assets) {
$outputAssetsPre[$position] = array();
foreach ($assets as $key => $asset) {
$o = new \stdClass();
$o->key = $key;
$o->asset = $asset;
$outputAssetsPre[$position][] = $o;
}
}
// now we iterate through the $outputAssetsPre array, maintaining position, and sorting all the stdClass
// objects within each array, keeping non-post-processed items first, and sorting by key.
foreach ($outputAssetsPre as $position => $assets) {
usort($assets, function ($o1, $o2) {
$a1 = $o1->asset;
$a2 = $o2->asset;
$k1 = $o1->key;
$k2 = $o2->key;
// This is a great idea but it's not working. We're going to ditch this attempt at
// intelligent grouping and just sort strictly by key.
if ($k1 > $k2) {
return 1;
} elseif ($k1 < $k2) {
return -1;
} else {
return 0;
}
/*
// o1 not an asset, o2 not an asset
if ((!($a1 instanceof Asset)) && (!($a2 instanceof Asset))) {
return sortByKey($k1, $k2);
}
// o1 an asset, doesn't support post processing, o2 not an asset
if ($a1 instanceof Asset && (!$a1->assetSupportsPostProcessing()) && (!($a2 instanceof Asset))) {
return -1; // always come before post processing.
}
// o1 an asset, supports post processing, o2 not an asset
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && (!($a2 instanceof Asset))) {
return 1; // asset 1 must ALWAYS come after asset 2
}
// o1 not an asset, o2 an asset, doesn't support post processing
if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {
return -1; // always come before post processing.
}
// o1 an asset, doesn't support post processing, o2 an asset, doesn't support post processing
if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && !$a2->assetSupportsPostProcessing()) {
return sortByKey($k1, $k2);
}
// o1 an asset, supports post processing, o2 an asset, doesn't support post processing
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {
return 1; // asset 1 must ALWAYS come after asset 2
}
// o1 not an asset, o2 an asset, supports post processing
if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && ($a2->assetSupportsPostProcessing())) {
return sortByKey($k1, $k2);
}
// o1 an asset, doesn't support post processing, o2 an asset, supports post processing
if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {
return -1;
}
// o1 an asset, supports post processing, o2 an asset, supports post processing
if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {
return sortByKey($k1, $k2);
}
*/
});
foreach ($assets as $object) {
$outputAssets[$position][] = $object->asset;
}
}
return $outputAssets;
} | [
"public",
"function",
"getAssetsToOutput",
"(",
")",
"{",
"$",
"assets",
"=",
"$",
"this",
"->",
"getRequiredAssetsToOutput",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"this",
"->",
"addOutputAsset",
"(",
"$",
"asset",
")",
";",
"}",
"$",
"outputAssetsPre",
"=",
"array",
"(",
")",
";",
"$",
"outputAssets",
"=",
"array",
"(",
")",
";",
"// now we create temporary objects to store assets and their original key.",
"// Why? Because not all \"assets\" in here are instances of the Asset class. Sometimes they're just strings.",
"foreach",
"(",
"$",
"this",
"->",
"outputAssets",
"as",
"$",
"position",
"=>",
"$",
"assets",
")",
"{",
"$",
"outputAssetsPre",
"[",
"$",
"position",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"key",
"=>",
"$",
"asset",
")",
"{",
"$",
"o",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"o",
"->",
"key",
"=",
"$",
"key",
";",
"$",
"o",
"->",
"asset",
"=",
"$",
"asset",
";",
"$",
"outputAssetsPre",
"[",
"$",
"position",
"]",
"[",
"]",
"=",
"$",
"o",
";",
"}",
"}",
"// now we iterate through the $outputAssetsPre array, maintaining position, and sorting all the stdClass",
"// objects within each array, keeping non-post-processed items first, and sorting by key.",
"foreach",
"(",
"$",
"outputAssetsPre",
"as",
"$",
"position",
"=>",
"$",
"assets",
")",
"{",
"usort",
"(",
"$",
"assets",
",",
"function",
"(",
"$",
"o1",
",",
"$",
"o2",
")",
"{",
"$",
"a1",
"=",
"$",
"o1",
"->",
"asset",
";",
"$",
"a2",
"=",
"$",
"o2",
"->",
"asset",
";",
"$",
"k1",
"=",
"$",
"o1",
"->",
"key",
";",
"$",
"k2",
"=",
"$",
"o2",
"->",
"key",
";",
"// This is a great idea but it's not working. We're going to ditch this attempt at",
"// intelligent grouping and just sort strictly by key.",
"if",
"(",
"$",
"k1",
">",
"$",
"k2",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"k1",
"<",
"$",
"k2",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"/*\n // o1 not an asset, o2 not an asset\n if ((!($a1 instanceof Asset)) && (!($a2 instanceof Asset))) {\n return sortByKey($k1, $k2);\n }\n\n // o1 an asset, doesn't support post processing, o2 not an asset\n if ($a1 instanceof Asset && (!$a1->assetSupportsPostProcessing()) && (!($a2 instanceof Asset))) {\n return -1; // always come before post processing.\n }\n\n // o1 an asset, supports post processing, o2 not an asset\n if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && (!($a2 instanceof Asset))) {\n return 1; // asset 1 must ALWAYS come after asset 2\n }\n\n // o1 not an asset, o2 an asset, doesn't support post processing\n if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {\n return -1; // always come before post processing.\n }\n\n // o1 an asset, doesn't support post processing, o2 an asset, doesn't support post processing\n if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && !$a2->assetSupportsPostProcessing()) {\n return sortByKey($k1, $k2);\n }\n\n // o1 an asset, supports post processing, o2 an asset, doesn't support post processing\n if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && (!$a2->assetSupportsPostProcessing())) {\n return 1; // asset 1 must ALWAYS come after asset 2\n }\n\n // o1 not an asset, o2 an asset, supports post processing\n if ((!($a1 instanceof Asset)) && $a2 instanceof Asset && ($a2->assetSupportsPostProcessing())) {\n return sortByKey($k1, $k2);\n }\n\n // o1 an asset, doesn't support post processing, o2 an asset, supports post processing\n if ($a1 instanceof Asset && !$a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {\n return -1;\n }\n\n // o1 an asset, supports post processing, o2 an asset, supports post processing\n if ($a1 instanceof Asset && $a1->assetSupportsPostProcessing() && $a2 instanceof Asset && $a2->assetSupportsPostProcessing()) {\n return sortByKey($k1, $k2);\n }\n */",
"}",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"object",
")",
"{",
"$",
"outputAssets",
"[",
"$",
"position",
"]",
"[",
"]",
"=",
"$",
"object",
"->",
"asset",
";",
"}",
"}",
"return",
"$",
"outputAssets",
";",
"}"
] | Get a list of assets that need to be outputted.
Responsible for a number of things:
1. Gets the required assets and adds them to the output assets array (which also contains other assets we have specifically asked for.)
2. Returns the assets with the non-post-process-able assets FIRST, in the order in which they were added, with post-processable assets
grouped after. We also make sure to maintain the proper position.
@return array[
'H' => \Concrete\Core\Asset\Asset[]
'F' => \Concrete\Core\Asset\Asset[]
] | [
"Get",
"a",
"list",
"of",
"assets",
"that",
"need",
"to",
"be",
"outputted",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/ResponseAssetGroup.php#L114-L210 | train |
concrete5/concrete5 | concrete/src/Http/ResponseAssetGroup.php | ResponseAssetGroup.markAssetAsIncluded | public function markAssetAsIncluded($assetType, $assetHandle = false)
{
$list = AssetList::getInstance();
if ($assetType && $assetHandle) {
$asset = $list->getAsset($assetType, $assetHandle);
} else {
$assetGroup = $list->getAssetGroup($assetType);
}
if (isset($assetGroup)) {
$this->providedAssetGroup->addGroup($assetGroup);
} elseif (isset($asset)) {
$ap = new AssetPointer($asset->getAssetType(), $asset->getAssetHandle());
$this->providedAssetGroup->add($ap);
} else {
$ap = new AssetPointer($assetType, $assetHandle);
$this->providedAssetGroupUnmatched[] = $ap;
}
} | php | public function markAssetAsIncluded($assetType, $assetHandle = false)
{
$list = AssetList::getInstance();
if ($assetType && $assetHandle) {
$asset = $list->getAsset($assetType, $assetHandle);
} else {
$assetGroup = $list->getAssetGroup($assetType);
}
if (isset($assetGroup)) {
$this->providedAssetGroup->addGroup($assetGroup);
} elseif (isset($asset)) {
$ap = new AssetPointer($asset->getAssetType(), $asset->getAssetHandle());
$this->providedAssetGroup->add($ap);
} else {
$ap = new AssetPointer($assetType, $assetHandle);
$this->providedAssetGroupUnmatched[] = $ap;
}
} | [
"public",
"function",
"markAssetAsIncluded",
"(",
"$",
"assetType",
",",
"$",
"assetHandle",
"=",
"false",
")",
"{",
"$",
"list",
"=",
"AssetList",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"$",
"assetType",
"&&",
"$",
"assetHandle",
")",
"{",
"$",
"asset",
"=",
"$",
"list",
"->",
"getAsset",
"(",
"$",
"assetType",
",",
"$",
"assetHandle",
")",
";",
"}",
"else",
"{",
"$",
"assetGroup",
"=",
"$",
"list",
"->",
"getAssetGroup",
"(",
"$",
"assetType",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"assetGroup",
")",
")",
"{",
"$",
"this",
"->",
"providedAssetGroup",
"->",
"addGroup",
"(",
"$",
"assetGroup",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"asset",
")",
")",
"{",
"$",
"ap",
"=",
"new",
"AssetPointer",
"(",
"$",
"asset",
"->",
"getAssetType",
"(",
")",
",",
"$",
"asset",
"->",
"getAssetHandle",
"(",
")",
")",
";",
"$",
"this",
"->",
"providedAssetGroup",
"->",
"add",
"(",
"$",
"ap",
")",
";",
"}",
"else",
"{",
"$",
"ap",
"=",
"new",
"AssetPointer",
"(",
"$",
"assetType",
",",
"$",
"assetHandle",
")",
";",
"$",
"this",
"->",
"providedAssetGroupUnmatched",
"[",
"]",
"=",
"$",
"ap",
";",
"}",
"}"
] | Notes in the current request that a particular asset has already been provided.
@param string $assetType E.g. 'css' or 'javascript'.
@param string|false $assetHandle E.g. 'core/colorpicker'. | [
"Notes",
"in",
"the",
"current",
"request",
"that",
"a",
"particular",
"asset",
"has",
"already",
"been",
"provided",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/ResponseAssetGroup.php#L218-L236 | train |
concrete5/concrete5 | concrete/src/Http/ResponseAssetGroup.php | ResponseAssetGroup.getRequiredAssetsToOutput | public function getRequiredAssetsToOutput()
{
$required = $this->requiredAssetGroup->getAssetPointers();
$assetPointers = array_filter($required, array('\Concrete\Core\Http\ResponseAssetGroup', 'filterProvidedAssets'));
$assets = array();
$al = AssetList::getInstance();
foreach ($assetPointers as $ap) {
$asset = $ap->getAsset();
if ($asset instanceof Asset) {
$assets[] = $asset;
}
}
// also include any hard-passed $assets into the group. This is rare but it's used for handle-less
// assets like layout css
$assets = array_merge($this->requiredAssetGroup->getAssets(), $assets);
return $assets;
} | php | public function getRequiredAssetsToOutput()
{
$required = $this->requiredAssetGroup->getAssetPointers();
$assetPointers = array_filter($required, array('\Concrete\Core\Http\ResponseAssetGroup', 'filterProvidedAssets'));
$assets = array();
$al = AssetList::getInstance();
foreach ($assetPointers as $ap) {
$asset = $ap->getAsset();
if ($asset instanceof Asset) {
$assets[] = $asset;
}
}
// also include any hard-passed $assets into the group. This is rare but it's used for handle-less
// assets like layout css
$assets = array_merge($this->requiredAssetGroup->getAssets(), $assets);
return $assets;
} | [
"public",
"function",
"getRequiredAssetsToOutput",
"(",
")",
"{",
"$",
"required",
"=",
"$",
"this",
"->",
"requiredAssetGroup",
"->",
"getAssetPointers",
"(",
")",
";",
"$",
"assetPointers",
"=",
"array_filter",
"(",
"$",
"required",
",",
"array",
"(",
"'\\Concrete\\Core\\Http\\ResponseAssetGroup'",
",",
"'filterProvidedAssets'",
")",
")",
";",
"$",
"assets",
"=",
"array",
"(",
")",
";",
"$",
"al",
"=",
"AssetList",
"::",
"getInstance",
"(",
")",
";",
"foreach",
"(",
"$",
"assetPointers",
"as",
"$",
"ap",
")",
"{",
"$",
"asset",
"=",
"$",
"ap",
"->",
"getAsset",
"(",
")",
";",
"if",
"(",
"$",
"asset",
"instanceof",
"Asset",
")",
"{",
"$",
"assets",
"[",
"]",
"=",
"$",
"asset",
";",
"}",
"}",
"// also include any hard-passed $assets into the group. This is rare but it's used for handle-less",
"// assets like layout css",
"$",
"assets",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"requiredAssetGroup",
"->",
"getAssets",
"(",
")",
",",
"$",
"assets",
")",
";",
"return",
"$",
"assets",
";",
"}"
] | Returns only assets that are required but that aren't also in the providedAssetGroup.
@return \Concrete\Core\Asset\Asset[] | [
"Returns",
"only",
"assets",
"that",
"are",
"required",
"but",
"that",
"aren",
"t",
"also",
"in",
"the",
"providedAssetGroup",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/ResponseAssetGroup.php#L304-L321 | train |
concrete5/concrete5 | concrete/src/Attribute/ObjectTrait.php | ObjectTrait.setAttribute | public function setAttribute($ak, $value)
{
$orm = \Database::connection()->getEntityManager();
$this->clearAttribute($ak);
// Create the attribute category value.
$attributeValue = $this->getAttributeValueObject($ak, true);
$orm->persist($attributeValue);
$orm->flush();
// Create the generic value. This gets joined to any specific Attribute value objects later on.
$genericValue = new Value();
$genericValue->setAttributeKey($attributeValue->getAttributeKey());
$orm->persist($genericValue);
$orm->flush();
// Set the generic value to the attribute category value.
$attributeValue->setGenericValue($genericValue);
$orm->persist($attributeValue);
$orm->flush();
$controller = $attributeValue->getAttributeKey()->getController();
$controller->setAttributeValue($attributeValue);
if (!($value instanceof AttributeValue\AbstractValue)) {
if ($value instanceof EmptyRequestAttributeValue) {
// LEGACY SUPPORT
// If the passed $value object == EmptyRequestAttributeValue, we know we are dealing
// with a legacy attribute type that's not using Doctrine. We have not returned an
// attribute value value object.
$controller->saveForm($controller->post());
unset($value);
} else {
/**
* @var $value AttributeValue\AbstractValue
*/
$value = $controller->createAttributeValue($value);
}
}
if ($value) {
$value->setGenericValue($genericValue);
$orm->persist($value);
$orm->flush();
}
$category = $this->getObjectAttributeCategory();
$indexer = $category->getSearchIndexer();
if ($indexer) {
$indexer->indexEntry($category, $attributeValue, $this);
}
return $attributeValue;
} | php | public function setAttribute($ak, $value)
{
$orm = \Database::connection()->getEntityManager();
$this->clearAttribute($ak);
// Create the attribute category value.
$attributeValue = $this->getAttributeValueObject($ak, true);
$orm->persist($attributeValue);
$orm->flush();
// Create the generic value. This gets joined to any specific Attribute value objects later on.
$genericValue = new Value();
$genericValue->setAttributeKey($attributeValue->getAttributeKey());
$orm->persist($genericValue);
$orm->flush();
// Set the generic value to the attribute category value.
$attributeValue->setGenericValue($genericValue);
$orm->persist($attributeValue);
$orm->flush();
$controller = $attributeValue->getAttributeKey()->getController();
$controller->setAttributeValue($attributeValue);
if (!($value instanceof AttributeValue\AbstractValue)) {
if ($value instanceof EmptyRequestAttributeValue) {
// LEGACY SUPPORT
// If the passed $value object == EmptyRequestAttributeValue, we know we are dealing
// with a legacy attribute type that's not using Doctrine. We have not returned an
// attribute value value object.
$controller->saveForm($controller->post());
unset($value);
} else {
/**
* @var $value AttributeValue\AbstractValue
*/
$value = $controller->createAttributeValue($value);
}
}
if ($value) {
$value->setGenericValue($genericValue);
$orm->persist($value);
$orm->flush();
}
$category = $this->getObjectAttributeCategory();
$indexer = $category->getSearchIndexer();
if ($indexer) {
$indexer->indexEntry($category, $attributeValue, $this);
}
return $attributeValue;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"ak",
",",
"$",
"value",
")",
"{",
"$",
"orm",
"=",
"\\",
"Database",
"::",
"connection",
"(",
")",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"this",
"->",
"clearAttribute",
"(",
"$",
"ak",
")",
";",
"// Create the attribute category value.",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"getAttributeValueObject",
"(",
"$",
"ak",
",",
"true",
")",
";",
"$",
"orm",
"->",
"persist",
"(",
"$",
"attributeValue",
")",
";",
"$",
"orm",
"->",
"flush",
"(",
")",
";",
"// Create the generic value. This gets joined to any specific Attribute value objects later on.",
"$",
"genericValue",
"=",
"new",
"Value",
"(",
")",
";",
"$",
"genericValue",
"->",
"setAttributeKey",
"(",
"$",
"attributeValue",
"->",
"getAttributeKey",
"(",
")",
")",
";",
"$",
"orm",
"->",
"persist",
"(",
"$",
"genericValue",
")",
";",
"$",
"orm",
"->",
"flush",
"(",
")",
";",
"// Set the generic value to the attribute category value.",
"$",
"attributeValue",
"->",
"setGenericValue",
"(",
"$",
"genericValue",
")",
";",
"$",
"orm",
"->",
"persist",
"(",
"$",
"attributeValue",
")",
";",
"$",
"orm",
"->",
"flush",
"(",
")",
";",
"$",
"controller",
"=",
"$",
"attributeValue",
"->",
"getAttributeKey",
"(",
")",
"->",
"getController",
"(",
")",
";",
"$",
"controller",
"->",
"setAttributeValue",
"(",
"$",
"attributeValue",
")",
";",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"AttributeValue",
"\\",
"AbstractValue",
")",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"EmptyRequestAttributeValue",
")",
"{",
"// LEGACY SUPPORT",
"// If the passed $value object == EmptyRequestAttributeValue, we know we are dealing",
"// with a legacy attribute type that's not using Doctrine. We have not returned an
",
"// attribute value value object.",
"$",
"controller",
"->",
"saveForm",
"(",
"$",
"controller",
"->",
"post",
"(",
")",
")",
";",
"unset",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"/**\n * @var $value AttributeValue\\AbstractValue\n */",
"$",
"value",
"=",
"$",
"controller",
"->",
"createAttributeValue",
"(",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"->",
"setGenericValue",
"(",
"$",
"genericValue",
")",
";",
"$",
"orm",
"->",
"persist",
"(",
"$",
"value",
")",
";",
"$",
"orm",
"->",
"flush",
"(",
")",
";",
"}",
"$",
"category",
"=",
"$",
"this",
"->",
"getObjectAttributeCategory",
"(",
")",
";",
"$",
"indexer",
"=",
"$",
"category",
"->",
"getSearchIndexer",
"(",
")",
";",
"if",
"(",
"$",
"indexer",
")",
"{",
"$",
"indexer",
"->",
"indexEntry",
"(",
"$",
"category",
",",
"$",
"attributeValue",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"attributeValue",
";",
"}"
] | Sets the attribute of a user info object to the specified value, and saves it in the database.
@param AttributeKeyInterface | string $ak
@param mixed $value
@return \Concrete\Core\Entity\Attribute\Value\Value | [
"Sets",
"the",
"attribute",
"of",
"a",
"user",
"info",
"object",
"to",
"the",
"specified",
"value",
"and",
"saves",
"it",
"in",
"the",
"database",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/ObjectTrait.php#L68-L122 | train |
concrete5/concrete5 | concrete/src/Console/Command/ConfigCommand.php | ConfigCommand.doGetAction | private function doGetAction($repository, $item)
{
$this->output->writeln($this->serialize($repository->get($item)));
} | php | private function doGetAction($repository, $item)
{
$this->output->writeln($this->serialize($repository->get($item)));
} | [
"private",
"function",
"doGetAction",
"(",
"$",
"repository",
",",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"serialize",
"(",
"$",
"repository",
"->",
"get",
"(",
"$",
"item",
")",
")",
")",
";",
"}"
] | Complete a requested get action
@param $repository
@param $item | [
"Complete",
"a",
"requested",
"get",
"action"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command/ConfigCommand.php#L143-L146 | train |
concrete5/concrete5 | concrete/src/Console/Command/ConfigCommand.php | ConfigCommand.doSetAction | private function doSetAction(Repository $repository, $item)
{
if (!$this->hasArgument('value')) {
$this->output->error('A value must be provided when using the "set" action.');
}
$value = $this->argument('value');
$repository->save($item, $this->unserialize($value));
} | php | private function doSetAction(Repository $repository, $item)
{
if (!$this->hasArgument('value')) {
$this->output->error('A value must be provided when using the "set" action.');
}
$value = $this->argument('value');
$repository->save($item, $this->unserialize($value));
} | [
"private",
"function",
"doSetAction",
"(",
"Repository",
"$",
"repository",
",",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasArgument",
"(",
"'value'",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"error",
"(",
"'A value must be provided when using the \"set\" action.'",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"argument",
"(",
"'value'",
")",
";",
"$",
"repository",
"->",
"save",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"unserialize",
"(",
"$",
"value",
")",
")",
";",
"}"
] | Complete a requested set action
@param Repository $repository
@param string $item | [
"Complete",
"a",
"requested",
"set",
"action"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/Command/ConfigCommand.php#L154-L162 | train |
concrete5/concrete5 | concrete/src/Page/Search/IndexedSearch.php | IndexedSearch.reindexAll | public function reindexAll($fullReindex = false)
{
Cache::disableAll();
/** @var IndexManagerInterface $indexStack */
$indexStack = Application::getFacadeApplication()->make(IndexManagerInterface::class);
$db = Loader::db();
if ($fullReindex) {
$db->Execute("truncate table PageSearchIndex");
}
$pl = new PageList();
$pl->ignoreAliases();
$pl->ignorePermissions();
$pl->sortByCollectionIDAscending();
$pl->filter(
false,
'(c.cDateModified > psi.cDateLastIndexed or UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(psi.cDateLastIndexed) > ' . $this->searchReindexTimeout . ' or psi.cID is null or psi.cDateLastIndexed is null)'
);
$pl->filter(false, '(ak_exclude_search_index is null or ak_exclude_search_index = 0)');
$pages = $pl->get($this->searchBatchSize);
$num = 0;
foreach ($pages as $c) {
$indexStack->index(Page::class, $c);
}
$pnum = Collection::reindexPendingPages();
$num = $num + $pnum;
Cache::enableAll();
$result = new stdClass();
$result->count = $num;
return $result;
} | php | public function reindexAll($fullReindex = false)
{
Cache::disableAll();
/** @var IndexManagerInterface $indexStack */
$indexStack = Application::getFacadeApplication()->make(IndexManagerInterface::class);
$db = Loader::db();
if ($fullReindex) {
$db->Execute("truncate table PageSearchIndex");
}
$pl = new PageList();
$pl->ignoreAliases();
$pl->ignorePermissions();
$pl->sortByCollectionIDAscending();
$pl->filter(
false,
'(c.cDateModified > psi.cDateLastIndexed or UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(psi.cDateLastIndexed) > ' . $this->searchReindexTimeout . ' or psi.cID is null or psi.cDateLastIndexed is null)'
);
$pl->filter(false, '(ak_exclude_search_index is null or ak_exclude_search_index = 0)');
$pages = $pl->get($this->searchBatchSize);
$num = 0;
foreach ($pages as $c) {
$indexStack->index(Page::class, $c);
}
$pnum = Collection::reindexPendingPages();
$num = $num + $pnum;
Cache::enableAll();
$result = new stdClass();
$result->count = $num;
return $result;
} | [
"public",
"function",
"reindexAll",
"(",
"$",
"fullReindex",
"=",
"false",
")",
"{",
"Cache",
"::",
"disableAll",
"(",
")",
";",
"/** @var IndexManagerInterface $indexStack */",
"$",
"indexStack",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
"->",
"make",
"(",
"IndexManagerInterface",
"::",
"class",
")",
";",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"if",
"(",
"$",
"fullReindex",
")",
"{",
"$",
"db",
"->",
"Execute",
"(",
"\"truncate table PageSearchIndex\"",
")",
";",
"}",
"$",
"pl",
"=",
"new",
"PageList",
"(",
")",
";",
"$",
"pl",
"->",
"ignoreAliases",
"(",
")",
";",
"$",
"pl",
"->",
"ignorePermissions",
"(",
")",
";",
"$",
"pl",
"->",
"sortByCollectionIDAscending",
"(",
")",
";",
"$",
"pl",
"->",
"filter",
"(",
"false",
",",
"'(c.cDateModified > psi.cDateLastIndexed or UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(psi.cDateLastIndexed) > '",
".",
"$",
"this",
"->",
"searchReindexTimeout",
".",
"' or psi.cID is null or psi.cDateLastIndexed is null)'",
")",
";",
"$",
"pl",
"->",
"filter",
"(",
"false",
",",
"'(ak_exclude_search_index is null or ak_exclude_search_index = 0)'",
")",
";",
"$",
"pages",
"=",
"$",
"pl",
"->",
"get",
"(",
"$",
"this",
"->",
"searchBatchSize",
")",
";",
"$",
"num",
"=",
"0",
";",
"foreach",
"(",
"$",
"pages",
"as",
"$",
"c",
")",
"{",
"$",
"indexStack",
"->",
"index",
"(",
"Page",
"::",
"class",
",",
"$",
"c",
")",
";",
"}",
"$",
"pnum",
"=",
"Collection",
"::",
"reindexPendingPages",
"(",
")",
";",
"$",
"num",
"=",
"$",
"num",
"+",
"$",
"pnum",
";",
"Cache",
"::",
"enableAll",
"(",
")",
";",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"count",
"=",
"$",
"num",
";",
"return",
"$",
"result",
";",
"}"
] | Reindexes the search engine. | [
"Reindexes",
"the",
"search",
"engine",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Search/IndexedSearch.php#L175-L212 | train |
concrete5/concrete5 | concrete/src/Authentication/Type/ExternalConcrete5/Extractor.php | Extractor.profileLoader | public function profileLoader()
{
$idTokenString = null;
$token = $this->service->getStorage()->retrieveAccessToken($this->service->service());
if ($token instanceof StdOAuth2Token) {
$idTokenString = array_get($token->getExtraParams(), 'id_token');
}
// If we don't have a proper ID token, let's just fetch the data from the API
if (!$idTokenString) {
return json_decode($this->service->request(self::USER_PATH), true)['data'];
}
$decoder = new Parser();
$idToken = $decoder->parse($idTokenString);
return [
'claims' => $idToken->getClaims()
];
} | php | public function profileLoader()
{
$idTokenString = null;
$token = $this->service->getStorage()->retrieveAccessToken($this->service->service());
if ($token instanceof StdOAuth2Token) {
$idTokenString = array_get($token->getExtraParams(), 'id_token');
}
// If we don't have a proper ID token, let's just fetch the data from the API
if (!$idTokenString) {
return json_decode($this->service->request(self::USER_PATH), true)['data'];
}
$decoder = new Parser();
$idToken = $decoder->parse($idTokenString);
return [
'claims' => $idToken->getClaims()
];
} | [
"public",
"function",
"profileLoader",
"(",
")",
"{",
"$",
"idTokenString",
"=",
"null",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"service",
"->",
"getStorage",
"(",
")",
"->",
"retrieveAccessToken",
"(",
"$",
"this",
"->",
"service",
"->",
"service",
"(",
")",
")",
";",
"if",
"(",
"$",
"token",
"instanceof",
"StdOAuth2Token",
")",
"{",
"$",
"idTokenString",
"=",
"array_get",
"(",
"$",
"token",
"->",
"getExtraParams",
"(",
")",
",",
"'id_token'",
")",
";",
"}",
"// If we don't have a proper ID token, let's just fetch the data from the API",
"if",
"(",
"!",
"$",
"idTokenString",
")",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"service",
"->",
"request",
"(",
"self",
"::",
"USER_PATH",
")",
",",
"true",
")",
"[",
"'data'",
"]",
";",
"}",
"$",
"decoder",
"=",
"new",
"Parser",
"(",
")",
";",
"$",
"idToken",
"=",
"$",
"decoder",
"->",
"parse",
"(",
"$",
"idTokenString",
")",
";",
"return",
"[",
"'claims'",
"=>",
"$",
"idToken",
"->",
"getClaims",
"(",
")",
"]",
";",
"}"
] | Load the external concrete5 profile, either from id_token or through the API
@return array
@throws \OAuth\Common\Exception\Exception
@throws \OAuth\Common\Storage\Exception\TokenNotFoundException
@throws \OAuth\Common\Token\Exception\ExpiredTokenException | [
"Load",
"the",
"external",
"concrete5",
"profile",
"either",
"from",
"id_token",
"or",
"through",
"the",
"API"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Authentication/Type/ExternalConcrete5/Extractor.php#L116-L135 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.getIterator | public function getIterator()
{
$db = $this->manager->connection();
// Make sure we have the proper columns before doing anything with SQL
if (!$this->lockColumnsExist($db)) {
return;
}
$qb = $db->createQueryBuilder();
$nextQuery = $this->getNextQuery($qb);
$try = 10;
while ($next = $this->next($nextQuery)) {
unset($next[$this->lockColumn]);
unset($next[$this->lockTimeoutColumn]);
if (!$this->reserveNext($next, $db)) {
if ($try--) {
// Avoid infinite loop
break;
}
// We were unable to reserve this properly, lets try the next item instead.
continue;
}
yield $next;
}
} | php | public function getIterator()
{
$db = $this->manager->connection();
// Make sure we have the proper columns before doing anything with SQL
if (!$this->lockColumnsExist($db)) {
return;
}
$qb = $db->createQueryBuilder();
$nextQuery = $this->getNextQuery($qb);
$try = 10;
while ($next = $this->next($nextQuery)) {
unset($next[$this->lockColumn]);
unset($next[$this->lockTimeoutColumn]);
if (!$this->reserveNext($next, $db)) {
if ($try--) {
// Avoid infinite loop
break;
}
// We were unable to reserve this properly, lets try the next item instead.
continue;
}
yield $next;
}
} | [
"public",
"function",
"getIterator",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"manager",
"->",
"connection",
"(",
")",
";",
"// Make sure we have the proper columns before doing anything with SQL",
"if",
"(",
"!",
"$",
"this",
"->",
"lockColumnsExist",
"(",
"$",
"db",
")",
")",
"{",
"return",
";",
"}",
"$",
"qb",
"=",
"$",
"db",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"nextQuery",
"=",
"$",
"this",
"->",
"getNextQuery",
"(",
"$",
"qb",
")",
";",
"$",
"try",
"=",
"10",
";",
"while",
"(",
"$",
"next",
"=",
"$",
"this",
"->",
"next",
"(",
"$",
"nextQuery",
")",
")",
"{",
"unset",
"(",
"$",
"next",
"[",
"$",
"this",
"->",
"lockColumn",
"]",
")",
";",
"unset",
"(",
"$",
"next",
"[",
"$",
"this",
"->",
"lockTimeoutColumn",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"reserveNext",
"(",
"$",
"next",
",",
"$",
"db",
")",
")",
"{",
"if",
"(",
"$",
"try",
"--",
")",
"{",
"// Avoid infinite loop",
"break",
";",
"}",
"// We were unable to reserve this properly, lets try the next item instead.",
"continue",
";",
"}",
"yield",
"$",
"next",
";",
"}",
"}"
] | Get an iterator that outputs locked thumbnail rows
@return \Generator|void | [
"Get",
"an",
"iterator",
"that",
"outputs",
"locked",
"thumbnail",
"rows"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L47-L74 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.next | private function next(QueryBuilder $nextQuery)
{
$now = new \DateTime('now');
$qb = clone $nextQuery;
$qb->setParameter(':currentTime', $now->format('Y-m-d H:i:s'));
return $qb->execute()->fetch();
} | php | private function next(QueryBuilder $nextQuery)
{
$now = new \DateTime('now');
$qb = clone $nextQuery;
$qb->setParameter(':currentTime', $now->format('Y-m-d H:i:s'));
return $qb->execute()->fetch();
} | [
"private",
"function",
"next",
"(",
"QueryBuilder",
"$",
"nextQuery",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
";",
"$",
"qb",
"=",
"clone",
"$",
"nextQuery",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"':currentTime'",
",",
"$",
"now",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
")",
";",
"return",
"$",
"qb",
"->",
"execute",
"(",
")",
"->",
"fetch",
"(",
")",
";",
"}"
] | Get the next matching thumbnail path row
@param \Doctrine\DBAL\Query\QueryBuilder $nextQuery
@return mixed | [
"Get",
"the",
"next",
"matching",
"thumbnail",
"path",
"row"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L81-L89 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.reserveNext | private function reserveNext(array $next, Connection $db)
{
$lockID = $this->getLockID();
// First update the table
try {
$date = new \DateTime('now');
$date->setTimestamp($date->getTimestamp() + $this->timeout);
if (!$db->update($this->table, [
$this->lockColumn => $lockID,
$this->lockTimeoutColumn => $date->format('Y-m-d H:i:s')
], $next)
) {
return false;
}
} catch (\Exception $e) {
return false;
}
return $this->matchingLock($lockID, $next, $db);
} | php | private function reserveNext(array $next, Connection $db)
{
$lockID = $this->getLockID();
// First update the table
try {
$date = new \DateTime('now');
$date->setTimestamp($date->getTimestamp() + $this->timeout);
if (!$db->update($this->table, [
$this->lockColumn => $lockID,
$this->lockTimeoutColumn => $date->format('Y-m-d H:i:s')
], $next)
) {
return false;
}
} catch (\Exception $e) {
return false;
}
return $this->matchingLock($lockID, $next, $db);
} | [
"private",
"function",
"reserveNext",
"(",
"array",
"$",
"next",
",",
"Connection",
"$",
"db",
")",
"{",
"$",
"lockID",
"=",
"$",
"this",
"->",
"getLockID",
"(",
")",
";",
"// First update the table",
"try",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
";",
"$",
"date",
"->",
"setTimestamp",
"(",
"$",
"date",
"->",
"getTimestamp",
"(",
")",
"+",
"$",
"this",
"->",
"timeout",
")",
";",
"if",
"(",
"!",
"$",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"table",
",",
"[",
"$",
"this",
"->",
"lockColumn",
"=>",
"$",
"lockID",
",",
"$",
"this",
"->",
"lockTimeoutColumn",
"=>",
"$",
"date",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
"]",
",",
"$",
"next",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"matchingLock",
"(",
"$",
"lockID",
",",
"$",
"next",
",",
"$",
"db",
")",
";",
"}"
] | Mark the next item as reserved
@param array $next
@param \Concrete\Core\Database\Connection\Connection $db
@return bool | [
"Mark",
"the",
"next",
"item",
"as",
"reserved"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L97-L118 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.matchingLock | private function matchingLock($lockID, array $next, Connection $db)
{
// Then go back and double check that we successfully locked it
$qb = $db->createQueryBuilder();
$select = $qb
->select('*')
->from($this->table, 't')
// Match the lock ID we just tried to set
->where($qb->expr()->eq($this->lockColumn, $qb->expr()->literal($lockID)));
// Build additional predicates from already known values
$predicates = array_map(function ($value, $key) use ($qb) {
return $qb->expr()->eq($key, $qb->expr()->literal($value));
}, $next, array_keys($next));
call_user_func_array([$select, 'andWhere'], $predicates);
// Get the result and validate it
if ($result = $select->setMaxResults(1)->execute()->fetch()) {
return $result;
}
return false;
} | php | private function matchingLock($lockID, array $next, Connection $db)
{
// Then go back and double check that we successfully locked it
$qb = $db->createQueryBuilder();
$select = $qb
->select('*')
->from($this->table, 't')
// Match the lock ID we just tried to set
->where($qb->expr()->eq($this->lockColumn, $qb->expr()->literal($lockID)));
// Build additional predicates from already known values
$predicates = array_map(function ($value, $key) use ($qb) {
return $qb->expr()->eq($key, $qb->expr()->literal($value));
}, $next, array_keys($next));
call_user_func_array([$select, 'andWhere'], $predicates);
// Get the result and validate it
if ($result = $select->setMaxResults(1)->execute()->fetch()) {
return $result;
}
return false;
} | [
"private",
"function",
"matchingLock",
"(",
"$",
"lockID",
",",
"array",
"$",
"next",
",",
"Connection",
"$",
"db",
")",
"{",
"// Then go back and double check that we successfully locked it",
"$",
"qb",
"=",
"$",
"db",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"select",
"=",
"$",
"qb",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"table",
",",
"'t'",
")",
"// Match the lock ID we just tried to set",
"->",
"where",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"$",
"this",
"->",
"lockColumn",
",",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"literal",
"(",
"$",
"lockID",
")",
")",
")",
";",
"// Build additional predicates from already known values",
"$",
"predicates",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"qb",
")",
"{",
"return",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"$",
"key",
",",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"literal",
"(",
"$",
"value",
")",
")",
";",
"}",
",",
"$",
"next",
",",
"array_keys",
"(",
"$",
"next",
")",
")",
";",
"call_user_func_array",
"(",
"[",
"$",
"select",
",",
"'andWhere'",
"]",
",",
"$",
"predicates",
")",
";",
"// Get the result and validate it",
"if",
"(",
"$",
"result",
"=",
"$",
"select",
"->",
"setMaxResults",
"(",
"1",
")",
"->",
"execute",
"(",
")",
"->",
"fetch",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"false",
";",
"}"
] | Find the row matching the passed criteria
This is used to verify that we've successfully locked a row in the database.
@param $lockID
@param array $next
@param \Concrete\Core\Database\Connection\Connection $db
@return bool|mixed | [
"Find",
"the",
"row",
"matching",
"the",
"passed",
"criteria",
"This",
"is",
"used",
"to",
"verify",
"that",
"we",
"ve",
"successfully",
"locked",
"a",
"row",
"in",
"the",
"database",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L128-L152 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.lockColumnsExist | private function lockColumnsExist(Connection $db)
{
$schema = $db->getSchemaManager()->listTableColumns($this->table);
return isset($schema['lockid']);
} | php | private function lockColumnsExist(Connection $db)
{
$schema = $db->getSchemaManager()->listTableColumns($this->table);
return isset($schema['lockid']);
} | [
"private",
"function",
"lockColumnsExist",
"(",
"Connection",
"$",
"db",
")",
"{",
"$",
"schema",
"=",
"$",
"db",
"->",
"getSchemaManager",
"(",
")",
"->",
"listTableColumns",
"(",
"$",
"this",
"->",
"table",
")",
";",
"return",
"isset",
"(",
"$",
"schema",
"[",
"'lockid'",
"]",
")",
";",
"}"
] | Check if the required lock columns have been added to the database.
This prevents people upgrading from seeing 500 errors in their logs.
@param \Concrete\Core\Database\Connection\Connection $db
@return bool | [
"Check",
"if",
"the",
"required",
"lock",
"columns",
"have",
"been",
"added",
"to",
"the",
"database",
".",
"This",
"prevents",
"people",
"upgrading",
"from",
"seeing",
"500",
"errors",
"in",
"their",
"logs",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L161-L165 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php | AtomicThumbnailStream.getLockID | private function getLockID()
{
if ($this->lockID) {
return $this->lockID;
}
$id = uniqid('thumbnail_thread_', true);
$this->lockID = $id;
return $id;
} | php | private function getLockID()
{
if ($this->lockID) {
return $this->lockID;
}
$id = uniqid('thumbnail_thread_', true);
$this->lockID = $id;
return $id;
} | [
"private",
"function",
"getLockID",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lockID",
")",
"{",
"return",
"$",
"this",
"->",
"lockID",
";",
"}",
"$",
"id",
"=",
"uniqid",
"(",
"'thumbnail_thread_'",
",",
"true",
")",
";",
"$",
"this",
"->",
"lockID",
"=",
"$",
"id",
";",
"return",
"$",
"id",
";",
"}"
] | Get and memoize the current lock ID
@return string | [
"Get",
"and",
"memoize",
"the",
"current",
"lock",
"ID"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/AtomicThumbnailStream.php#L197-L207 | train |
concrete5/concrete5 | concrete/src/Block/BlockType/BlockType.php | BlockType.getByHandle | public static function getByHandle($btHandle)
{
$result = null;
$btHandle = (string) $btHandle;
if ($btHandle !== '') {
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$repo = $em->getRepository(BlockTypeEntity::class);
$result = $repo->findOneBy(['btHandle' => $btHandle]);
if ($result !== null) {
$result->loadController();
}
}
return $result;
} | php | public static function getByHandle($btHandle)
{
$result = null;
$btHandle = (string) $btHandle;
if ($btHandle !== '') {
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$repo = $em->getRepository(BlockTypeEntity::class);
$result = $repo->findOneBy(['btHandle' => $btHandle]);
if ($result !== null) {
$result->loadController();
}
}
return $result;
} | [
"public",
"static",
"function",
"getByHandle",
"(",
"$",
"btHandle",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"btHandle",
"=",
"(",
"string",
")",
"$",
"btHandle",
";",
"if",
"(",
"$",
"btHandle",
"!==",
"''",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"em",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"$",
"repo",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"BlockTypeEntity",
"::",
"class",
")",
";",
"$",
"result",
"=",
"$",
"repo",
"->",
"findOneBy",
"(",
"[",
"'btHandle'",
"=>",
"$",
"btHandle",
"]",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"null",
")",
"{",
"$",
"result",
"->",
"loadController",
"(",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a BlockType given its handle.
@param string $btHandle
@return \Concrete\Core\Entity\Block\BlockType\BlockType|null | [
"Get",
"a",
"BlockType",
"given",
"its",
"handle",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/BlockType.php#L21-L36 | train |
concrete5/concrete5 | concrete/src/Block/BlockType/BlockType.php | BlockType.getByID | public static function getByID($btID)
{
$result = null;
$btID = (int) $btID;
if ($btID !== 0) {
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$result = $em->find(BlockTypeEntity::class, $btID);
if ($result !== null) {
$result->loadController();
}
}
return $result;
} | php | public static function getByID($btID)
{
$result = null;
$btID = (int) $btID;
if ($btID !== 0) {
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$result = $em->find(BlockTypeEntity::class, $btID);
if ($result !== null) {
$result->loadController();
}
}
return $result;
} | [
"public",
"static",
"function",
"getByID",
"(",
"$",
"btID",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"btID",
"=",
"(",
"int",
")",
"$",
"btID",
";",
"if",
"(",
"$",
"btID",
"!==",
"0",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"em",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"$",
"result",
"=",
"$",
"em",
"->",
"find",
"(",
"BlockTypeEntity",
"::",
"class",
",",
"$",
"btID",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"null",
")",
"{",
"$",
"result",
"->",
"loadController",
"(",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a BlockType given its ID.
@param int $btID
@return \Concrete\Core\Entity\Block\BlockType\BlockType|null | [
"Get",
"a",
"BlockType",
"given",
"its",
"ID",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/BlockType.php#L45-L59 | train |
concrete5/concrete5 | concrete/src/Block/BlockType/BlockType.php | BlockType.installBlockType | public static function installBlockType($btHandle, $pkg = false)
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$pkgHandle = (string) (is_object($pkg) ? $pkg->getPackageHandle() : $pkg);
$class = static::getBlockTypeMappedClass($btHandle, $pkgHandle);
$bta = $app->build($class);
$locator = $app->make(FileLocator::class);
if ($pkgHandle !== '') {
$locator->addLocation(new FileLocator\PackageLocation($pkgHandle));
}
$path = dirname($locator->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_BLOCK_DB)->getFile());
//Attempt to run the subclass methods (install schema from db.xml, etc.)
$bta->install($path);
// Prevent the database records being stored in wrong language
$loc = $app->make(Localization::class);
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
try {
//Install the block
$bt = new BlockTypeEntity();
$bt->loadFromController($bta);
if (is_object($pkg)) {
$bt->setPackageID($pkg->getPackageID());
}
$bt->setBlockTypeHandle($btHandle);
} finally {
$loc->popActiveContext();
}
$em->persist($bt);
$em->flush();
if ($bta->getBlockTypeDefaultSet()) {
$set = Set::getByHandle($bta->getBlockTypeDefaultSet());
if ($set !== null) {
$set->addBlockType($bt);
}
}
return $bt;
} | php | public static function installBlockType($btHandle, $pkg = false)
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
$pkgHandle = (string) (is_object($pkg) ? $pkg->getPackageHandle() : $pkg);
$class = static::getBlockTypeMappedClass($btHandle, $pkgHandle);
$bta = $app->build($class);
$locator = $app->make(FileLocator::class);
if ($pkgHandle !== '') {
$locator->addLocation(new FileLocator\PackageLocation($pkgHandle));
}
$path = dirname($locator->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_BLOCK_DB)->getFile());
//Attempt to run the subclass methods (install schema from db.xml, etc.)
$bta->install($path);
// Prevent the database records being stored in wrong language
$loc = $app->make(Localization::class);
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
try {
//Install the block
$bt = new BlockTypeEntity();
$bt->loadFromController($bta);
if (is_object($pkg)) {
$bt->setPackageID($pkg->getPackageID());
}
$bt->setBlockTypeHandle($btHandle);
} finally {
$loc->popActiveContext();
}
$em->persist($bt);
$em->flush();
if ($bta->getBlockTypeDefaultSet()) {
$set = Set::getByHandle($bta->getBlockTypeDefaultSet());
if ($set !== null) {
$set->addBlockType($bt);
}
}
return $bt;
} | [
"public",
"static",
"function",
"installBlockType",
"(",
"$",
"btHandle",
",",
"$",
"pkg",
"=",
"false",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"em",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
";",
"$",
"pkgHandle",
"=",
"(",
"string",
")",
"(",
"is_object",
"(",
"$",
"pkg",
")",
"?",
"$",
"pkg",
"->",
"getPackageHandle",
"(",
")",
":",
"$",
"pkg",
")",
";",
"$",
"class",
"=",
"static",
"::",
"getBlockTypeMappedClass",
"(",
"$",
"btHandle",
",",
"$",
"pkgHandle",
")",
";",
"$",
"bta",
"=",
"$",
"app",
"->",
"build",
"(",
"$",
"class",
")",
";",
"$",
"locator",
"=",
"$",
"app",
"->",
"make",
"(",
"FileLocator",
"::",
"class",
")",
";",
"if",
"(",
"$",
"pkgHandle",
"!==",
"''",
")",
"{",
"$",
"locator",
"->",
"addLocation",
"(",
"new",
"FileLocator",
"\\",
"PackageLocation",
"(",
"$",
"pkgHandle",
")",
")",
";",
"}",
"$",
"path",
"=",
"dirname",
"(",
"$",
"locator",
"->",
"getRecord",
"(",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"btHandle",
".",
"'/'",
".",
"FILENAME_BLOCK_DB",
")",
"->",
"getFile",
"(",
")",
")",
";",
"//Attempt to run the subclass methods (install schema from db.xml, etc.)",
"$",
"bta",
"->",
"install",
"(",
"$",
"path",
")",
";",
"// Prevent the database records being stored in wrong language",
"$",
"loc",
"=",
"$",
"app",
"->",
"make",
"(",
"Localization",
"::",
"class",
")",
";",
"$",
"loc",
"->",
"pushActiveContext",
"(",
"Localization",
"::",
"CONTEXT_SYSTEM",
")",
";",
"try",
"{",
"//Install the block",
"$",
"bt",
"=",
"new",
"BlockTypeEntity",
"(",
")",
";",
"$",
"bt",
"->",
"loadFromController",
"(",
"$",
"bta",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"pkg",
")",
")",
"{",
"$",
"bt",
"->",
"setPackageID",
"(",
"$",
"pkg",
"->",
"getPackageID",
"(",
")",
")",
";",
"}",
"$",
"bt",
"->",
"setBlockTypeHandle",
"(",
"$",
"btHandle",
")",
";",
"}",
"finally",
"{",
"$",
"loc",
"->",
"popActiveContext",
"(",
")",
";",
"}",
"$",
"em",
"->",
"persist",
"(",
"$",
"bt",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"$",
"bta",
"->",
"getBlockTypeDefaultSet",
"(",
")",
")",
"{",
"$",
"set",
"=",
"Set",
"::",
"getByHandle",
"(",
"$",
"bta",
"->",
"getBlockTypeDefaultSet",
"(",
")",
")",
";",
"if",
"(",
"$",
"set",
"!==",
"null",
")",
"{",
"$",
"set",
"->",
"addBlockType",
"(",
"$",
"bt",
")",
";",
"}",
"}",
"return",
"$",
"bt",
";",
"}"
] | Install a BlockType that is passed via a btHandle string. The core or override directories are parsed.
@param string $btHandle The handle of the block type
@param \Concrete\Core\Entity\Package|\Concrete\Core\Package\Package|string|false $pkg The package owning the block type (or its handle)
@return \Concrete\Core\Entity\Block\BlockType\BlockType | [
"Install",
"a",
"BlockType",
"that",
"is",
"passed",
"via",
"a",
"btHandle",
"string",
".",
"The",
"core",
"or",
"override",
"directories",
"are",
"parsed",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/BlockType.php#L69-L112 | train |
concrete5/concrete5 | concrete/src/Block/BlockType/BlockType.php | BlockType.getBlockTypeMappedClass | public static function getBlockTypeMappedClass($btHandle, $pkgHandle = false)
{
$app = Application::getFacadeApplication();
$txt = $app->make('helper/text');
$pkgHandle = (string) $pkgHandle;
$locator = $app->make(FileLocator::class);
if ($pkgHandle !== '') {
$locator->addLocation(new FileLocator\PackageLocation($pkgHandle));
}
$r = $locator->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_CONTROLLER);
$overriddenPackageHandle = (string) $r->getPackageHandle();
if ($overriddenPackageHandle !== '') {
$pkgHandle = $overriddenPackageHandle;
}
$prefix = $r->isOverride() ? true : $pkgHandle;
$class = core_class('Block\\' . $txt->camelcase($btHandle) . '\\Controller', $prefix);
return class_exists($class) ? $class : null;
} | php | public static function getBlockTypeMappedClass($btHandle, $pkgHandle = false)
{
$app = Application::getFacadeApplication();
$txt = $app->make('helper/text');
$pkgHandle = (string) $pkgHandle;
$locator = $app->make(FileLocator::class);
if ($pkgHandle !== '') {
$locator->addLocation(new FileLocator\PackageLocation($pkgHandle));
}
$r = $locator->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_CONTROLLER);
$overriddenPackageHandle = (string) $r->getPackageHandle();
if ($overriddenPackageHandle !== '') {
$pkgHandle = $overriddenPackageHandle;
}
$prefix = $r->isOverride() ? true : $pkgHandle;
$class = core_class('Block\\' . $txt->camelcase($btHandle) . '\\Controller', $prefix);
return class_exists($class) ? $class : null;
} | [
"public",
"static",
"function",
"getBlockTypeMappedClass",
"(",
"$",
"btHandle",
",",
"$",
"pkgHandle",
"=",
"false",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"txt",
"=",
"$",
"app",
"->",
"make",
"(",
"'helper/text'",
")",
";",
"$",
"pkgHandle",
"=",
"(",
"string",
")",
"$",
"pkgHandle",
";",
"$",
"locator",
"=",
"$",
"app",
"->",
"make",
"(",
"FileLocator",
"::",
"class",
")",
";",
"if",
"(",
"$",
"pkgHandle",
"!==",
"''",
")",
"{",
"$",
"locator",
"->",
"addLocation",
"(",
"new",
"FileLocator",
"\\",
"PackageLocation",
"(",
"$",
"pkgHandle",
")",
")",
";",
"}",
"$",
"r",
"=",
"$",
"locator",
"->",
"getRecord",
"(",
"DIRNAME_BLOCKS",
".",
"'/'",
".",
"$",
"btHandle",
".",
"'/'",
".",
"FILENAME_CONTROLLER",
")",
";",
"$",
"overriddenPackageHandle",
"=",
"(",
"string",
")",
"$",
"r",
"->",
"getPackageHandle",
"(",
")",
";",
"if",
"(",
"$",
"overriddenPackageHandle",
"!==",
"''",
")",
"{",
"$",
"pkgHandle",
"=",
"$",
"overriddenPackageHandle",
";",
"}",
"$",
"prefix",
"=",
"$",
"r",
"->",
"isOverride",
"(",
")",
"?",
"true",
":",
"$",
"pkgHandle",
";",
"$",
"class",
"=",
"core_class",
"(",
"'Block\\\\'",
".",
"$",
"txt",
"->",
"camelcase",
"(",
"$",
"btHandle",
")",
".",
"'\\\\Controller'",
",",
"$",
"prefix",
")",
";",
"return",
"class_exists",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"null",
";",
"}"
] | Return the class file that this BlockType uses.
@param string $btHandle The handle of the block type
@param string|false $pkgHandle The handle of the package owning the block type
@return string|null | [
"Return",
"the",
"class",
"file",
"that",
"this",
"BlockType",
"uses",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/BlockType.php#L122-L142 | train |
concrete5/concrete5 | concrete/src/Block/BlockType/BlockType.php | BlockType.clearCache | public static function clearCache()
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$sm = $db->getSchemaManager();
$tableNames = array_map('strtolower', $sm->listTableNames());
if (in_array('config', $tableNames, true)) {
$platform = $db->getDatabasePlatform();
foreach ($sm->listTableColumns('Blocks') as $tableColumn) {
if (strcasecmp($tableColumn->getName(), 'btCachedBlockRecord') === 0) {
$db->query('update Blocks set btCachedBlockRecord = null');
break;
}
}
if (in_array('collectionversionblocksoutputcache', $tableNames, true)) {
$db->exec($platform->getTruncateTableSQL('CollectionVersionBlocksOutputCache'));
}
}
} | php | public static function clearCache()
{
$app = Application::getFacadeApplication();
$db = $app->make(Connection::class);
$sm = $db->getSchemaManager();
$tableNames = array_map('strtolower', $sm->listTableNames());
if (in_array('config', $tableNames, true)) {
$platform = $db->getDatabasePlatform();
foreach ($sm->listTableColumns('Blocks') as $tableColumn) {
if (strcasecmp($tableColumn->getName(), 'btCachedBlockRecord') === 0) {
$db->query('update Blocks set btCachedBlockRecord = null');
break;
}
}
if (in_array('collectionversionblocksoutputcache', $tableNames, true)) {
$db->exec($platform->getTruncateTableSQL('CollectionVersionBlocksOutputCache'));
}
}
} | [
"public",
"static",
"function",
"clearCache",
"(",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"db",
"=",
"$",
"app",
"->",
"make",
"(",
"Connection",
"::",
"class",
")",
";",
"$",
"sm",
"=",
"$",
"db",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"tableNames",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"sm",
"->",
"listTableNames",
"(",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"'config'",
",",
"$",
"tableNames",
",",
"true",
")",
")",
"{",
"$",
"platform",
"=",
"$",
"db",
"->",
"getDatabasePlatform",
"(",
")",
";",
"foreach",
"(",
"$",
"sm",
"->",
"listTableColumns",
"(",
"'Blocks'",
")",
"as",
"$",
"tableColumn",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"tableColumn",
"->",
"getName",
"(",
")",
",",
"'btCachedBlockRecord'",
")",
"===",
"0",
")",
"{",
"$",
"db",
"->",
"query",
"(",
"'update Blocks set btCachedBlockRecord = null'",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"in_array",
"(",
"'collectionversionblocksoutputcache'",
",",
"$",
"tableNames",
",",
"true",
")",
")",
"{",
"$",
"db",
"->",
"exec",
"(",
"$",
"platform",
"->",
"getTruncateTableSQL",
"(",
"'CollectionVersionBlocksOutputCache'",
")",
")",
";",
"}",
"}",
"}"
] | Clears output and record caches. | [
"Clears",
"output",
"and",
"record",
"caches",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/BlockType.php#L147-L165 | train |
concrete5/concrete5 | concrete/src/Localization/Service/TranslationsInstaller.php | TranslationsInstaller.installMissingPackageTranslations | public function installMissingPackageTranslations(Package $package)
{
// Get the list of languages that users may need for the user interface.
$wanted = Localization::getAvailableInterfaceLanguages();
// Get the list of languages that users may need for the site locales.
$siteService = $this->app->make(SiteService::class);
$site = $siteService->getSite();
if ($site) {
foreach ($site->getLocales() as $locale) {
$wanted[] = $locale->getLocale();
}
}
$wanted = array_unique($wanted);
$wanted = array_filter($wanted, function ($localeID) {
return $localeID !== Localization::BASE_LOCALE;
});
$already = array_keys($this->localFactory->getAvailablePackageStats($package));
$missing = array_diff($wanted, $already);
$result = [];
if (count($missing) > 0) {
$available = $this->remoteProvider->getAvailablePackageStats($package->getPackageHandle(), $package->getPackageVersion());
$toDownload = array_intersect($missing, array_keys($available));
foreach ($missing as $missingID) {
if (!in_array($missingID, $toDownload, true)) {
$result[$missingID] = false;
} else {
try {
$this->installPackageTranslations($package, $missingID);
$result[$missingID] = true;
} catch (Exception $x) {
$result[$missingID] = $x;
}
}
}
}
return $result;
} | php | public function installMissingPackageTranslations(Package $package)
{
// Get the list of languages that users may need for the user interface.
$wanted = Localization::getAvailableInterfaceLanguages();
// Get the list of languages that users may need for the site locales.
$siteService = $this->app->make(SiteService::class);
$site = $siteService->getSite();
if ($site) {
foreach ($site->getLocales() as $locale) {
$wanted[] = $locale->getLocale();
}
}
$wanted = array_unique($wanted);
$wanted = array_filter($wanted, function ($localeID) {
return $localeID !== Localization::BASE_LOCALE;
});
$already = array_keys($this->localFactory->getAvailablePackageStats($package));
$missing = array_diff($wanted, $already);
$result = [];
if (count($missing) > 0) {
$available = $this->remoteProvider->getAvailablePackageStats($package->getPackageHandle(), $package->getPackageVersion());
$toDownload = array_intersect($missing, array_keys($available));
foreach ($missing as $missingID) {
if (!in_array($missingID, $toDownload, true)) {
$result[$missingID] = false;
} else {
try {
$this->installPackageTranslations($package, $missingID);
$result[$missingID] = true;
} catch (Exception $x) {
$result[$missingID] = $x;
}
}
}
}
return $result;
} | [
"public",
"function",
"installMissingPackageTranslations",
"(",
"Package",
"$",
"package",
")",
"{",
"// Get the list of languages that users may need for the user interface.",
"$",
"wanted",
"=",
"Localization",
"::",
"getAvailableInterfaceLanguages",
"(",
")",
";",
"// Get the list of languages that users may need for the site locales.",
"$",
"siteService",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"SiteService",
"::",
"class",
")",
";",
"$",
"site",
"=",
"$",
"siteService",
"->",
"getSite",
"(",
")",
";",
"if",
"(",
"$",
"site",
")",
"{",
"foreach",
"(",
"$",
"site",
"->",
"getLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"wanted",
"[",
"]",
"=",
"$",
"locale",
"->",
"getLocale",
"(",
")",
";",
"}",
"}",
"$",
"wanted",
"=",
"array_unique",
"(",
"$",
"wanted",
")",
";",
"$",
"wanted",
"=",
"array_filter",
"(",
"$",
"wanted",
",",
"function",
"(",
"$",
"localeID",
")",
"{",
"return",
"$",
"localeID",
"!==",
"Localization",
"::",
"BASE_LOCALE",
";",
"}",
")",
";",
"$",
"already",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"localFactory",
"->",
"getAvailablePackageStats",
"(",
"$",
"package",
")",
")",
";",
"$",
"missing",
"=",
"array_diff",
"(",
"$",
"wanted",
",",
"$",
"already",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"missing",
")",
">",
"0",
")",
"{",
"$",
"available",
"=",
"$",
"this",
"->",
"remoteProvider",
"->",
"getAvailablePackageStats",
"(",
"$",
"package",
"->",
"getPackageHandle",
"(",
")",
",",
"$",
"package",
"->",
"getPackageVersion",
"(",
")",
")",
";",
"$",
"toDownload",
"=",
"array_intersect",
"(",
"$",
"missing",
",",
"array_keys",
"(",
"$",
"available",
")",
")",
";",
"foreach",
"(",
"$",
"missing",
"as",
"$",
"missingID",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"missingID",
",",
"$",
"toDownload",
",",
"true",
")",
")",
"{",
"$",
"result",
"[",
"$",
"missingID",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"this",
"->",
"installPackageTranslations",
"(",
"$",
"package",
",",
"$",
"missingID",
")",
";",
"$",
"result",
"[",
"$",
"missingID",
"]",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"result",
"[",
"$",
"missingID",
"]",
"=",
"$",
"x",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Install missing package translation files.
@param Package $package
@return array array keys are the missing locale IDs, array values are: false (package not translated), true (language file downloaded), \Exception (in case of errors) | [
"Install",
"missing",
"package",
"translation",
"files",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/TranslationsInstaller.php#L90-L127 | train |
concrete5/concrete5 | concrete/src/Notification/Type/UserDeactivatedType.php | UserDeactivatedType.getDefaultSubscription | protected function getDefaultSubscription()
{
if (!$this->defaultSubscription) {
$this->defaultSubscription = $this->app->make(StandardSubscription::class,
[self::IDENTIFIER, t('User Deactivated')]);
}
return $this->defaultSubscription;
} | php | protected function getDefaultSubscription()
{
if (!$this->defaultSubscription) {
$this->defaultSubscription = $this->app->make(StandardSubscription::class,
[self::IDENTIFIER, t('User Deactivated')]);
}
return $this->defaultSubscription;
} | [
"protected",
"function",
"getDefaultSubscription",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"defaultSubscription",
")",
"{",
"$",
"this",
"->",
"defaultSubscription",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"StandardSubscription",
"::",
"class",
",",
"[",
"self",
"::",
"IDENTIFIER",
",",
"t",
"(",
"'User Deactivated'",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"defaultSubscription",
";",
"}"
] | Get the default subscription object.
If one was not passed in at construct time create one now
@return \Concrete\Core\Notification\Subscription\SubscriptionInterface | [
"Get",
"the",
"default",
"subscription",
"object",
".",
"If",
"one",
"was",
"not",
"passed",
"in",
"at",
"construct",
"time",
"create",
"one",
"now"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Notification/Type/UserDeactivatedType.php#L77-L85 | train |
concrete5/concrete5 | concrete/src/Notification/Type/UserDeactivatedType.php | UserDeactivatedType.getAvailableFilters | public function getAvailableFilters()
{
if (!$this->defaultFilter) {
$this->defaultFilter = $this->app->make(StandardFilter::class, [
$this,
self::IDENTIFIER,
t('User Deactivated'),
'userdeactivatednotification'
]);
}
return [$this->defaultFilter];
} | php | public function getAvailableFilters()
{
if (!$this->defaultFilter) {
$this->defaultFilter = $this->app->make(StandardFilter::class, [
$this,
self::IDENTIFIER,
t('User Deactivated'),
'userdeactivatednotification'
]);
}
return [$this->defaultFilter];
} | [
"public",
"function",
"getAvailableFilters",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"defaultFilter",
")",
"{",
"$",
"this",
"->",
"defaultFilter",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"StandardFilter",
"::",
"class",
",",
"[",
"$",
"this",
",",
"self",
"::",
"IDENTIFIER",
",",
"t",
"(",
"'User Deactivated'",
")",
",",
"'userdeactivatednotification'",
"]",
")",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"defaultFilter",
"]",
";",
"}"
] | Get available notification filters
@return \Concrete\Core\Notification\Alert\Filter\FilterInterface[] | [
"Get",
"available",
"notification",
"filters"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Notification/Type/UserDeactivatedType.php#L116-L128 | train |
concrete5/concrete5 | concrete/src/Page/Single.php | Single.addGlobal | public static function addGlobal($cPath, $pkg = null)
{
$pathToFile = static::getPathToNode($cPath, $pkg);
$txt = Loader::helper('text');
$c = CorePage::getByPath($cPath);
if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) {
// create the page at that point in the tree
$data = array();
$data['handle'] = trim($cPath, '/');
$data['name'] = $txt->unhandle($data['handle']);
$data['filename'] = $pathToFile;
$data['uID'] = USER_SUPER_ID;
if ($pkg != null) {
$data['pkgID'] = $pkg->getPackageID();
}
$c = Page::addStatic($data, null);
$c->moveToRoot();
return $c;
}
} | php | public static function addGlobal($cPath, $pkg = null)
{
$pathToFile = static::getPathToNode($cPath, $pkg);
$txt = Loader::helper('text');
$c = CorePage::getByPath($cPath);
if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) {
// create the page at that point in the tree
$data = array();
$data['handle'] = trim($cPath, '/');
$data['name'] = $txt->unhandle($data['handle']);
$data['filename'] = $pathToFile;
$data['uID'] = USER_SUPER_ID;
if ($pkg != null) {
$data['pkgID'] = $pkg->getPackageID();
}
$c = Page::addStatic($data, null);
$c->moveToRoot();
return $c;
}
} | [
"public",
"static",
"function",
"addGlobal",
"(",
"$",
"cPath",
",",
"$",
"pkg",
"=",
"null",
")",
"{",
"$",
"pathToFile",
"=",
"static",
"::",
"getPathToNode",
"(",
"$",
"cPath",
",",
"$",
"pkg",
")",
";",
"$",
"txt",
"=",
"Loader",
"::",
"helper",
"(",
"'text'",
")",
";",
"$",
"c",
"=",
"CorePage",
"::",
"getByPath",
"(",
"$",
"cPath",
")",
";",
"if",
"(",
"$",
"c",
"->",
"isError",
"(",
")",
"&&",
"$",
"c",
"->",
"getError",
"(",
")",
"==",
"COLLECTION_NOT_FOUND",
")",
"{",
"// create the page at that point in the tree",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"data",
"[",
"'handle'",
"]",
"=",
"trim",
"(",
"$",
"cPath",
",",
"'/'",
")",
";",
"$",
"data",
"[",
"'name'",
"]",
"=",
"$",
"txt",
"->",
"unhandle",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
";",
"$",
"data",
"[",
"'filename'",
"]",
"=",
"$",
"pathToFile",
";",
"$",
"data",
"[",
"'uID'",
"]",
"=",
"USER_SUPER_ID",
";",
"if",
"(",
"$",
"pkg",
"!=",
"null",
")",
"{",
"$",
"data",
"[",
"'pkgID'",
"]",
"=",
"$",
"pkg",
"->",
"getPackageID",
"(",
")",
";",
"}",
"$",
"c",
"=",
"Page",
"::",
"addStatic",
"(",
"$",
"data",
",",
"null",
")",
";",
"$",
"c",
"->",
"moveToRoot",
"(",
")",
";",
"return",
"$",
"c",
";",
"}",
"}"
] | Adds a single page outside of any site trees. The global=true declaration in content importer XML must come at
on the first URL segment, so we don't have to be smart and check to see if the parents already eixst.
@param $cPath
@param null $pkg
@return mixed | [
"Adds",
"a",
"single",
"page",
"outside",
"of",
"any",
"site",
"trees",
".",
"The",
"global",
"=",
"true",
"declaration",
"in",
"content",
"importer",
"XML",
"must",
"come",
"at",
"on",
"the",
"first",
"URL",
"segment",
"so",
"we",
"don",
"t",
"have",
"to",
"be",
"smart",
"and",
"check",
"to",
"see",
"if",
"the",
"parents",
"already",
"eixst",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Single.php#L134-L155 | train |
concrete5/concrete5 | concrete/src/Page/Single.php | Single.getList | public static function getList()
{
$db = Loader::db();
$r = $db->query("select Pages.cID from Pages inner join Collections on Pages.cID = Collections.cID where cFilename is not null order by cDateModified desc");
$pages = array();
while ($row = $r->fetchRow()) {
$c = Page::getByID($row['cID']);
$pages[] = $c;
}
return $pages;
} | php | public static function getList()
{
$db = Loader::db();
$r = $db->query("select Pages.cID from Pages inner join Collections on Pages.cID = Collections.cID where cFilename is not null order by cDateModified desc");
$pages = array();
while ($row = $r->fetchRow()) {
$c = Page::getByID($row['cID']);
$pages[] = $c;
}
return $pages;
} | [
"public",
"static",
"function",
"getList",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"query",
"(",
"\"select Pages.cID from Pages inner join Collections on Pages.cID = Collections.cID where cFilename is not null order by cDateModified desc\"",
")",
";",
"$",
"pages",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"r",
"->",
"fetchRow",
"(",
")",
")",
"{",
"$",
"c",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'cID'",
"]",
")",
";",
"$",
"pages",
"[",
"]",
"=",
"$",
"c",
";",
"}",
"return",
"$",
"pages",
";",
"}"
] | returns all pages in the site that are "single" | [
"returns",
"all",
"pages",
"in",
"the",
"site",
"that",
"are",
"single"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Single.php#L253-L264 | train |
concrete5/concrete5 | concrete/src/Permission/Access/Entity/GroupCombinationEntity.php | GroupCombinationEntity.getAccessEntitiesForUser | public static function getAccessEntitiesForUser($user)
{
$entities = [];
// If the user isnt registered, there is no need to do this anymore.
if ($user->isRegistered()) {
$ingids = [];
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
// First look for any combos that this group would specifically be in.
// We check if the combos contain any of the groups this user is in.
// That way if there aren't any we can just skip it.
foreach ($user->getUserGroups() as $key => $val) {
$ingids[] = $key;
}
$instr = implode(',', $ingids);
$peIDs = $database->fetchAll(
'select distinct pae.peID from PermissionAccessEntities pae
inner join PermissionAccessEntityTypes paet on pae.petID = paet.petID
inner join PermissionAccessEntityGroups paeg on pae.peID = paeg.peID
where petHandle = \'group_combination\'
and paeg.gID in (' . $instr . ')'
);
// Now for each one we check to see if it applies here.
foreach ($peIDs as $peID) {
$r = $database->fetchAssoc(
'select count(gID) as peGroups,
(select count(UserGroups.gID) from UserGroups where uID = ?
and gID in
(select gID from PermissionAccessEntityGroups where peID = ?))
as uGroups from PermissionAccessEntityGroups where peID = ?',
[$user->getUserID(), $peID['peID'], $peID['peID']]
);
if ($r['peGroups'] == $r['uGroups'] && $r['peGroups'] > 1) {
$entity = Entity::getByID($peID['peID']);
if (is_object($entity)) {
$entities[] = $entity;
}
}
}
}
return $entities;
} | php | public static function getAccessEntitiesForUser($user)
{
$entities = [];
// If the user isnt registered, there is no need to do this anymore.
if ($user->isRegistered()) {
$ingids = [];
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
// First look for any combos that this group would specifically be in.
// We check if the combos contain any of the groups this user is in.
// That way if there aren't any we can just skip it.
foreach ($user->getUserGroups() as $key => $val) {
$ingids[] = $key;
}
$instr = implode(',', $ingids);
$peIDs = $database->fetchAll(
'select distinct pae.peID from PermissionAccessEntities pae
inner join PermissionAccessEntityTypes paet on pae.petID = paet.petID
inner join PermissionAccessEntityGroups paeg on pae.peID = paeg.peID
where petHandle = \'group_combination\'
and paeg.gID in (' . $instr . ')'
);
// Now for each one we check to see if it applies here.
foreach ($peIDs as $peID) {
$r = $database->fetchAssoc(
'select count(gID) as peGroups,
(select count(UserGroups.gID) from UserGroups where uID = ?
and gID in
(select gID from PermissionAccessEntityGroups where peID = ?))
as uGroups from PermissionAccessEntityGroups where peID = ?',
[$user->getUserID(), $peID['peID'], $peID['peID']]
);
if ($r['peGroups'] == $r['uGroups'] && $r['peGroups'] > 1) {
$entity = Entity::getByID($peID['peID']);
if (is_object($entity)) {
$entities[] = $entity;
}
}
}
}
return $entities;
} | [
"public",
"static",
"function",
"getAccessEntitiesForUser",
"(",
"$",
"user",
")",
"{",
"$",
"entities",
"=",
"[",
"]",
";",
"// If the user isnt registered, there is no need to do this anymore.",
"if",
"(",
"$",
"user",
"->",
"isRegistered",
"(",
")",
")",
"{",
"$",
"ingids",
"=",
"[",
"]",
";",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"/** @var $database \\Concrete\\Core\\Database\\Connection\\Connection */",
"$",
"database",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"// First look for any combos that this group would specifically be in.",
"// We check if the combos contain any of the groups this user is in.",
"// That way if there aren't any we can just skip it.",
"foreach",
"(",
"$",
"user",
"->",
"getUserGroups",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"ingids",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"$",
"instr",
"=",
"implode",
"(",
"','",
",",
"$",
"ingids",
")",
";",
"$",
"peIDs",
"=",
"$",
"database",
"->",
"fetchAll",
"(",
"'select distinct pae.peID from PermissionAccessEntities pae\n inner join PermissionAccessEntityTypes paet on pae.petID = paet.petID\n inner join PermissionAccessEntityGroups paeg on pae.peID = paeg.peID\n where petHandle = \\'group_combination\\' \n and paeg.gID in ('",
".",
"$",
"instr",
".",
"')'",
")",
";",
"// Now for each one we check to see if it applies here.",
"foreach",
"(",
"$",
"peIDs",
"as",
"$",
"peID",
")",
"{",
"$",
"r",
"=",
"$",
"database",
"->",
"fetchAssoc",
"(",
"'select count(gID) as peGroups, \n (select count(UserGroups.gID) from UserGroups where uID = ? \n and gID in \n (select gID from PermissionAccessEntityGroups where peID = ?))\n as uGroups from PermissionAccessEntityGroups where peID = ?'",
",",
"[",
"$",
"user",
"->",
"getUserID",
"(",
")",
",",
"$",
"peID",
"[",
"'peID'",
"]",
",",
"$",
"peID",
"[",
"'peID'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"r",
"[",
"'peGroups'",
"]",
"==",
"$",
"r",
"[",
"'uGroups'",
"]",
"&&",
"$",
"r",
"[",
"'peGroups'",
"]",
">",
"1",
")",
"{",
"$",
"entity",
"=",
"Entity",
"::",
"getByID",
"(",
"$",
"peID",
"[",
"'peID'",
"]",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"entities",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"entities",
";",
"}"
] | Returns all GroupCombination Access Entities for the provided user.
@param \Concrete\Core\User\User | \Concrete\Core\Entity\User\User $user
@return Entity[] | array | [
"Returns",
"all",
"GroupCombination",
"Access",
"Entities",
"for",
"the",
"provided",
"user",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Access/Entity/GroupCombinationEntity.php#L53-L98 | train |
concrete5/concrete5 | concrete/src/Permission/Access/Entity/GroupCombinationEntity.php | GroupCombinationEntity.getOrCreate | public static function getOrCreate($groups)
{
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$petID = $database->fetchColumn(
'select petID from PermissionAccessEntityTypes
where petHandle = \'group_combination\''
);
$query = $database->createQueryBuilder();
$query->select('pae.peID')->from('PermissionAccessEntities', 'pae');
$i = 1;
$query->where('petid = :entityTypeID')->setParameter('entityTypeID', $petID);
foreach ($groups as $group) {
$query
->leftJoin(
'pae',
'PermissionAccessEntityGroups',
'paeg' . $i,
'pae.peID = paeg' . $i . '.peID'
)
->andWhere('paeg' . $i . '.gID = :group' . $i)
->setParameter('group' . $i, $group->getGroupID());
$i++;
}
$peIDs = $query->execute()->fetchAll();
$peID = 0;
// Check for all the groups belonging to this AccessEntity.
if (!empty($peIDs)) {
foreach ($peIDs as $result) {
$allGroups = $database->fetchColumn(
'select count(gID) from PermissionAccessEntityGroups
where peID = ' . $result['peID']
);
if ($allGroups == count($groups)) {
$peID = $result['peID'];
break;
}
}
}
// If the accessEntity doesnt exist, then create a new one.
if (empty($peID)) {
$database->insert('PermissionAccessEntities', ['petID' => $petID]);
$peID = $database->lastInsertId();
$app->make('config')->save(
'concrete.misc.access_entity_updated',
time()
);
foreach ($groups as $group) {
$database->insert(
'PermissionAccessEntityGroups',
['peID' => $peID, 'gID' => $group->getGroupID()]
);
}
}
return self::getByID($peID);
} | php | public static function getOrCreate($groups)
{
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$petID = $database->fetchColumn(
'select petID from PermissionAccessEntityTypes
where petHandle = \'group_combination\''
);
$query = $database->createQueryBuilder();
$query->select('pae.peID')->from('PermissionAccessEntities', 'pae');
$i = 1;
$query->where('petid = :entityTypeID')->setParameter('entityTypeID', $petID);
foreach ($groups as $group) {
$query
->leftJoin(
'pae',
'PermissionAccessEntityGroups',
'paeg' . $i,
'pae.peID = paeg' . $i . '.peID'
)
->andWhere('paeg' . $i . '.gID = :group' . $i)
->setParameter('group' . $i, $group->getGroupID());
$i++;
}
$peIDs = $query->execute()->fetchAll();
$peID = 0;
// Check for all the groups belonging to this AccessEntity.
if (!empty($peIDs)) {
foreach ($peIDs as $result) {
$allGroups = $database->fetchColumn(
'select count(gID) from PermissionAccessEntityGroups
where peID = ' . $result['peID']
);
if ($allGroups == count($groups)) {
$peID = $result['peID'];
break;
}
}
}
// If the accessEntity doesnt exist, then create a new one.
if (empty($peID)) {
$database->insert('PermissionAccessEntities', ['petID' => $petID]);
$peID = $database->lastInsertId();
$app->make('config')->save(
'concrete.misc.access_entity_updated',
time()
);
foreach ($groups as $group) {
$database->insert(
'PermissionAccessEntityGroups',
['peID' => $peID, 'gID' => $group->getGroupID()]
);
}
}
return self::getByID($peID);
} | [
"public",
"static",
"function",
"getOrCreate",
"(",
"$",
"groups",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"/** @var $database \\Concrete\\Core\\Database\\Connection\\Connection */",
"$",
"database",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"petID",
"=",
"$",
"database",
"->",
"fetchColumn",
"(",
"'select petID from PermissionAccessEntityTypes\n where petHandle = \\'group_combination\\''",
")",
";",
"$",
"query",
"=",
"$",
"database",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'pae.peID'",
")",
"->",
"from",
"(",
"'PermissionAccessEntities'",
",",
"'pae'",
")",
";",
"$",
"i",
"=",
"1",
";",
"$",
"query",
"->",
"where",
"(",
"'petid = :entityTypeID'",
")",
"->",
"setParameter",
"(",
"'entityTypeID'",
",",
"$",
"petID",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"query",
"->",
"leftJoin",
"(",
"'pae'",
",",
"'PermissionAccessEntityGroups'",
",",
"'paeg'",
".",
"$",
"i",
",",
"'pae.peID = paeg'",
".",
"$",
"i",
".",
"'.peID'",
")",
"->",
"andWhere",
"(",
"'paeg'",
".",
"$",
"i",
".",
"'.gID = :group'",
".",
"$",
"i",
")",
"->",
"setParameter",
"(",
"'group'",
".",
"$",
"i",
",",
"$",
"group",
"->",
"getGroupID",
"(",
")",
")",
";",
"$",
"i",
"++",
";",
"}",
"$",
"peIDs",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
")",
";",
"$",
"peID",
"=",
"0",
";",
"// Check for all the groups belonging to this AccessEntity.",
"if",
"(",
"!",
"empty",
"(",
"$",
"peIDs",
")",
")",
"{",
"foreach",
"(",
"$",
"peIDs",
"as",
"$",
"result",
")",
"{",
"$",
"allGroups",
"=",
"$",
"database",
"->",
"fetchColumn",
"(",
"'select count(gID) from PermissionAccessEntityGroups\n where peID = '",
".",
"$",
"result",
"[",
"'peID'",
"]",
")",
";",
"if",
"(",
"$",
"allGroups",
"==",
"count",
"(",
"$",
"groups",
")",
")",
"{",
"$",
"peID",
"=",
"$",
"result",
"[",
"'peID'",
"]",
";",
"break",
";",
"}",
"}",
"}",
"// If the accessEntity doesnt exist, then create a new one.",
"if",
"(",
"empty",
"(",
"$",
"peID",
")",
")",
"{",
"$",
"database",
"->",
"insert",
"(",
"'PermissionAccessEntities'",
",",
"[",
"'petID'",
"=>",
"$",
"petID",
"]",
")",
";",
"$",
"peID",
"=",
"$",
"database",
"->",
"lastInsertId",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'config'",
")",
"->",
"save",
"(",
"'concrete.misc.access_entity_updated'",
",",
"time",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"database",
"->",
"insert",
"(",
"'PermissionAccessEntityGroups'",
",",
"[",
"'peID'",
"=>",
"$",
"peID",
",",
"'gID'",
"=>",
"$",
"group",
"->",
"getGroupID",
"(",
")",
"]",
")",
";",
"}",
"}",
"return",
"self",
"::",
"getByID",
"(",
"$",
"peID",
")",
";",
"}"
] | Function used to get or create a GroupCombination Permission Access Entity.
@param Group[] $groups Groups for this combination.
@return self | [
"Function",
"used",
"to",
"get",
"or",
"create",
"a",
"GroupCombination",
"Permission",
"Access",
"Entity",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Access/Entity/GroupCombinationEntity.php#L107-L166 | train |
concrete5/concrete5 | concrete/src/Permission/Access/Entity/GroupCombinationEntity.php | GroupCombinationEntity.getAccessEntityUsers | public function getAccessEntityUsers(PermissionAccess $pa)
{
$userList = new UserList();
$userList->ignorePermissions();
foreach ($this->groups as $g) {
$userList->filterByGroupID($g->getGroupID());
}
return $userList->getResults();
} | php | public function getAccessEntityUsers(PermissionAccess $pa)
{
$userList = new UserList();
$userList->ignorePermissions();
foreach ($this->groups as $g) {
$userList->filterByGroupID($g->getGroupID());
}
return $userList->getResults();
} | [
"public",
"function",
"getAccessEntityUsers",
"(",
"PermissionAccess",
"$",
"pa",
")",
"{",
"$",
"userList",
"=",
"new",
"UserList",
"(",
")",
";",
"$",
"userList",
"->",
"ignorePermissions",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"as",
"$",
"g",
")",
"{",
"$",
"userList",
"->",
"filterByGroupID",
"(",
"$",
"g",
"->",
"getGroupID",
"(",
")",
")",
";",
"}",
"return",
"$",
"userList",
"->",
"getResults",
"(",
")",
";",
"}"
] | Get the users who have access to this GroupCombination.
@param PermissionAccess $pa
@return array | [
"Get",
"the",
"users",
"who",
"have",
"access",
"to",
"this",
"GroupCombination",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Access/Entity/GroupCombinationEntity.php#L175-L184 | train |
concrete5/concrete5 | concrete/src/Permission/Access/Entity/GroupCombinationEntity.php | GroupCombinationEntity.load | public function load()
{
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$gIDs = $database->fetchAll(
'select gID from PermissionAccessEntityGroups
where peID = ? order by gID asc',
[$this->peID]
);
if ($gIDs && is_array($gIDs)) {
for ($i = 0; $i < count($gIDs); ++$i) {
$g = Group::getByID($gIDs[$i]['gID']);
if (is_object($g)) {
$this->groups[] = $g;
$this->label .= $g->getGroupDisplayName();
if ($i + 1 < count($gIDs)) {
$this->label .= t(
/*i18n: used for combining Group Display Names,
eg GroupName1 + GroupName2 */
' + '
);
}
}
}
}
} | php | public function load()
{
$app = Facade::getFacadeApplication();
/** @var $database \Concrete\Core\Database\Connection\Connection */
$database = $app->make('database')->connection();
$gIDs = $database->fetchAll(
'select gID from PermissionAccessEntityGroups
where peID = ? order by gID asc',
[$this->peID]
);
if ($gIDs && is_array($gIDs)) {
for ($i = 0; $i < count($gIDs); ++$i) {
$g = Group::getByID($gIDs[$i]['gID']);
if (is_object($g)) {
$this->groups[] = $g;
$this->label .= $g->getGroupDisplayName();
if ($i + 1 < count($gIDs)) {
$this->label .= t(
/*i18n: used for combining Group Display Names,
eg GroupName1 + GroupName2 */
' + '
);
}
}
}
}
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"/** @var $database \\Concrete\\Core\\Database\\Connection\\Connection */",
"$",
"database",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"gIDs",
"=",
"$",
"database",
"->",
"fetchAll",
"(",
"'select gID from PermissionAccessEntityGroups\n where peID = ? order by gID asc'",
",",
"[",
"$",
"this",
"->",
"peID",
"]",
")",
";",
"if",
"(",
"$",
"gIDs",
"&&",
"is_array",
"(",
"$",
"gIDs",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"gIDs",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"g",
"=",
"Group",
"::",
"getByID",
"(",
"$",
"gIDs",
"[",
"$",
"i",
"]",
"[",
"'gID'",
"]",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"g",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"[",
"]",
"=",
"$",
"g",
";",
"$",
"this",
"->",
"label",
".=",
"$",
"g",
"->",
"getGroupDisplayName",
"(",
")",
";",
"if",
"(",
"$",
"i",
"+",
"1",
"<",
"count",
"(",
"$",
"gIDs",
")",
")",
"{",
"$",
"this",
"->",
"label",
".=",
"t",
"(",
"/*i18n: used for combining Group Display Names,\n eg GroupName1 + GroupName2 */",
"' + '",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Function used to load the properties for this
GroupCombinationEntity from the database.
@return void | [
"Function",
"used",
"to",
"load",
"the",
"properties",
"for",
"this",
"GroupCombinationEntity",
"from",
"the",
"database",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Access/Entity/GroupCombinationEntity.php#L192-L218 | train |
concrete5/concrete5 | concrete/src/Console/OutputStyle.php | OutputStyle.askWithCompletion | public function askWithCompletion($question, array $choices, $default = null, $attempts = null, $strict = false)
{
$question = new Question($question, $default);
$question->setMaxAttempts($attempts)->setAutocompleterValues($choices);
if ($strict) {
$question->setValidator(function($result) use ($choices) {
if (!in_array($result, $choices)) {
throw new \InvalidArgumentException(sprintf(
'The provided answer is ambiguous. Value should be one of %s',
implode(' or ', $choices)));
}
return $result;
});
}
return $this->askQuestion($question);
} | php | public function askWithCompletion($question, array $choices, $default = null, $attempts = null, $strict = false)
{
$question = new Question($question, $default);
$question->setMaxAttempts($attempts)->setAutocompleterValues($choices);
if ($strict) {
$question->setValidator(function($result) use ($choices) {
if (!in_array($result, $choices)) {
throw new \InvalidArgumentException(sprintf(
'The provided answer is ambiguous. Value should be one of %s',
implode(' or ', $choices)));
}
return $result;
});
}
return $this->askQuestion($question);
} | [
"public",
"function",
"askWithCompletion",
"(",
"$",
"question",
",",
"array",
"$",
"choices",
",",
"$",
"default",
"=",
"null",
",",
"$",
"attempts",
"=",
"null",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"$",
"question",
",",
"$",
"default",
")",
";",
"$",
"question",
"->",
"setMaxAttempts",
"(",
"$",
"attempts",
")",
"->",
"setAutocompleterValues",
"(",
"$",
"choices",
")",
";",
"if",
"(",
"$",
"strict",
")",
"{",
"$",
"question",
"->",
"setValidator",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"choices",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"result",
",",
"$",
"choices",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The provided answer is ambiguous. Value should be one of %s'",
",",
"implode",
"(",
"' or '",
",",
"$",
"choices",
")",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
")",
";",
"}",
"return",
"$",
"this",
"->",
"askQuestion",
"(",
"$",
"question",
")",
";",
"}"
] | Ask a question with autocompletion
@param $question
@param array $choices
@param null $default
@param null $attempts
@param bool $strict
@return string | [
"Ask",
"a",
"question",
"with",
"autocompletion"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/OutputStyle.php#L46-L64 | train |
concrete5/concrete5 | concrete/src/Console/OutputStyle.php | OutputStyle.columns | public function columns(array $values, $width = 5, $tableStyle = 'compact', array $columnStyles = [])
{
$table = new Table($this);
$table->setHeaders([])->setRows(iterator_to_array($this->chunk($values, $width)))->setStyle($tableStyle);
foreach ($columnStyles as $columnIndex => $columnStyle) {
$table->setColumnStyle($columnIndex, $columnStyle);
}
$columnWidths = $this->getColumnWidths($width);
$table->setColumnWidths($columnWidths);
$table->render();
} | php | public function columns(array $values, $width = 5, $tableStyle = 'compact', array $columnStyles = [])
{
$table = new Table($this);
$table->setHeaders([])->setRows(iterator_to_array($this->chunk($values, $width)))->setStyle($tableStyle);
foreach ($columnStyles as $columnIndex => $columnStyle) {
$table->setColumnStyle($columnIndex, $columnStyle);
}
$columnWidths = $this->getColumnWidths($width);
$table->setColumnWidths($columnWidths);
$table->render();
} | [
"public",
"function",
"columns",
"(",
"array",
"$",
"values",
",",
"$",
"width",
"=",
"5",
",",
"$",
"tableStyle",
"=",
"'compact'",
",",
"array",
"$",
"columnStyles",
"=",
"[",
"]",
")",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"this",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"[",
"]",
")",
"->",
"setRows",
"(",
"iterator_to_array",
"(",
"$",
"this",
"->",
"chunk",
"(",
"$",
"values",
",",
"$",
"width",
")",
")",
")",
"->",
"setStyle",
"(",
"$",
"tableStyle",
")",
";",
"foreach",
"(",
"$",
"columnStyles",
"as",
"$",
"columnIndex",
"=>",
"$",
"columnStyle",
")",
"{",
"$",
"table",
"->",
"setColumnStyle",
"(",
"$",
"columnIndex",
",",
"$",
"columnStyle",
")",
";",
"}",
"$",
"columnWidths",
"=",
"$",
"this",
"->",
"getColumnWidths",
"(",
"$",
"width",
")",
";",
"$",
"table",
"->",
"setColumnWidths",
"(",
"$",
"columnWidths",
")",
";",
"$",
"table",
"->",
"render",
"(",
")",
";",
"}"
] | Output in even width columns
@param array $values
@param int $width
@param string $tableStyle
@param array $columnStyles | [
"Output",
"in",
"even",
"width",
"columns"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Console/OutputStyle.php#L134-L147 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.