method history documentation in bbn\Appui\Ide

Returns all backups of a file.

function(string $url, array $repository = [], bool $all = false) { $check_ctrl = false; $copy_url = explode("/", $url); $backups = []; $history_ctrl = []; if (!empty($repository) && !empty($repository['name'])) { $path = self::$backup_path . $repository['root'] . '/' . substr($url, Strpos($url, $repository['code'], 1)); } else { // File's backup path $path = self::$backup_path . $url; } if (!empty($url) && !empty(self::$backup_path)) { $ctrl_path = explode("/", $path); for ($y = 0; $y < 2; $y++) { array_pop($ctrl_path); } //check if there is "_ctrl" in the url as the last step of the "$url"; in that case we tart $url to give the right path to get it to take its own backup files. if (end($copy_url) === "_ctrl") { $url = explode("/", $url); array_pop($url); $url = implode("/", $url); $check_ctrl_files = true; $copy_url = explode("/", $url); for ($y = 0; $y < 2; $y++) { array_pop($copy_url); } $copy_url = implode("/", $copy_url) . "/" . "_ctrl"; } //First, check the presence of _ctrl backups. $ctrl_path = implode("/", $ctrl_path) . "/" . "_ctrl"; // read _ctrl if exsist if ($this->fs->isDir($ctrl_path)) { //If there is a "_ctrl" backup, insert it into the array that will be merged with the remaining backup at the end of the function. if ($files_ctrl = $this->fs->getFiles($ctrl_path)) { $mode = X::basename($ctrl_path); $history_ctrl = [ 'text' => X::basename($ctrl_path), 'icon' => 'folder-icon', 'folder' => true, 'items' => [], 'num_items' => \count($this->fs->getFiles($ctrl_path)) //'num_items' => \count(\bbn\File\Dir::getFiles($files_ctrl)) ]; //If we are requesting all files with their contents, this block returns to the "_ctrl" block. if ($all === true) { foreach ($files_ctrl as $file) { $filename = Str::fileExt($file, true)[0]; $file_name = $filename; $moment = strtotime(str_replace('_', ' ', $filename)); $date = date('d/m/Y', $moment); $dir = date('Y/m/d', $moment); $time = date('H:i:s', $moment); if (($i = \bbn\X::find($history_ctrl['items'], ['text' => $date])) === null) { array_push( $history_ctrl['items'], [ 'text' => $date, 'items' => [], 'folder' => true, 'icon' => 'folder-icon' ] ); $i = \count($history_ctrl['items']) - 1; if (($idx = \bbn\X::find($history_ctrl['items'][$i]['items'], ['text' => $time])) === null) { array_push( $history_ctrl['items'][$i]['items'], [ 'text' => $time, 'mode' => X::basename($ctrl_path), 'file' => $file_name, 'ext' => Str::fileExt($file, true)[1], 'uid' => $url, 'folder' => false ] ); } } else { $j = \bbn\X::find($history_ctrl['items'], ['text' => $date]); if (($idx = \bbn\X::find($history_ctrl['items'][$j]['items'], ['text' => $time])) === null) { array_push( $history_ctrl['items'][$j]['items'], [ 'text' => $time, 'code' => $this->fs->getContents($file), 'folder' => false, 'mode' => X::basename($ctrl_path), 'folder' => false ] ); } } } } //otherwise pass some useful parameters to get information with other posts see block in case of "$all" to false. else { $check_ctrl = true; } } } //taken or not the backup of the "_ctrl" we move on to acquire the date of the project, if set to true then as done before, we will take into consideration all the date including the contents of the files. if ($all === true) { //if ( is_dir($path) ){ if ($this->fs->isDir($path)) { //if we pass a path that contains all the backups if ($dirs = $this->fs->getDirs($path)) { if (!empty($dirs)) { $basepath = X::basename($path); $mode = $basepath === "_ctrl" || ($basepath === "model") ? "php" : $basepath; foreach ($dirs as $dir) { //if ( $files = \bbn\File\Dir::getFiles($dir) ){ if ($files = $this->fs->getFiles($dir)) { foreach ($files as $file) { $filename = Str::fileExt($file, true)[0]; $moment = strtotime(str_replace('_', ' ', $filename)); $date = date('d/m/Y', $moment); $time = date('H:i:s', $moment); if (($i = \bbn\X::find($backups, ['text' => $date])) === null) { array_push( $backups, [ 'text' => $date, 'folder' => true, 'items' => [], 'icon' => 'folder-icon' ] ); $i = \count($backups) - 1; } if (($idx = \bbn\X::find($backups[$i]['items'], ['title' => $d])) === null) { array_push( $backups[$i]['items'], [ 'text' => $d, 'folder' => true, 'items' => [], 'icon' => 'folder-icon' ] ); $idx = \count($backups[$i]['items']) - 1; } array_push( $backups[$i]['items'][$idx]['items'], [ 'text' => $time, 'mode' => $mode, 'code' => $this->fs->getContents($file), 'folder' => false ] ); } } } } } //If we pass a path that contains the specific backups of a type and is set to "$all" to true then all backups of this type will return. else { if ($files = $this->fs->getFiles($path)) { if (!empty($files)) { $basepath = X::basename($path); $mode = ($basepath === "_ctrl") || ($basepath === "model") ? "php" : $basepath; foreach ($files as $file) { $filename = Str::fileExt($file, true)[0]; $file_name = $filename; $moment = strtotime(str_replace('_', ' ', $filename)); $date = date('d/m/Y', $moment); $time = date('H:i:s', $moment); if (($i = \bbn\X::find($backups, ['text' => $date])) === null) { array_push( $backups, [ 'text' => $date, 'folder' => true, 'items' => [], 'icon' => 'folder-icon' ] ); $i = \count($backups) - 1; if (($idx = \bbn\X::find($backups[$i]['items'], ['text' => $time])) === null) { array_push( $backups[$i]['items'], [ 'text' => $time, 'mode' => $mode, 'code' => $this->fs->getContents($file), 'folder' => false ] ); } } else { $j = \bbn\X::find($backups, ['text' => $date]); if (($idx = \bbn\X::find($backups[$j]['items'], ['text' => $time])) === null) { array_push( $backups[$j]['items'], [ 'text' => $time, 'mode' => $mode, 'code' => $this->fs->getContents($file), 'folder' => false ] ); } } } } } } } } //otherwise returns the useful information for processing and to make any subsequent postings. else { //if we want you to return all the backup information useful to process and make other posts $listDir = $this->fs->getDirs($path); if (!empty($listDir) && !isset($check_ctrl_files)) { foreach ($listDir as $val) { array_push( $backups, [ 'text' => X::basename($val), 'icon' => 'folder-icon', 'folder' => true, //'num_items' => \count(\bbn\File\Dir::getFiles($val)) 'num_items' => \count($this->fs->getFiles($val)) ] ); } //If the _ctrl backup folder exists, then it will be added to the list. if ($check_ctrl === true) { array_push($backups, $history_ctrl); } } //If we pass a path that contains the specific backups of a type and is not set "$all" then the backup of with useful information for any other posts returns. else { //If we are requesting ctrl backup files then we give it the right path and "$check_ctrl_files" is a variable that makes us understand whether or not we ask for backup files of "_ctrl". if (isset($check_ctrl_files) && ($check_ctrl_files === true)) { $url = $copy_url; $path = self::$backup_path . $url; } //if ( $files = \bbn\File\Dir::getFiles($path) ){ if ($files = $this->fs->getFiles($path)) { if (!empty($files)) { $basepath = X::basename($path); $mode = ($basepath === "_ctrl") || ($basepath === "model") ? "php" : $basepath; foreach ($files as $file) { if (Str::fileExt($file, true)[1] !== 'json') { $filename = Str::fileExt($file, true)[0]; $file_name = $filename; $moment = strtotime(str_replace('_', ' ', $filename)); $date = date('d/m/Y', $moment); $time = date('H:i:s', $moment); if (($i = \bbn\X::find($backups, ['text' => $date])) === null) { array_push( $backups, [ 'text' => $date, 'folder' => true, 'items' => [], 'icon' => 'folder-icon' ] ); $i = \count($backups) - 1; if (($idx = \bbn\X::find($backups[$i]['items'], ['text' => $time])) === null) { array_push( $backups[$i]['items'], [ 'text' => $time, 'mode' => $mode, 'file' => $file_name, 'ext' => Str::fileExt($file, true)[1], 'uid' => $url, 'folder' => false ] ); } } else { $j = \bbn\X::find($backups, ['text' => $date]); if (($idx = \bbn\X::find($backups[$j]['items'], ['text' => $time])) === null) { array_push( $backups[$j]['items'], [ 'text' => $time, 'mode' => $mode, 'file' => $file_name, 'ext' => Str::fileExt($file, true)[1], 'uid' => $url, 'folder' => false ] ); } } } } } } } } } //If you add the "_ctrl " backup, enter it to the rest of the date. if (!empty($history_ctrl) && !empty($backups) && ($all === true) && ($check_ctrl === false)) { array_push($backups, $history_ctrl); } //if you have only the backups of the super _ctrl and no other, it has been differentiated because of different paths elseif (!empty($history_ctrl) && empty($backups) && $check_ctrl === true) { array_push($backups, $history_ctrl); } return $backups; }

Returns all backups of a file. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.