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 1: Line 1:
{{fmt/title|<code>[[../../|DataFolder]]::PairCheck()</code>}}
{{fmt/title|<code>[[../../|DataFolder]]::PairCheck()</code>}}
==About==
==About==
* '''Name usage''': {{l/ver/fx|PairCheck}}
* '''General docs''': {{l/ver/fx|PairCheck}}
* '''Note''': the core function of indexing-by-ext is in $oaDir->IndexByExt().
 
==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)
** (...that is, data files which don't have an associated .json index file)
** (...that is, data files which don't have an associated .json index file)
* '''{{fmt/date|2025|11|02}}''' renamed from <code>IndexIt()</code> &rarr; <code>PairCheck()</code>
* '''{{fmt/date|2025|11|02}}''' renamed from <code>IndexIt()</code> &rArr; <code>PairCheck()</code>
==Code==
==Code==
''as of {{fmt/date|2025|11|02}}''
''as of {{fmt/date|2025|11|11}} (including some debug code)''
{{fmt/php/block|1=
{{fmt/php/block|1=
     public function IndexIt() : StatusIface {
     public function PairCheck() : StatusIface {
         $oStat = new StatusClass;
         $oStat = new StatusClass;
         $this->AmHere('Indexing the folder');
         $this->AmHere();
 
         if ($this->Ident()->Exists()) {
         if ($this->Ident()->Exists()) {
             $oaDir = $this->InOut()->ContentArray();  // read the dir into an array
             $oaDir = $this->InOut()->ContentArray();  // read the dir into an array
             $oaExts = $oaDir->IndexByExt();        // index the array by filename extension
             $oaExts = $oaDir->IndexByExt();        // index the array by filename extension
             $osJS = $oaExts->QryIt('json');
             $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();
            #echo '## $oaExts is: '.get_class($oaExts).CRLF;
                    $arByFName[$sName] = $oMeta;
 
                    $qsSchm = $oMetaIO->QSchemaName();
            $arJSNames = $this->NamesArrayFromQArray($osJS);
                    if ($qsSchm->HasIt()) {
 
                        $arBySchm[$qsSchm->GetIt()] = $oMeta;
             // First, look at all the .sql files:
                    } 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');
             $osSQ = $oaExts->QryIt('sql');
             if ($osSQ->HasIt()) { // if there are any .sql files...
             if ($osSQ->HasIt()) { // if any were found --
                 $arSQ = $osSQ->GetIt(); // get the list of files
        $this->AmHere();
                 $arSQ = $osSQ->GetIt(); // get the list
                 foreach ($arSQ as $nIdx => $oEntry) {
                 foreach ($arSQ as $nIdx => $oEntry) {
                     // for each .sql file:
                     // for each .sql file, create a MetaPair object:
                     $fsTarg = $oEntry->Ident()->SpecFull();
                     $fsData = $oEntry->Ident()->SpecFull();
                     $oMeta = MetaNodeClass::FromTargetSpec($fsTarg);
        $this->AmHere("fsData=[$fsData]");
                     $oPair = $this->MetaPairClass()::FromDataSpec($fsData);
                    $oData = $oPair->DataFile();
                    $oMeta = $oPair->MetaFile();
 
                     $oMetaIO = $oMeta->InOut();
                     $oMetaIO = $oMeta->InOut();
                     $oMetaIO->DataFormat('SQL'); // TODO: should be tied to enum
                     $oaMeta = $oMetaIO->OAData();
                     $sName = $oMetaIO->TargetFileName();
                    $oaMeta->DataFormat('SQL'); // TODO: should be tied to enum or clade-const
                     if (array_key_exists($sName,$arByFName)) {
                     $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:
                         // There's already a .json metafile for this .sql:
                         $oMeta = $arByFName[$sName];
                         $oMeta = $arJSNames[$sName];
                     } else {
                     } else {
                         // JSON-meta file not found; create object...
                         // JSON-meta file not found; create object...
                         $arByFName[$sName] = $oMeta;
                         $arJSNames[$sName] = $oMeta;
                         // ...and save data:
                         // ...and save data:
                         $oMetaIO->OAData()->Store(); // create/populate the meta file
                         $oMetaIO->OAData()->Store(); // create/populate the meta file
                     }
                     }
                 }
                 }
            }
            if (isset($arByFName) && (count($arByFName) > 0)) {
                 $oStat->SetOkay(TRUE);
                 $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 {
         } else {
          // 2025-02-10 This method will need some rewriting.
        $this->AmHere();
          $oStat->AddMsgString("Can't access import folder $ffp. Does it exist?");
            $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;
         return $oStat;
     }
     }
}}
}}

Revision as of 02:40, 12 November 2025

DataFolder::PairCheck()

About

  • General docs: PairCheck
  • Note: the core function of indexing-by-ext is in $oaDir->IndexByExt().

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;
    }