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
No edit summary
 
Line 2: Line 2:
==About==
==About==
* '''General docs''': {{l/ver/fx|PairCheck}}
* '''General docs''': {{l/ver/fx|PairCheck}}
* '''Note''': the core function of indexing-by-ext is in $oaDir->IndexByExt().
* '''Note''': the core function of indexing-by-ext is in <code>$oaDir->{{l/ver/fx|IndexByExt}}()</code>.


==Status==
==Status==

Latest revision as of 02:42, 12 November 2025

DataFolder::PairCheck()

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)
  • 2025-11-02 renamed from IndexIt()PairCheck()

Code

as of 2025-11-11 (including some debug code)

public function PairCheck() : StatusIface {
        $oStat = new StatusClass;
        $this->AmHere();
        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');

            #echo '## $oaExts is: '.get_class($oaExts).CRLF;

            $arJSNames = $this->NamesArrayFromQArray($osJS);

            // First, look at all the .sql files:
            $osSQ = $oaExts->QryIt('sql');
            if ($osSQ->HasIt()) { // if any were found --
        $this->AmHere();
                $arSQ = $osSQ->GetIt(); // get the list
                foreach ($arSQ as $nIdx => $oEntry) {
                    // for each .sql file, create a MetaPair object:
                    $fsData = $oEntry->Ident()->SpecFull();
        $this->AmHere("fsData=[$fsData]");
                    $oPair = $this->MetaPairClass()::FromDataSpec($fsData);
                    $oData = $oPair->DataFile();
                    $oMeta = $oPair->MetaFile();

                    $oMetaIO = $oMeta->InOut();
                    $oaMeta = $oMetaIO->OAData();
                    $oaMeta->DataFormat('SQL'); // TODO: should be tied to enum or clade-const
                    $sName = $oaMeta->QSFileName()->GetIt();
                    #$sName2 = $oData->SpecFull();
                    #$this->AmHere("NAME1: [$sName] NAME2: [$sName2]"); die();

                    if (array_key_exists($sName,$arJSNames)) {
                        // There's already a .json metafile for this .sql:
                        $oMeta = $arJSNames[$sName];
                    } else {
                        // JSON-meta file not found; create object...
                        $arJSNames[$sName] = $oMeta;
                        // ...and save data:
                        $oMetaIO->OAData()->Store(); // create/populate the meta file
                    }
                }
                $oStat->SetOkay(TRUE);
            }
        } else {
        $this->AmHere();
            $oStat->SetOkay(FALSE);
            // 2025-02-10 This method will need some rewriting.
            $ffp = $this->Ident()->SpecFull();
            $oStat->AddMsgString("Can't access import folder $ffp. Does it exist?");
        }
        return $oStat;
    }