code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function getMutexKey() { return $this->mutexKey; }
Get the invalid mutex key. @return mixed
getMutexKey
php
concretecms/concretecms
concrete/src/System/Mutex/InvalidMutexKeyException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/InvalidMutexKeyException.php
MIT
public function __construct($mutexKey) { $this->mutexKey = (string) $mutexKey; parent::__construct(t(/*i18n: A mutex is a system object that represents a system to run code; usually this word shouldn't be translated */'The mutex with key "%s" is busy.', $this->mutexKey)); }
Initialize the instance. @param string $mutexKey The mutex key
__construct
php
concretecms/concretecms
concrete/src/System/Mutex/MutexBusyException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/MutexBusyException.php
MIT
public function getMutexKey() { return $this->mutexKey; }
Get the mutex key. @return string
getMutexKey
php
concretecms/concretecms
concrete/src/System/Mutex/MutexBusyException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/MutexBusyException.php
MIT
protected function setTemporaryDirectory($temporaryDirectory) { $this->temporaryDirectory = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $temporaryDirectory), '/'); }
Set the temporary directory. @param string $value @param mixed $temporaryDirectory
setTemporaryDirectory
php
concretecms/concretecms
concrete/src/System/Mutex/MutexTrait.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/MutexTrait.php
MIT
protected function getFilenameForMutexKey($mutexKey) { $mutexKeyString = (is_string($mutexKey) || is_int($mutexKey)) ? (string) $mutexKey : ''; if ($mutexKeyString === '') { throw new InvalidMutexKeyException($mutexKey); } if (preg_match('/^[a-zA-Z0-9_\-]{1,50}$/', $mutexKeyString)) { $filenameChunk = $mutexKeyString; } else { $filenameChunk = sha1($mutexKeyString); } return $this->temporaryDirectory . '/mutex-' . md5(DIR_APPLICATION) . '-' . $filenameChunk . '.lock'; }
Get the full path of a temporary file that's unique for the concrete5 application and for the specified mutex key. @param string $key The mutex key @param mixed $mutexKey @throws InvalidMutexKeyException @return string
getFilenameForMutexKey
php
concretecms/concretecms
concrete/src/System/Mutex/MutexTrait.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/MutexTrait.php
MIT
public function __construct($temporaryDirectory) { $this->setTemporaryDirectory($temporaryDirectory); }
Initialize the instance. @param string $temporaryDirectory the path to the temporary directory
__construct
php
concretecms/concretecms
concrete/src/System/Mutex/SemaphoreMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/SemaphoreMutex.php
MIT
public static function isSupported(Application $app) { $result = false; if (PHP_VERSION_ID >= 50601) { // we need the $nowait parameter of sem_acquire, available since PHP 5.6.1 $fi = $app->make(FunctionInspector::class); $result = $fi->functionAvailable('sem_get') && $fi->functionAvailable('sem_acquire') && $fi->functionAvailable('sem_release') & $fi->functionAvailable('ftok'); } return $result; }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::isSupported()
isSupported
php
concretecms/concretecms
concrete/src/System/Mutex/SemaphoreMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/SemaphoreMutex.php
MIT
public function acquire($key) { $filename = $this->getFilenameForMutexKey($key); for ($cycle = 1; ; ++$cycle) { $retry = false; // Let's cycle a few times to avoid concurrency problems try { if (isset($this->semaphores[$key]) && is_resource($this->semaphores[$key]) && is_file($filename)) { $statBefore = @stat($filename); $sem = $this->semaphores[$key]; } else { @touch($filename); @chmod($filename, 0666); $statBefore = @stat($filename); $semKey = @ftok($filename, 'a'); if (!is_int($semKey) || $semKey === -1) { $retry = true; // file may have been deleted in the meanwhile throw new RuntimeException("ftok() failed for path {$filename}"); } $errorDescription = ''; set_error_handler(function ($errno, $errstr) use (&$errorDescription) { $errorDescription = (string) $errstr; }); $sem = sem_get($semKey, 1); restore_error_handler(); if ($sem === false) { if (preg_match('/^sem_get\(\): failed for key 0x[A-Fa-f0-9]+: No space left on device$/', $errorDescription)) { // In case we couldn't create the semaphore because the system reached the maximum number of semaphores, // the system semget() function called by the sem_get() PHP function returns the ENOSPC error code. // Its default description is // "No space left on device" // But it's really misleading. // @see https://github.com/php/php-src/blob/php-7.3.1/ext/sysvsem/sysvsem.c#L216-L220 // @see http://man7.org/linux/man-pages/man2/semget.2.html#ERRORS // @see https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html#index-ENOSPC throw new RuntimeException("The system ran out of semaphores.\nYou have to free some semaphores, or disable semaphore-based mutex."); } throw new RuntimeException("sem_get() failed for path {$filename}: {$errorDescription}"); } } if (@sem_acquire($sem, true) !== true) { throw new MutexBusyException($key); } $statAfter = @stat($filename); if (!$statBefore || !$statAfter || $statBefore['ino'] !== $statBefore['ino']) { @sem_release($sem); $retry = true; // file may have been deleted and re-created in the meanwhile throw new RuntimeException("sem_get() failed for path {$filename}"); } } catch (RuntimeException $x) { if ($retry === true && $cycle < 5) { continue; } throw $x; } break; } $this->semaphores[$key] = $sem; }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::acquire()
acquire
php
concretecms/concretecms
concrete/src/System/Mutex/SemaphoreMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/SemaphoreMutex.php
MIT
public function release($key) { $key = (string) $key; if (isset($this->semaphores[$key])) { $sem = $this->semaphores[$key]; unset($this->semaphores[$key]); if (is_resource($sem)) { @sem_release($sem); } $filename = $this->getFilenameForMutexKey($key); if (is_file($filename)) { @unlink($filename); } } }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::release()
release
php
concretecms/concretecms
concrete/src/System/Mutex/SemaphoreMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/SemaphoreMutex.php
MIT
public function execute($key, callable $callback) { $this->acquire($key); try { $callback(); } finally { $this->release($key); } }
{@inheritdoc} @see \Concrete\Core\System\Mutex\MutexInterface::execute()
execute
php
concretecms/concretecms
concrete/src/System/Mutex/SemaphoreMutex.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/System/Mutex/SemaphoreMutex.php
MIT
public static function importDetails(SimpleXMLElement $sx) { return null; }
@param SimpleXMLElement $sx @return static|null @abstract
importDetails
php
concretecms/concretecms
concrete/src/Tree/Tree.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Tree.php
MIT
public function getRootTreeNodeObject() { return TreeNode::getByID($this->rootTreeNodeID); }
@return \Concrete\Core\Tree\Node\Node|null
getRootTreeNodeObject
php
concretecms/concretecms
concrete/src/Tree/Tree.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Tree.php
MIT
public function getNodeByDisplayPath($path) { $root = $this->getRootTreeNodeObject(); if ($path == '/' || !$path) { return $root; } $computedPath = ''; $tree = $this; $walk = function ($node, $computedPath) use (&$walk, &$tree, &$path) { $node->populateDirectChildrenOnly(); if ($node->getTreeNodeID() != $tree->getRootTreeNodeID()) { $name = $node->getTreeNodeName(); $computedPath .= '/' . $name; } if (strcasecmp($computedPath, $path) == 0) { return $node; } else { $children = $node->getChildNodes(); foreach ($children as $child) { $node = $walk($child, $computedPath); if ($node !== null) { return $node; } } } return; }; $node = $walk($root, $computedPath); return $node; }
Iterates through the segments in the path, to return the node at the proper display. Mostly used for export and import. @param $path
getNodeByDisplayPath
php
concretecms/concretecms
concrete/src/Tree/Tree.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Tree.php
MIT
final public static function getByID($treeID) { $treeID = (int) $treeID; if ($treeID === 0) { return null; } $app = app(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem('/Tree/' . $treeID); if ($item->isHit()) { return $item->get(); } } $db = $app->make(Connection::class); $row = $db->fetchAssociative('select * from Trees where treeID = ?', [$treeID]); if ($row === false) { return null; } $tt = TreeType::getByID($row['treeTypeID']); $class = $tt->getTreeTypeClass(); $tree = $app->make($class); $tree->setPropertiesFromArray($row); $tree->loadDetails(); if (isset($item)) { $cache->save($item->set($tree)); } return $tree; }
@param int|mixed $treeID @return \Concrete\Core\Tree\Tree|null
getByID
php
concretecms/concretecms
concrete/src/Tree/Tree.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Tree.php
MIT
public static function exportTranslations() { $translations = new Translations(); $loc = Localization::getInstance(); $loc->pushActiveContext(Localization::CONTEXT_SYSTEM); try { $app = Application::getFacadeApplication(); $db = $app->make('database')->connection(); $r = $db->executeQuery('select treeID from Trees order by treeID asc'); while ($row = $r->fetch()) { try { $tree = static::getByID($row['treeID']); } catch (Exception $x) { $tree = null; } if (isset($tree)) { /* @var $tree Tree */ $treeName = $tree->getTreeName(); if (is_string($treeName) && ($treeName !== '')) { $translations->insert('TreeName', $treeName); } $rootNode = $tree->getRootTreeNodeObject(); /* @var $rootNode TreeNode */ if (isset($rootNode)) { $rootNode->exportTranslations($translations); } } } } catch (Exception $x) { $loc->popActiveContext(); throw $x; } $loc->popActiveContext(); return $translations; }
Export all the translations associates to every trees. @return Translations
exportTranslations
php
concretecms/concretecms
concrete/src/Tree/Tree.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Tree.php
MIT
public function __construct(FileFolder $folder) { $this->folder = $folder; }
FolderItem constructor. @param \Concrete\Core\Tree\Node\Type\FileFolder $folder
__construct
php
concretecms/concretecms
concrete/src/Tree/Menu/Item/File/FolderItem.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Menu/Item/File/FolderItem.php
MIT
public function __construct(GroupFolder $folder) { $this->folder = $folder; }
FolderItem constructor. @param \Concrete\Core\Tree\Node\Type\GroupFolder $folder
__construct
php
concretecms/concretecms
concrete/src/Tree/Menu/Item/Group/FolderItem.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Menu/Item/Group/FolderItem.php
MIT
public function getChildNodes() { return $this->childNodes; }
Return the list of child nodes (call populateDirectChildrenOnly() before calling this method). @return static[]
getChildNodes
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function transformNode($treeNodeType) { $class = self::getClassByType($treeNodeType); $node = new $class(); $node->setPropertiesFromArray($this); return $node; }
Transforms a node to another node. @param mixed $treeNodeType
transformNode
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function getTreeNodeParentArray() { $db = app(Connection::class); $nodeArray = []; $currentNodeParentID = $this->getTreeNodeParentID(); if ($currentNodeParentID > 0) { while (is_numeric($currentNodeParentID) && $currentNodeParentID > 0 && $currentNodeParentID) { $row = $db->fetchAssoc('select treeNodeID, treeNodeParentID from TreeNodes where treeNodeID = ?', [$currentNodeParentID]); if ($row && $row['treeNodeID']) { $nodeArray[] = self::getByID($row['treeNodeID']); } $currentNodeParentID = $row['treeNodeParentID']; // moving up the tree until we hit 1 } } return $nodeArray; }
Returns an array of all parents of this tree node.
getTreeNodeParentArray
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function selectChildrenNodesByID($nodeID, $loadMissingChildren = false) { if ($this->getTreeNodeID() == $nodeID) { $this->treeNodeIsSelected = true; } else { foreach ($this->getChildNodes() as $childnode) { if ($loadMissingChildren && !$childnode->getChildNodesLoaded()) { $childnode->populateDirectChildrenOnly(); } $childnode->selectChildrenNodesByID($nodeID, $loadMissingChildren); } } }
Recursively searches for a children node and marks it as selected. @param int $nodeID ID of the children to be selected @param bool $loadMissingChildren if set to true, it will fetch, as needed, the children of the current node, that have not been loaded yet
selectChildrenNodesByID
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
protected function updateTreeNodePermissionsID(array $treeNodeParentIDs, int $newPermissionsTreeNodeID) { /** * @var $db Connection */ $db = app(Connection::class); $treeNodePermissionsID = $this->getTreeNodePermissionsNodeID(); $r = $db->createQueryBuilder() ->select('t.treeNodeID') ->from('TreeNodes', 't') ->where('t.treeNodeParentID in (:treeNodeParentIDs)') ->andWhere('t.inheritPermissionsFromTreeNodeID = :currentTreeNodePermissionsID') ->setParameter('treeNodeParentIDs', $treeNodeParentIDs, Connection::PARAM_INT_ARRAY) ->setParameter('currentTreeNodePermissionsID', $treeNodePermissionsID) ->execute(); $treeNodes = []; while ($row = $r->fetchAssociative()) { $treeNodes[] = (int) $row['treeNodeID']; } if (count($treeNodes)) { $db->createQueryBuilder() ->update('TreeNodes', 't') ->set('inheritPermissionsFromTreeNodeID', $newPermissionsTreeNodeID) ->where('t.treeNodeID in (:treeNodes)') ->setParameter('treeNodes', $treeNodes, Connection::PARAM_INT_ARRAY) ->execute(); $this->updateTreeNodePermissionsID($treeNodes, $newPermissionsTreeNodeID); } }
Set the child nodes of a list of tree nodes to inherit permissions from the specified tree node ID (provided that they previously had the same inheritance ID as this node). @param array $treeNodeParentIDs An array of tree node parent IDs to check @param int $newPermissionsTreeNodeID the ID of the new tree node the nodes should inherit permissions from
updateTreeNodePermissionsID
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function checkMove(Node $newParent) { $result = null; if ($this->getTreeNodeParentID() != $newParent->getTreeNodeID()) { if ($this->getTreeNodeID() == $newParent->getTreeNodeID()) { $result = new MoveException(t("It's not possible to move a node under itself")); } else { foreach ($newParent->getTreeNodeParentArray() as $newParentAncestor) { if ($newParentAncestor->getTreeNodeID() == $this->getTreeNodeID()) { $result = new MoveException(t("It's not possible to move a node under one of its descending nodes")); break; } } } } return $result; }
Check if this node can be moved under another parent. @param Node $newParent the new parent node @return MoveException|null return a MoveException in case of problems, null in case of success
checkMove
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function move(Node $newParent) { $error = $this->checkMove($newParent); if ($error !== null) { throw $error; } if ($this->getTreeNodeParentID() != $newParent->getTreeNodeID()) { $db = app(Connection::class); $existingDisplayOrder = $this->treeNodeDisplayOrder; $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$newParent->getTreeNodeID()]); $db->executeQuery('update TreeNodes set treeNodeParentID = ?, treeNodeDisplayOrder = ? where treeNodeID = ?', [$newParent->getTreeNodeID(), $treeNodeDisplayOrder, $this->treeNodeID]); if (!$this->overrideParentTreeNodePermissions()) { $newParentPermissionsNodeID = $newParent->getTreeNodePermissionsNodeID(); if ($newParentPermissionsNodeID != $this->getTreeNodePermissionsNodeID()) { // first we do this one $db->executeQuery('update TreeNodes set inheritPermissionsFromTreeNodeID = ? where treeNodeID = ?', [$newParentPermissionsNodeID, $this->treeNodeID]); // Now let's do it recursively down the tree $this->updateTreeNodePermissionsID([$this->treeNodeID], $newParentPermissionsNodeID); } } $oldParent = $this->getTreeNodeParentObject(); if (is_object($oldParent)) { // Instead of just rescanning all the nodes (which could take a long time), // let's just update all the nodes with display order above this one to be their current // order - 1 $db->executeQuery( 'update TreeNodes set treeNodeDisplayOrder = (treeNodeDisplayOrder - 1) where treeNodeDisplayOrder > ? and treeNodeParentID = ?', [$existingDisplayOrder, $oldParent->getTreeNodeID()] ); //$oldParent->rescanChildrenDisplayOrder(); $oldParent->updateDateModified(); } $newParent->updateDateModified(); $this->treeNodeParentID = $newParent->getTreeNodeID(); $this->treeNodeDisplayOrder = $treeNodeDisplayOrder; $newParent->clearLoadedChildren(); } }
Move this node under another node. @param Node $newParent The new parent node @throws MoveException throws a MoveException in case of errors
move
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function updateDateModified() { $dateModified = app('date')->toDB(); $db = app(Connection::class); $db->update('TreeNodes', ['dateModified' => $dateModified], ['treeNodeID' => $this->getTreeNodeID()]); }
Update the Date Modified to the current time.
updateDateModified
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public static function add($parent = false) { $db = app(Connection::class); $treeNodeParentID = 0; $treeID = 0; $treeNodeDisplayOrder = 0; $inheritPermissionsFromTreeNodeID = 0; if (is_object($parent)) { $treeNodeParentID = $parent->getTreeNodeID(); $treeID = $parent->getTreeID(); $inheritPermissionsFromTreeNodeID = $parent->getTreeNodePermissionsNodeID(); $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$treeNodeParentID]); $parent->updateDateModified(); } else { $parent = null; } $treeNodeTypeHandle = uncamelcase(strrchr(get_called_class(), '\\')); $dateModified = app('date')->toDB(); $dateCreated = app('date')->toDB(); $type = TreeNodeType::getByHandle($treeNodeTypeHandle); $db->executeQuery( 'insert into TreeNodes (treeNodeTypeID, treeNodeParentID, treeNodeDisplayOrder, inheritPermissionsFromTreeNodeID, dateModified, dateCreated, treeID) values (?, ?, ?, ?, ?, ?, ?)', [ $type->getTreeNodeTypeID(), $treeNodeParentID, $treeNodeDisplayOrder, $inheritPermissionsFromTreeNodeID, $dateModified, $dateCreated, $treeID, ] ); $id = $db->lastInsertId(); $node = self::getByID($id); if (!$inheritPermissionsFromTreeNodeID) { $node->setTreeNodePermissionsToOverride(); } if ($parent !== null && $parent->childNodesLoaded) { $parent->childNodes[] = $node; } return $node; }
Add a new node. @param Node|null|false $parent the parent node @return Node
add
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function clearLoadedChildren(): self { $this->childNodesLoaded = false; $this->childNodes = []; return $this; }
Clear the child nodes loaded by populateChildren() / populateDirectChildrenOnly(). @return $this
clearLoadedChildren
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public static function getByID($treeNodeID) { $treeNodeID = (int) $treeNodeID; if ($treeNodeID === 0) { return null; } $app = app(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem(sprintf('tree/node/%s', $treeNodeID)); if ($item->isHit()) { return $item->get(); } } $db = $app->make(Connection::class); $row = $db->fetchAssociative('select * from TreeNodes where treeNodeID = ?', [$treeNodeID]); if ($row === false) { return null; } $tt = TreeNodeType::getByID($row['treeNodeTypeID']); $node = $app->make($tt->getTreeNodeTypeClass()); $row['treeNodeTypeHandle'] = $tt->getTreeNodeTypeHandle(); $node->setPropertiesFromArray($row); $node->loadDetails(); if (isset($item)) { $cache->save($item->set($node)); } return $node; }
@param int|mixed $treeNodeID @return \Concrete\Core\Tree\Node\Node|null
getByID
php
concretecms/concretecms
concrete/src/Tree/Node/Node.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Node.php
MIT
public function transform(Node $node) { return (array) $node->getTreeNodeJSON(); }
Basic transforming of a node into an array. @param Node $node @return array
transform
php
concretecms/concretecms
concrete/src/Tree/Node/NodeTransformer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/NodeTransformer.php
MIT
public function getSite() { return app(Service::class)->getByID($this->getSiteID()); }
@deprecated Use the siteservice to resolve the site object using ->getByResultsNode(...) @return Site|null
getSite
php
concretecms/concretecms
concrete/src/Tree/Node/Type/ExpressEntrySiteResults.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/ExpressEntrySiteResults.php
MIT
public function getSiteID(): ?int { return $this->siteID; }
Get the ID of the site this node belongs to @return int|null
getSiteID
php
concretecms/concretecms
concrete/src/Tree/Node/Type/ExpressEntrySiteResults.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/ExpressEntrySiteResults.php
MIT
public function getTreeNodeStorageLocationID() { return (int) $this->fslID; }
Returns the storage location id of the folder. @return int
getTreeNodeStorageLocationID
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function getTreeNodeStorageLocationObject() { $app = Application::getFacadeApplication(); return $app->make(StorageLocationFactory::class)->fetchByID($this->getTreeNodeStorageLocationID()); }
@return \Concrete\Core\Entity\File\StorageLocation\StorageLocation
getTreeNodeStorageLocationObject
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function setTreeNodeStorageLocation($storageLocation) { if ($storageLocation instanceof \Concrete\Core\Entity\File\StorageLocation\StorageLocation) { $this->setTreeNodeStorageLocationID($storageLocation->getID()); } elseif (!is_object($storageLocation)) { $this->setTreeNodeStorageLocationID($storageLocation); } else { throw new Exception(t('Invalid file storage location.')); } }
@param \Concrete\Core\Entity\File\StorageLocation\StorageLocation|int $storageLocation Storage location object or id
setTreeNodeStorageLocation
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function setTreeNodeStorageLocationID($fslID) { $app = Application::getFacadeApplication(); $location = $app->make(StorageLocationFactory::class)->fetchByID((int) $fslID); if (!is_object($location)) { throw new Exception(t('Invalid file storage location.')); } $db = $app->make(Connection::class); $db->replace('TreeFileFolderNodes', [ 'treeNodeID' => $this->getTreeNodeID(), 'fslID' => (int) $fslID, ], ['treeNodeID'], true); $this->fslID = (int) $fslID; }
@param int $fslID Storage location id
setTreeNodeStorageLocationID
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function duplicate($parent = false) { $node = static::add($this->getTreeNodeName(), $parent, $this->getTreeNodeStorageLocationID()); $this->duplicateChildren($node); return $node; }
@param \Concrete\Core\Tree\Node\Node|bool $parent Node's parent folder @return \Concrete\Core\Tree\Node\Node
duplicate
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public static function add($treeNodeName = '', $parent = false, $storageLocationID = null) { // Get the storage location id if we have an object if (is_object($storageLocationID) && $storageLocationID instanceof \Concrete\Core\Entity\File\StorageLocation\StorageLocation) { $storageLocationID = $storageLocationID->getID(); } // If its not empty verify its a real location elseif (!empty($storageLocationID)) { $app = Application::getFacadeApplication(); $storageLocation = $app->make(StorageLocationFactory::class)->fetchByID((int) $storageLocationID); if (is_object($storageLocation)) { $storageLocationID = $storageLocation->getID(); } else { $storageLocationID = null; } } else { $storageLocationID = null; } $node = parent::add($parent); $node->setTreeNodeName($treeNodeName); // Only set storage location if we have one if (!empty($storageLocationID)) { $node->setTreeNodeStorageLocationID($storageLocationID); } return $node; }
@param string $treeNodeName Node name @param \Concrete\Core\Tree\Node\Node|bool $parent Node's parent folder @param int|\Concrete\Core\Entity\File\StorageLocation\StorageLocation|null $storageLocationID Id or object of the storage location, if null the default one will be used @return \Concrete\Core\Tree\Node\Node
add
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function getChildFolderByName($name, $create = false) { $typeHandle = $this->getTreeNodeTypeHandle(); if ($this->childNodesLoaded) { $childNodes = $this->childNodes; } else { $childNodesData = $this->getHierarchicalNodesOfType($typeHandle, 1, true, false, 1); $childNodes = array_map(function ($item) { return $item['treeNodeObject']; }, $childNodesData); } $result = null; foreach ($childNodes as $childNode) { if ($childNode->getTreeNodeTypeHandle() === $typeHandle && $childNode->getTreeNodeName() === $name) { $result = $childNode; break; } } if ($result === null && $create) { $result = static::add($name, $this); } return $result; }
Get the first child folder this folder that has a specific name. @param string $name The name of the child folder @param bool $create Should the child folder be created if it does not exist? @return static|null return NULL if no child folder has the specified name and $create is false
getChildFolderByName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function getChildFolderByPath(array $names, $create = false) { if (count($names) === 0) { $result = $this; } else { $childName = array_shift($names); $result = $this->getChildFolderByName($childName, $create); if ($result !== null) { $result = $result->getChildFolderByPath($names, $create); } } return $result; }
Get a descendent folder of this folder given its path. @param array $names The names of the child folders (1st item: child folder, 2nd item: grand-child folder, ...) @param bool $create Should the descendent folders be created if they don't exist? @return static|null return NULL if the descendent folder has not been found and $create is false
getChildFolderByPath
php
concretecms/concretecms
concrete/src/Tree/Node/Type/FileFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/FileFolder.php
MIT
public function getPermissionResponseClassName() { return '\\Concrete\\Core\\Permission\\Response\\GroupTreeNodeResponse'; }
{@inheritdoc} @see \Concrete\Core\Permission\ObjectInterface::getPermissionResponseClassName()
getPermissionResponseClassName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getPermissionAssignmentClassName() { return '\\Concrete\\Core\\Permission\\Assignment\\GroupTreeNodeAssignment'; }
{@inheritdoc} @see \Concrete\Core\Permission\ObjectInterface::getPermissionAssignmentClassName()
getPermissionAssignmentClassName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getPermissionObjectKeyCategoryHandle() { return 'group_tree_node'; }
{@inheritdoc} @see \Concrete\Core\Permission\ObjectInterface::getPermissionObjectKeyCategoryHandle()
getPermissionObjectKeyCategoryHandle
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeTypeName() { return 'Group'; }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getTreeNodeTypeName()
getTreeNodeTypeName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeMenu() { return new GroupMenu($this); }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getTreeNodeMenu()
getTreeNodeMenu
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getListFormatter() { if (count($this->getTreeNodeGroupObject()->getChildGroups()) > 0) { return new LegacyGroupFormatter(); } return new GroupFormatter(); }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getListFormatter()
getListFormatter
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeGroupObject() { if (!$this->gID) { return null; } $repository = app(GroupRepository::class); return $repository->getGroupByID($this->gID); }
@return \Concrete\Core\User\Group\Group|null
getTreeNodeGroupObject
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeName() { $group = $this->getTreeNodeGroupObject(); return $group === null ? null : $group->getGroupName(); }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getTreeNodeName()
getTreeNodeName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeDisplayName($format = 'html') { if ($this->treeNodeParentID == 0) { return t('All Groups'); } $group = $this->getTreeNodeGroupObject(); if ($group === null) { return null; } $gName = $group->getGroupDisplayName(false, false); switch ($format) { case 'html': return h($gName); case 'text': default: return $gName; } }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getTreeNodeDisplayName()
getTreeNodeDisplayName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function loadDetails() { $db = app(Connection::class); $row = $db->fetchAssociative( 'SELECT * FROM TreeGroupNodes WHERE treeNodeID = ? LIMIT 1', [$this->treeNodeID] ); if ($row !== false) { $this->setPropertiesFromArray($row); } }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::loadDetails()
loadDetails
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function move(TreeNode $newParent) { switch ($this->gID) { case GUEST_GROUP_ID: throw new UserMessageException(t("The guest users group can't be moved.")); case REGISTERED_GROUP_ID: throw new UserMessageException(t("The registered users group can't be moved.")); case ADMIN_GROUP_ID: throw new UserMessageException(t("The administrators group can't be moved.")); } parent::move($newParent); $g = $this->getTreeNodeGroupObject(); if (is_object($g)) { $g->rescanGroupPathRecursive(); } }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::move()
move
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public static function getTreeNodeByGroupID($gID) { $db = app(Connection::class); $treeNodeID = $db->fetchOne('select treeNodeID from TreeGroupNodes where gID = ?', [$gID]); return TreeNode::getByID($treeNodeID); }
@param int $gID @return \Concrete\Core\Tree\Node\Type\Group|null
getTreeNodeByGroupID
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function deleteDetails() { $db = app(Connection::class); $db->delete('TreeGroupNodes', ['treeNodeID' => $this->treeNodeID]); }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::deleteDetails()
deleteDetails
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function getTreeNodeJSON() { $obj = parent::getTreeNodeJSON(); if (!$obj) { return null; } $obj->gID = $this->gID; if (count($this->getTreeNodeGroupObject()->getChildGroups()) > 0) { $obj->icon = 'fas fa-folder'; } else { $obj->icon = 'fas fa-users'; } $group = $this->getTreeNodeGroupObject(); if ($group !== null) { foreach ($group->jsonSerialize() as $field => $value) { $obj->{$field} = $value; } $obj->title = $group->getGroupDisplayName(false, false); } if ($this->treeNodeParentID == 0) { $obj->title = t('All Groups'); } return $obj; }
{@inheritdoc} @see \Concrete\Core\Tree\Node\Node::getTreeNodeJSON()
getTreeNodeJSON
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public static function add($group = false, $parent = false) { $node = parent::add($parent); if (is_object($group)) { $node->setTreeNodeGroup($group); } return $node; }
@param \Concrete\Core\User\Group\Group|false|null $group @param \Concrete\Core\Tree\Node\Node|false|null $parent @return \Concrete\Core\Tree\Node\Type\Group
add
php
concretecms/concretecms
concrete/src/Tree/Node/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/Group.php
MIT
public function duplicate($parent = false) { $node = static::add($this->getTreeNodeName(), $parent); $this->duplicateChildren($node); return $node; }
@param TreeNode|bool $parent Node's parent folder @return TreeNode
duplicate
php
concretecms/concretecms
concrete/src/Tree/Node/Type/GroupFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/GroupFolder.php
MIT
public static function add($treeNodeName = '', $parent = false, $contains = self::CONTAINS_GROUP_FOLDERS, $selectedGroupTypes = []) { $node = parent::add($parent); $node->setTreeNodeName($treeNodeName); $node->setContains($contains); $node->setSelectedGroupTypes($selectedGroupTypes); return $node; }
@param string $treeNodeName Node name @param TreeNode|bool $parent Node's parent folder @param int $contains @param GroupType[] $selectedGroupTypes @return TreeNode|GroupFolder
add
php
concretecms/concretecms
concrete/src/Tree/Node/Type/GroupFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/GroupFolder.php
MIT
public function getChildFolderByName($name, $create = false) { $typeHandle = $this->getTreeNodeTypeHandle(); if ($this->childNodesLoaded) { $childNodes = $this->childNodes; } else { $childNodesData = $this->getHierarchicalNodesOfType($typeHandle, 1, true, false, 1); $childNodes = array_map(function ($item) { return $item['treeNodeObject']; }, $childNodesData); } $result = null; foreach ($childNodes as $childNode) { if ($childNode->getTreeNodeTypeHandle() === $typeHandle && $childNode->getTreeNodeName() === $name) { $result = $childNode; break; } } if ($result === null && $create) { $result = static::add($name, $this); } return $result; }
Get the first child folder this folder that has a specific name. @param string $name The name of the child folder @param bool $create Should the child folder be created if it does not exist? @return static|null return NULL if no child folder has the specified name and $create is false
getChildFolderByName
php
concretecms/concretecms
concrete/src/Tree/Node/Type/GroupFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/GroupFolder.php
MIT
public function getChildFolderByPath(array $names, $create = false) { if (count($names) === 0) { $result = $this; } else { $childName = array_shift($names); $result = $this->getChildFolderByName($childName, $create); if ($result !== null) { $result = $result->getChildFolderByPath($names, $create); } } return $result; }
Get a descendent folder of this folder given its path. @param array $names The names of the child folders (1st item: child folder, 2nd item: grand-child folder, ...) @param bool $create Should the descendent folders be created if they don't exist? @return static|null return NULL if the descendent folder has not been found and $create is false
getChildFolderByPath
php
concretecms/concretecms
concrete/src/Tree/Node/Type/GroupFolder.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Node/Type/GroupFolder.php
MIT
public function getTreeName() { return 'Express Entries'; }
Returns the standard name for this tree @return string
getTreeName
php
concretecms/concretecms
concrete/src/Tree/Type/ExpressEntryResults.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/ExpressEntryResults.php
MIT
public function getTreeDisplayName($format = 'html') { $value = tc('TreeName', 'Express Entries Tree'); switch ($format) { case 'html': return h($value); case 'text': default: return $value; } }
Returns the display name for this tree (localized and escaped accordingly to $format) @param string $format = 'html' Escape the result in html format (if $format is 'html'). If $format is 'text' or any other value, the display name won't be escaped. @return string
getTreeDisplayName
php
concretecms/concretecms
concrete/src/Tree/Type/ExpressEntryResults.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/ExpressEntryResults.php
MIT
public function getTreeName() { return 'File Manager'; }
Returns the standard name for this tree. @return string
getTreeName
php
concretecms/concretecms
concrete/src/Tree/Type/FileManager.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/FileManager.php
MIT
public function getTreeDisplayName($format = 'html') { $value = tc('TreeName', 'File Manager'); switch ($format) { case 'html': return h($value); case 'text': default: return $value; } }
Returns the display name for this tree (localized and escaped accordingly to $format). @param string $format = 'html' Escape the result in html format (if $format is 'html'). If $format is 'text' or any other value, the display name won't be escaped. @return string
getTreeDisplayName
php
concretecms/concretecms
concrete/src/Tree/Type/FileManager.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/FileManager.php
MIT
public static function get() { $db = Database::connection(); $treeID = $db->fetchColumn('select Trees.treeID from TreeTypes inner join Trees on TreeTypes.treeTypeID = Trees.treeTypeID where TreeTypes.treeTypeHandle = ?', ['file_manager']); return $treeID ? Tree::getByID($treeID) : null; }
Get the FileManager instance. @return FileManager|null
get
php
concretecms/concretecms
concrete/src/Tree/Type/FileManager.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/FileManager.php
MIT
public function getTreeName() { return 'Groups Tree'; }
Returns the standard name for this tree @return string
getTreeName
php
concretecms/concretecms
concrete/src/Tree/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/Group.php
MIT
public function getTreeDisplayName($format = 'html') { $value = tc('TreeName', 'Groups Tree'); switch ($format) { case 'html': return h($value); case 'text': default: return $value; } }
Returns the display name for this tree (localized and escaped accordingly to $format) @param string $format = 'html' Escape the result in html format (if $format is 'html'). If $format is 'text' or any other value, the display name won't be escaped. @return string
getTreeDisplayName
php
concretecms/concretecms
concrete/src/Tree/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/Group.php
MIT
public static function get() { $db = Database::connection(); $treeID = $db->fetchOne('SELECT Trees.treeID FROM TreeTypes INNER JOIN Trees ON TreeTypes.treeTypeID = Trees.treeTypeID WHERE TreeTypes.treeTypeHandle = ?', ['group']); return Tree::getByID($treeID); }
Get the Group instance. @return Group|null
get
php
concretecms/concretecms
concrete/src/Tree/Type/Group.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/Group.php
MIT
public function getTreeName() { return $this->topicTreeName; }
Returns the standard name for this tree @return string
getTreeName
php
concretecms/concretecms
concrete/src/Tree/Type/Topic.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/Topic.php
MIT
public function getTreeDisplayName($format = 'html') { $value = tc('TreeName', $this->topicTreeName); switch ($format) { case 'html': return h($value); case 'text': default: return $value; } }
Returns the display name for this tree (localized and escaped accordingly to $format) @param string $format = 'html' Escape the result in html format (if $format is 'html'). If $format is 'text' or any other value, the display name won't be escaped. @return string
getTreeDisplayName
php
concretecms/concretecms
concrete/src/Tree/Type/Topic.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Tree/Type/Topic.php
MIT
public function getUpdateVersion() { return $this->version; }
Returns the version string. @return string
getUpdateVersion
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
public function getUpdateIdentifier() { return $this->identifier; }
Returns the version identifier (equals to the name of the directory under the updates directory). @return string
getUpdateIdentifier
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
public static function getByVersionNumber($version) { $updates = id(new Update())->getLocalAvailableUpdates(); foreach ($updates as $up) { if ($up->getUpdateVersion() == $version) { return $up; } } }
Returns an ApplicationUpdate instance given its version string. @param string $version @return ApplicationUpdate|null Returns null if there's no update with $version, or an ApplicationUpdate instance if $version is ok
getByVersionNumber
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
public function apply() { $updates = []; $update_file = DIR_CONFIG_SITE . '/update.php'; if (file_exists($update_file)) { if (!is_writable($update_file)) { return self::E_UPDATE_WRITE_CONFIG; } $updates = (array) include $update_file; } $updates['core'] = $this->getUpdateIdentifier(); \Config::clear('concrete.version'); $renderer = new Renderer($updates); file_put_contents($update_file, $renderer->render()); OpCache::clear($update_file); return true; }
Writes the core pointer into config/update.php. @return true|int Returns true if the configuration file was updated, otherwise it returns the error code (one of the ApplicationUpdate::E_... constants)
apply
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
public static function get($dir) { $version_file = DIR_CORE_UPDATES . "/{$dir}/" . DIRNAME_CORE . '/config/concrete.php'; $concrete = is_file($version_file) ? @include $version_file : null; if (is_array($concrete) && !empty($concrete['version'])) { $obj = new self(); $obj->version = $concrete['version']; $obj->identifier = $dir; return $obj; } }
Parse an update dir and returns an ApplicationUpdate instance. @param string $dir The base name of the directory under the updates directory @return ApplicationUpdate|null Returns null if there's no update in the $dir directory, or an ApplicationUpdate instance if $dir is ok
get
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
public function getDiagnosticObject() { $app = Application::getFacadeApplication(); $formData = [ 'current_version' => Config::get('concrete.version_installed'), 'requested_version' => $this->getVersion(), 'site_url' => (string) \Core::getApplicationURL() ]; $packageRepository = $app->make(PackageRepositoryInterface::class); $connection = $packageRepository->getConnection(); if ($connection && $packageRepository->validate($connection)) { $config = \Core::make('config/database'); $formData['marketplace_token'] = $config->get('concrete.marketplace.token'); $list = Package::getInstalledList(); $packages = []; foreach ($list as $pkg) { $packages[] = ['version' => $pkg->getPackageVersion(), 'handle' => $pkg->getPackageHandle()]; } $formData['packages'] = $packages; } $info = \Core::make('\Concrete\Core\System\Info'); $overrides = $info->getOverrideList(); $info = $info->getJSONOBject(); $formData['overrides'] = $overrides; $formData['environment'] = json_encode($info); $client = $app->make('http/client'); $response = $client->post(Config::get('concrete.updates.services.inspect_update'), [ 'form_params' => $formData ]); $body = $response->getBody()->getContents(); return DiagnosticFactory::getFromJSON($body); }
Given the current update object, sends information to concrete5.org to determine updatability. @return \Concrete\Core\Updater\ApplicationUpdate\Diagnostic
getDiagnosticObject
php
concretecms/concretecms
concrete/src/Updater/ApplicationUpdate.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/ApplicationUpdate.php
MIT
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.
uploadZipToTemp
php
concretecms/concretecms
concrete/src/Updater/Archive.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Archive.php
MIT
protected function unzip($directory) { $file = $directory . '.zip'; $zip = new \ZipArchive(); if ($zip->open($this->f->getTemporaryDirectory() . '/' . $file) === true) { $zip->extractTo($this->f->getTemporaryDirectory() . '/' . $directory . '/'); $zip->close(); return $this->f->getTemporaryDirectory() . '/' . $directory; } }
Unzips a file at a directory level by concatenating ".zip" onto the end of it. <code> unzip("/path/to/files/themes/mytheme") // will unzip "mytheme.zip" </code>. @param string $directory The base name of the file (without extension, assumed to be in the the temporary directory). @return string Return the full path of the extracted directory.
unzip
php
concretecms/concretecms
concrete/src/Updater/Archive.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Archive.php
MIT
protected function getArchiveDirectory($dir) { $files = $this->f->getDirectoryContents($dir); // strip out items in directories that we know aren't valid if (count($files) == 1 && is_dir($dir . '/' . $files[0])) { return $dir . '/' . $files[0]; } else { return $dir; } }
Returns either the directory (if the archive itself contains files at the first level) or the subdirectory if, like many archiving programs, we the zip archive is a directory, THEN a list of files. @param string $dir The full path of the directory to be analyzed. @return string Returns the final directory containing the files to be used.
getArchiveDirectory
php
concretecms/concretecms
concrete/src/Updater/Archive.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Archive.php
MIT
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
install
php
concretecms/concretecms
concrete/src/Updater/Archive.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Archive.php
MIT
public static function getLatestAvailableVersionNumber() { $app = Application::getFacadeApplication(); $config = $app->make('config'); // first, we check session $queryWS = false; Cache::disableAll(); $vNum = $config->get('concrete.misc.latest_version', true); Cache::enableAll(); $versionNum = null; if (is_object($vNum)) { $seconds = strtotime($vNum->timestamp); $version = $vNum->value; if (is_object($version)) { $versionNum = $version->version; } else { $versionNum = $version; } $diff = time() - $seconds; if ($diff > $config->get('concrete.updates.check_threshold')) { // we grab a new value from the service $queryWS = true; } } else { $queryWS = true; } if ($queryWS) { $packageRepository = $app->make(PackageRepositoryInterface::class); $skip = $config->get('concrete.updates.skip_packages'); if ($skip !== true) { $packageService = $app->make(PackageService::class); $packageService->checkPackageUpdates($packageRepository, (array) $skip); } $update = static::getLatestAvailableUpdate(); $versionNum = null; if (is_object($update)) { $versionNum = $update->getVersion(); } if ($versionNum) { $config->save('concrete.misc.latest_version', $versionNum); } else { // we don't know so we're going to assume we're it $config->save('concrete.misc.latest_version', APP_VERSION); } } return $versionNum; }
Fetch from the remote marketplace the latest available versions of the core and the packages. These operations are done only the first time or after at least APP_VERSION_LATEST_THRESHOLD seconds since the previous check. @return string|null Returns the latest available core version (eg. '5.7.3.1'). If we can't retrieve the latest version and if this never succeeded previously, this function returns null
getLatestAvailableVersionNumber
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
public static function getApplicationUpdateInformation() { $app = Application::getFacadeApplication(); $cache = $app->make('cache'); $r = $cache->getItem('APP_UPDATE_INFO'); if ($r->isMiss()) { $r->lock(); $result = static::getLatestAvailableUpdate(); $r->set($result)->save(); } else { $result = $r->get(); } return $result; }
Retrieves the info about the latest available information. The effective request to the remote server is done just once per request. @return RemoteApplicationUpdate|null
getApplicationUpdateInformation
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
public function getLocalAvailableUpdates() { $app = Application::getFacadeApplication(); $fh = $app->make('helper/file'); $updates = []; $contents = @$fh->getDirectoryContents(DIR_CORE_UPDATES); foreach ($contents as $con) { if (is_dir(DIR_CORE_UPDATES . '/' . $con)) { $obj = ApplicationUpdate::get($con); if (is_object($obj)) { if (version_compare($obj->getUpdateVersion(), APP_VERSION, '>')) { $updates[] = $obj; } } } } usort( $updates, function ($a, $b) { return version_compare($a->getUpdateVersion(), $b->getUpdateVersion()); } ); return $updates; }
Looks in the designated updates location for all directories, ascertains what version they represent, and finds all versions greater than the currently installed version of concrete5. @return ApplicationUpdate[]
getLocalAvailableUpdates
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
public static function isCurrentVersionNewerThanDatabaseVersion() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $config = $app->make('config'); $database = $db->fetchColumn('select max(version) from SystemDatabaseMigrations'); $code = $config->get('concrete.version_db'); return $database < $code; }
Checks migrations to see if the current code DB version is greater than that registered in the database.
isCurrentVersionNewerThanDatabaseVersion
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
public static function updateToCurrentVersion(?Configuration $configuration = null) { $app = Application::getFacadeApplication(); $functionInspector = $app->make(FunctionInspector::class); if (!$app->isRunThroughCommandLineInterface()) { if ($functionInspector->functionAvailable('ignore_user_abort')) { // Don't abort the script execution when the web client disconnects, // otherwise we risk to halt the execution in the middle of a migration. @ignore_user_abort(true); } } $canSetTimeLimit = $functionInspector->functionAvailable('set_time_limit'); $defaultTimeLimit = null; if ($functionInspector->functionAvailable('ini_get')) { $defaultTimeLimit = @ini_get('max_execution_time'); if ($app->make(Numbers::class)->integer($defaultTimeLimit)) { $defaultTimeLimit = (int) $defaultTimeLimit; } else { $defaultTimeLimit = null; } } $config = $app->make('config'); $command = new ClearCacheCommand(); $command->setClearGlobalAreas(false); $app->executeCommand($command); $em = $app->make(EntityManagerInterface::class); $dbm = new DatabaseStructureManager($em); $dbm->destroyProxyClasses('ConcreteCore'); $dbm->generateProxyClasses(); // Refresh those entities and database tables that are so potentially wide-reaching and problematic // That they _have_ to be checked prior to upgrade $tool = new SchemaTool($em); $entityClasses = []; foreach ([Site::class] as $entity) { $entityClasses[] = $em->getClassMetadata($entity); } $tool->updateSchema($entityClasses, true); if (!$configuration) { $configuration = new Configuration(); } $configuration->registerPreviousMigratedVersions(); $isRerunning = $configuration->getForcedInitialMigration() !== null; $migrationVersions = $configuration->getMigrationsToExecute('up', $configuration->getLatestVersion()); $totalMigrations = count($migrationVersions); $performedMigrations = 0; foreach ($migrationVersions as $migrationVersion) { $migration = $migrationVersion->getMigration(); if ($defaultTimeLimit !== 0) { // The current execution time is not unlimited $timeLimitSet = $canSetTimeLimit ? @set_time_limit(max((int) $defaultTimeLimit, 300)) : false; if (!$timeLimitSet && $performedMigrations > 0) { // We are not able to reset the execution time limit if ($performedMigrations > 10 || $migration instanceof Migrations\LongRunningMigrationInterface) { // If we have done 10 migrations, or if the next migration requires long time throw new Migrations\MigrationIncompleteException($performedMigrations, $totalMigrations - $performedMigrations); } } } $configuration->getOutputWriter()->write(t('** Executing migration: %s', $migrationVersion->getVersion())); if ($isRerunning && $migrationVersion->isMigrated()) { $migrationVersion->markNotMigrated(); $migrated = false; try { $migrationVersion->execute('up'); $migrated = true; } finally { if (!$migrated) { try { $migrationVersion->markMigrated(); } catch (Exception $x) { } } } } else { $migrationVersion->execute('up'); } ++$performedMigrations; if ($defaultTimeLimit !== 0 && !$timeLimitSet && $migration instanceof Migrations\LongRunningMigrationInterface) { // The current execution time is not unlimited, we are unable to reset the time limit, and the performed migration took long time if ($performedMigrations < $totalMigrations) { throw new Migrations\MigrationIncompleteException($performedMigrations, $totalMigrations - $performedMigrations); } } } try { $app->make('helper/file')->makeExecutable(DIR_BASE_CORE . '/bin/concrete5', 'all'); $app->make('helper/file')->makeExecutable(DIR_BASE_CORE . '/bin/concrete', 'all'); } catch (Exception $x) { } $config->save('concrete.version_installed', $config->get('concrete.version')); $config->save('concrete.version_db_installed', $config->get('concrete.version_db')); $textIndexes = $app->make('config')->get('database.text_indexes'); $app->make(Connection::class)->createTextIndexes($textIndexes); }
Upgrade the current core version to the latest locally available by running the applicable migrations. @param null|Configuration $configuration @throws \Concrete\Core\Updater\Migrations\MigrationIncompleteException throws a MigrationIncompleteException exception if there's still some migration pending
updateToCurrentVersion
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
protected static function getLatestAvailableUpdate() { $app = Application::getFacadeApplication(); $config = $app->make('config'); /** * @var $inspector Inspector */ $inspector = $app->make(Inspector::class); try { $fields = [ $inspector->getUsersField(), $inspector->getPrivilegedUsersField(), $inspector->getSitesField(), $inspector->getPackagesField(), $inspector->getLocaleField(), ]; $command = new UpdateRemoteDataCommand($fields); $app->executeCommand($command); $appVersion = $config->get('concrete.version_installed'); $formParams = [ 'APP_VERSION' => $appVersion, ]; $response = $app->make('http/client')->post($config->get('concrete.updates.services.get_available_updates'), ['form_params' => $formParams] ); $update = RemoteApplicationUpdateFactory::getFromJSON($response->getBody()->getContents()); } catch (Exception $x) { $update = null; } return $update; }
Retrieves the info about the latest available information. @return RemoteApplicationUpdate|null
getLatestAvailableUpdate
php
concretecms/concretecms
concrete/src/Updater/Update.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Update.php
MIT
public function install($file, $inplace = true) { parent::install($file, $inplace); }
{@inheritdoc} @see \Concrete\Core\Updater\Archive::install()
install
php
concretecms/concretecms
concrete/src/Updater/UpdateArchive.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/UpdateArchive.php
MIT
final public function up(Schema $schema): void { $this->upgradeSchema($schema); }
{@inheritdoc} @see \Doctrine\Migrations\AbstractMigration::up()
up
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
final public function postUp(Schema $schema): void { $this->upgradeDatabase(); }
{@inheritdoc} @see \Doctrine\Migrations\AbstractMigration::postUp()
postUp
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
final public function down(Schema $schema): void { $this->downgradeSchema($schema); }
{@inheritdoc} @see \Doctrine\Migrations\AbstractMigration::down()
down
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
final public function postDown(Schema $schema): void { $this->downgradeDatabase(); }
{@inheritdoc} @see \Doctrine\Migrations\AbstractMigration::postDown()
postDown
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
protected function nullifyInvalidForeignKey($table, $field, $linkedTable, $linkedField) { $platform = $this->connection->getDatabasePlatform(); $sqlTable = $platform->quoteSingleIdentifier($table); $sqlField = $platform->quoteSingleIdentifier($field); $sqlLinkedTable = $platform->quoteSingleIdentifier($linkedTable); $sqlLinkedField = $platform->quoteSingleIdentifier($linkedField); $this->connection->executeQuery(" update {$sqlTable} left join {$sqlLinkedTable} on {$sqlTable}.{$sqlField} = {$sqlLinkedTable}.{$sqlLinkedField} set {$sqlTable}.{$sqlField} = null where {$sqlLinkedTable}.{$sqlLinkedField} is null "); }
Set to NULL the fields in a table that reference not existing values of another table. @param string $table The table containing the problematic field @param string $field The problematic field @param string $linkedTable The referenced table @param string $linkedField The referenced field
nullifyInvalidForeignKey
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
protected function deleteInvalidForeignKey($table, $field, $linkedTable, $linkedField) { $platform = $this->connection->getDatabasePlatform(); $sqlTable = $platform->quoteSingleIdentifier($table); $sqlField = $platform->quoteSingleIdentifier($field); $sqlLinkedTable = $platform->quoteSingleIdentifier($linkedTable); $sqlLinkedField = $platform->quoteSingleIdentifier($linkedField); $this->connection->executeQuery(" delete {$sqlTable} from {$sqlTable} left join {$sqlLinkedTable} on {$sqlTable}.{$sqlField} = {$sqlLinkedTable}.{$sqlLinkedField} where {$sqlLinkedTable}.{$sqlLinkedField} is null "); }
Delete the records in a table whose field references not existing values of another table. @param string $table The table containing the problematic field @param string $field The problematic field @param string $linkedTable The referenced table @param string $linkedField The referenced field
deleteInvalidForeignKey
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
protected function createSinglePage($path, $name = '', array $attributes = [], $global = false) { $sp = Page::getByPath($path); if (!is_object($sp) || $sp->isError()) { if ($global ) { $this->output(t('Creating global single page at %s...', $path)); $sp = SinglePage::addGlobal($path); } else { $this->output(t('Creating single page at %s...', $path)); $sp = SinglePage::add($path); } $update = []; $name = (string) $name; if ($name !== '') { $update['cName'] = $name; } if (array_key_exists('cDescription', $attributes)) { $description = (string) $attributes['cDescription']; unset($attributes['cDescription']); if ($description !== '') { $update['cDescription'] = $description; } } if (count($update) > 0) { $sp->update($update); } foreach ($attributes as $attributeHandle => $attributeValue) { if ($this->isAttributeHandleValid(PageCategory::class, $attributeHandle)) { $sp->setAttribute($attributeHandle, $attributeValue); } } } return $sp; }
Create a new SinglePage (if it does not exist). @param string $path the single page path @param string $name the single page name @param array $attributes the attribute values (keys are the attribute handles, values are the attribute values) @return \Concrete\Core\Page\Page
createSinglePage
php
concretecms/concretecms
concrete/src/Updater/Migrations/AbstractMigration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/AbstractMigration.php
MIT
public function __construct($registerMigrations = true) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); parent::__construct($db); $directory = DIR_BASE_CORE . '/' . DIRNAME_CLASSES . '/Updater/Migrations/Migrations'; $this->setName(t('Concrete Migrations')); $this->setMigrationsNamespace('Concrete\Core\Updater\Migrations\Migrations'); $this->setMigrationsDirectory($directory); if ($registerMigrations) { $this->registerMigrationsFromDirectory($directory); } $this->setMigrationsTableName('SystemDatabaseMigrations'); }
Construct a migration configuration object. @param bool $registerMigrations set to true to load the currently available migrations
__construct
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
public function forceMaxInitialMigration() { $forcedInitialMigration = null; foreach (array_reverse($this->getMigrations()) as $migration) { /* @var \Doctrine\Migrations\Version $migration */ if ($migration->isMigrated() && !$migration->getMigration() instanceof RepeatableMigrationInterface) { break; } $forcedInitialMigration = $migration; } $this->forcedInitialMigration = $forcedInitialMigration; }
Force the initial migration to be the least recent repeatable one.
forceMaxInitialMigration
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
public function forceInitialMigration($reference, $criteria = self::FORCEDMIGRATION_INCLUSIVE) { $reference = trim((string) $reference); if ($reference === '') { throw new Exception(t('Invalid initial migration reference.')); } if (!in_array($criteria, [static::FORCEDMIGRATION_INCLUSIVE, static::FORCEDMIGRATION_EXCLUSIVE], true)) { throw new Exception(t('Invalid initial migration criteria.')); } // Remove possible 'Version' prefix from the migration identifier. // This allows a user to also use VersionXXXXXXXXXXXX, which corresponds with the class name. $reference = str_replace('Version', '', $reference); $migration = $this->findInitialMigration($reference, $criteria); if ($migration === null) { throw new Exception(t('Unable to find a migration with identifier %s', $reference)); } $this->forcedInitialMigration = $migration; }
Force the initial migration, using a specific point. @param string $reference A Concrete version (eg. '8.3.1') or a migration identifier (eg '20171218000000') @param string $criteria One of the FORCEDMIGRATION_... constants
forceInitialMigration
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
public function getForcedInitialMigration() { return $this->forcedInitialMigration; }
Get the forced initial migration (if set). @return \Doctrine\DBAL\Migrations\Version|null
getForcedInitialMigration
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
public function registerPreviousMigratedVersions() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); try { $minimum = $db->fetchColumn('select min(version) from SystemDatabaseMigrations'); } catch (Exception $e) { return; } $migrations = $this->getMigrations(); $keys = array_keys($migrations); if ($keys[0] == $minimum) { // This is the first migration in Concrete. That means we have already populated this table. return; } else { // We have to populate this table with all the migrations from the very first migration up to // the $minMigration foreach ($migrations as $key => $migration) { if ($key < $minimum) { $migration->markMigrated(); } } } }
This is a stupid requirement, but basically, we grab the lowest version number in our system database migrations table, and we loop through all migrations in our file system and for any of those LOWER than the lowest one in the table, we can assume they are included in this migration. We then manually insert these rows into the SystemDatabaseMigrations table so Doctrine isn't stupid and attempt to apply them.
registerPreviousMigratedVersions
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
public function getMigrationsToExecute(string $direction, string $to): array { $result = parent::getMigrationsToExecute($direction, $to); $forcedInitialMigration = $this->getForcedInitialMigration(); if ($forcedInitialMigration !== null && $direction === 'up') { $allMigrations = $this->getMigrations(); $allMigrationKeys = array_keys($allMigrations); $forcedInitialMigrationIndex = array_search($forcedInitialMigration->getVersion(), $allMigrationKeys, false); if ($forcedInitialMigrationIndex === false) { // This should never occur throw new Exception(t('Unable to find the forced migration with version %s', $forcedInitialMigration->getVersion())); } $forcedMigrationKeys = array_slice($allMigrationKeys, $forcedInitialMigrationIndex); $forcedMigrations = []; foreach (array_reverse($forcedMigrationKeys) as $forcedMigrationKey) { $migration = $allMigrations[$forcedMigrationKey]; if ($migration->isMigrated() && !$migration->getMigration() instanceof RepeatableMigrationInterface) { throw new Exception(t('The migration %s has already been executed, and can\'t be executed again.', $migration->getVersion())); } $forcedMigrations[$forcedMigrationKey] = $migration; } $forcedMigrations = array_reverse($forcedMigrations, true); $missingMigrations = array_diff_key($result, $forcedMigrations); if (count($missingMigrations) > 0) { throw new Exception(t('The forced migration is later than the one to be executed (%s)', reset($missingMigrations)->getVersion())); } $result = $forcedMigrations; } return $result; }
{@inheritdoc} @see \Doctrine\Migrations\Configuration\Configuration::getMigrationsToExecute()
getMigrationsToExecute
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
protected function findInitialMigration($reference, $criteria) { return preg_match('/^' . str_repeat('\d', strlen('YYYYMMDDhhmmss')) . '$/', $reference) ? $this->findInitialMigrationByIdentifier($reference, $criteria) : $this->findInitialMigrationByCoreVersion($reference, $criteria); }
Get the initial migration given a reference (in form YYYYMMDDhhmmss or as a core version). @param string $reference The migration reference @param string $criteria One of the FORCEDMIGRATION_... constants @throws Exception throws an Exception if $criteria is not valid @return \Doctrine\DBAL\Migrations\Version|null
findInitialMigration
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT
protected function findInitialMigrationByIdentifier($identifier, $criteria) { switch ($criteria) { case static::FORCEDMIGRATION_INCLUSIVE: if ($this->hasVersion($identifier)) { $result = $this->getVersion($identifier); } else { $result = null; } break; case static::FORCEDMIGRATION_EXCLUSIVE: $allIdentifiers = array_keys($this->getMigrations()); $migrationIndex = array_search($identifier, $allIdentifiers, false); if ($migrationIndex === false) { $result = null; } elseif ($migrationIndex === count($allIdentifiers) - 1) { $result = null; } else { $result = $this->getVersion($allIdentifiers[$migrationIndex + 1]); } break; default: throw new Exception(t('Invalid initial migration criteria.')); } return $result; }
Get the initial migration starting from its identifier (in form YYYYMMDDhhmmss). @param string $identifier The migration identifier @param string $criteria One of the FORCEDMIGRATION_... constants @throws Exception throws an Exception if $criteria is not valid @return \Doctrine\DBAL\Migrations\Version|null
findInitialMigrationByIdentifier
php
concretecms/concretecms
concrete/src/Updater/Migrations/Configuration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Updater/Migrations/Configuration.php
MIT