Futilities/v0.6/clade/Sys/dba/files/DataFolder/@fx/PairCheck: Difference between revisions

From Woozle Writes Code
< Futilities‎ | v0.6‎ | clade‎ | Sys‎ | dba‎ | files/DataFolder
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{fmt/title|<code>[[../../|DataFolder]]::IndexIt()</code>}}
==About==
* '''Name usage''': {{l/ver/fx|IndexIt}}
==Status==
==Status==
* '''{{fmt/date|2025|01|27}}''' {{hashtag|TODO}}: use data-migration enum as basis for orphaned-file-extension list (in the <code>QryIt('sql')</code> section)
* '''{{fmt/date|2025|01|27}}''' {{hashtag|TODO}}: use data-migration enum as basis for orphaned-file-extension list (in the <code>QryIt('sql')</code> section)

Revision as of 16:57, 2 November 2025

DataFolder::IndexIt()

About

Status

  • 2025-01-27 #TODO: use data-migration enum as basis for orphaned-file-extension list (in the QryIt('sql') section)
    • (...that is, data files which don't have an associated .json index file)

Code

as of 2025-11-02

public function IndexIt() : StatusIface {
        $oStat = new StatusClass;
        $this->AmHere('Indexing the folder');

        if ($this->Ident()->Exists()) {
            $oaDir = $this->InOut()->ContentArray();  // read the dir into an array
            $oaExts = $oaDir->IndexByExt();         // index the array by filename extension
            $osJS = $oaExts->QryIt('json');
            if ($osJS->HasIt()) {
                $arJS = $osJS->GetIt();
                $arByFName = [];
                $arBySchm = [];
                foreach ($arJS as $nIdx => $oEntry) {
                    $fsMeta = $oEntry->Ident()->SpecFull();
                    $oMeta = MetaNodeClass::FromSpec($fsMeta);
                    $oMetaIO = $oMeta->InOut();
                    $oaMeta = $oMetaIO->OAData();
                    $oaMeta->Fetch();

                    $sName = $oMetaIO->TargetFileName();
                    $arByFName[$sName] = $oMeta;
                    $qsSchm = $oMetaIO->QSchemaName();
                    if ($qsSchm->HasIt()) {
                        $arBySchm[$qsSchm->GetIt()] = $oMeta;
                    } else {
                        echo self::Screen()->ErrorIt('Data missing:')." data file $fsMeta has no Schema name.".CRLF;
                    }
                }
            }
            // TODO 2025-01-27: use data-migration enum as basis for orphaned-file-extension list
            // (...that is, data files which don't have an associated .json index file)
            $osSQ = $oaExts->QryIt('sql');
            if ($osSQ->HasIt()) { // if there are any .sql files...
                $arSQ = $osSQ->GetIt(); // get the list of files
                foreach ($arSQ as $nIdx => $oEntry) {
                    // for each .sql file:
                    $fsTarg = $oEntry->Ident()->SpecFull();
                    $oMeta = MetaNodeClass::FromTargetSpec($fsTarg);
                    $oMetaIO = $oMeta->InOut();
                    $oMetaIO->DataFormat('SQL'); // TODO: should be tied to enum
                    $sName = $oMetaIO->TargetFileName();
                    if (array_key_exists($sName,$arByFName)) {
                        // There's already a .json metafile for this .sql:
                        $oMeta = $arByFName[$sName];
                    } else {
                        // JSON-meta file not found; create object...
                        $arByFName[$sName] = $oMeta;
                        // ...and save data:
                        $oMetaIO->OAData()->Store(); // create/populate the meta file
                    }
                }
            }
            if (isset($arByFName) && (count($arByFName) > 0)) {
                $oStat->SetOkay(TRUE);
                $oaByFName = NodesClass::FromVArray($arByFName);
                $this->SetByFName($oaByFName);
            } else {
                // 2025-02-10 This method will need some rewriting.
                $oStat->AddMsgString("No importable files found in $ffp.");
            }
            if (is_array($arBySchm)) {
                $oaBySchm = NodesClass::FromVArray($arBySchm);
                #$this->AmHere('Setting schema list.');
                $this->SetBySchm($oaBySchm);
            } else {
                $this->AmHere('No array found, for some reason.');
            }
        } else {
          // 2025-02-10 This method will need some rewriting.
          $oStat->AddMsgString("Can't access import folder $ffp. Does it exist?");
        }
        return $oStat;
    }