<commit_before><?php
require_once dirname(__FILE__) . '/StorageInventory.class.php';
define("LIBSERVERFUSIONINVENTORY_STORAGELOCATION",dirname(__FILE__)."/../../../".$configs['storageLocation']);

class DirectoryStorageInventory extends StorageInventory
{

    public function __construct($applicationName, $configs, $simpleXMLData)
    {

        $this->_configs=$configs;
        $this->_applicationName=$applicationName;

        $this->_possibleCriterias = array(
        "motherboardSerial" => $simpleXMLData->CONTENT->BIOS->MOTHERBOARDSERIAL,
        "assetTag" => $simpleXMLData->CONTENT->BIOS->ASSETTAG,
        "msn" => $simpleXMLData->CONTENT->BIOS->MSN,
        "ssn" => $simpleXMLData->CONTENT->BIOS->SSN,
        "baseboardSerial" => $simpleXMLData->CONTENT->BIOS->BASEBOARDSERIAL,
        "macAddress" => $simpleXMLData->CONTENT->NETWORKS,
        "uuid" => $simpleXMLData->CONTENT->HARDWARE->UUID,
        "winProdKey" => $simpleXMLData->CONTENT->HARDWARE->WINPRODKEY,
        "biosSerial" => $simpleXMLData->CONTENT->BIOS->BIOSSERIAL,
        "enclosureSerial" => $simpleXMLData->CONTENT->BIOS->ENCLOSURESERIAL,
        "smodel" => $simpleXMLData->CONTENT->BIOS->SMODEL,
        "storagesSerial" => $simpleXMLData->CONTENT->STORAGES,
        "drivesSerial" => $simpleXMLData->CONTENT->DRIVES);
    }

    /**
    * We look for the machine with the relevant criterias defined by user, if it doesn't exist, return false; else return internalId.
    * @return bool false or internalId
    */
    public function isMachineExist()
    {
        $falseCriteriaNb=-1;
        $internalId;

        foreach($this->_configs["criterias"] as $criteria)
        {

            if($falseCriteriaNb == $this->_configs["maxFalse"])
            {
                return false;
            }

            foreach($this->_possibleCriterias as $criteriaName => $criteriaValue)
            {
                if ($criteria == $criteriaName)
                {
                    if ($criteriaValue)
                    {
                        switch($criteria)
                        {
                            case "drivesSerial":
                            foreach($criteriaValue as $drives)
                            {
                                if ($drives->SYSTEMDRIVE==1)
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $drives->SERIAL)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $drives->SERIAL));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            case "storagesSerial":
                            foreach($criteriaValue as $storages)
                            {
                                if ($storages->TYPE=="disk")
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $storages->SERIAL)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $storages->SERIAL));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            case "macAddress":
                            foreach($criteriaValue as $networks)
                            {
                                if ($networks->VIRTUALDEV!=1 AND $networks->DESCRIPTION=="eth0")
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $networks->MACADDR)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $networks->MACADDR));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            default:
                            if (file_exists($this->_getCriteriaDSN($criteria, $criteriaValue)))
                            {
                                $internalId = scandir($this->_getCriteriaDSN($criteria, $criteriaValue));
                            } else {
                                $falseCriteriaNb++;
                            }
                            break;

                        }
                    }
                }
            }
        }
        if($falseCriteriaNb == $this->_configs["maxFalse"])
        {
            return false;
        }
        if (isset($internalId[2]))
        {
            return $internalId[2];
        }
        else {
            throw new MyException ("no avalaible criterias to compare");
        }


    }

    /**
    * We create directory tree for machine and store the externalId within INI file.
    * @param string $internalId
    * @param $externalId
    */
    public function addLibMachine($internalId, $externalId)
    {
        $infoPath = $this->_getInfoPathDSN($internalId);

        if(!is_dir($infoPath))
        {
            mkdir($infoPath,0777,true);
        }
        if (!file_exists($infoPath."/infos.file"))
        {
            $infoFile = fopen($infoPath."/infos.file","w");
            fclose($infoFile);
        }

        $data = <<<INFOCONTENT
$externalId
INFOCONTENT;

        file_put_contents($infoPath."/infos.file", $data);

    }

    /**
    * We create directory tree for criteria and internalId.
    * @param string $internalId
    */
    public function addLibCriteriasMachine($internalId)
    {
        $criteriasPathList = array();
        foreach($this->_possibleCriterias as $criteriaName => $criteriaValue)
        {
            if ($criteriaValue)
            {
                switch($criteriaName)
                {
                    case "drivesSerial":
                    foreach($criteriaValue as $drives)
                    {
                        if ($drives->SYSTEMDRIVE==1)
                        {
                            $criteriaPath = $this->_getCriteriaDSN($criteriaName, $drives->SERIAL);

                            $internalIdPath = sprintf('%s/%s',
                            $criteriaPath,
                            $internalId);

                            mkdir($internalIdPath,0777,true);

                            array_push($criteriasPathList, $criteriaPath);
                        }
                    }
                    break;

                    case "storagesSerial":
                    foreach($criteriaValue as $storages)
                    {
                        if ($storages->TYPE=="disk")
                        {
                            $criteriaPath = $this->_getCriteriaDSN($criteriaName, $storages->SERIAL);

                            $internalIdPath = sprintf('%s/%s',
                            $criteriaPath,
                            $internalId);

                            mkdir($internalIdPath,0777,true);

                            array_push($criteriasPathList, $criteriaPath);
                        }
                    }
                    break;

                    case "macAddress":
                    foreach($criteriaValue as $networks)
                    {
                        if ($networks->VIRTUALDEV!=1 AND $networks->DESCRIPTION=="eth0")<commit_msg>Fix creation folder for criteria when SERIAL disk not exist in XML<commit_after><?php
require_once dirname(__FILE__) . '/StorageInventory.class.php';
define("LIBSERVERFUSIONINVENTORY_STORAGELOCATION",dirname(__FILE__)."/../../../".$configs['storageLocation']);

class DirectoryStorageInventory extends StorageInventory
{

    public function __construct($applicationName, $configs, $simpleXMLData)
    {

        $this->_configs=$configs;
        $this->_applicationName=$applicationName;

        $this->_possibleCriterias = array(
        "motherboardSerial" => $simpleXMLData->CONTENT->BIOS->MOTHERBOARDSERIAL,
        "assetTag" => $simpleXMLData->CONTENT->BIOS->ASSETTAG,
        "msn" => $simpleXMLData->CONTENT->BIOS->MSN,
        "ssn" => $simpleXMLData->CONTENT->BIOS->SSN,
        "baseboardSerial" => $simpleXMLData->CONTENT->BIOS->BASEBOARDSERIAL,
        "macAddress" => $simpleXMLData->CONTENT->NETWORKS,
        "uuid" => $simpleXMLData->CONTENT->HARDWARE->UUID,
        "winProdKey" => $simpleXMLData->CONTENT->HARDWARE->WINPRODKEY,
        "biosSerial" => $simpleXMLData->CONTENT->BIOS->BIOSSERIAL,
        "enclosureSerial" => $simpleXMLData->CONTENT->BIOS->ENCLOSURESERIAL,
        "smodel" => $simpleXMLData->CONTENT->BIOS->SMODEL,
        "storagesSerial" => $simpleXMLData->CONTENT->STORAGES,
        "drivesSerial" => $simpleXMLData->CONTENT->DRIVES);
    }

    /**
    * We look for the machine with the relevant criterias defined by user, if it doesn't exist, return false; else return internalId.
    * @return bool false or internalId
    */
    public function isMachineExist()
    {
        $falseCriteriaNb=-1;
        $internalId;

        foreach($this->_configs["criterias"] as $criteria)
        {

            if($falseCriteriaNb == $this->_configs["maxFalse"])
            {
                return false;
            }

            foreach($this->_possibleCriterias as $criteriaName => $criteriaValue)
            {
                if ($criteria == $criteriaName)
                {
                    if ($criteriaValue)
                    {
                        switch($criteria)
                        {
                            case "drivesSerial":
                            foreach($criteriaValue as $drives)
                            {
                                if ($drives->SYSTEMDRIVE==1)
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $drives->SERIAL)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $drives->SERIAL));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            case "storagesSerial":
                            foreach($criteriaValue as $storages)
                            {
                                if ($storages->TYPE=="disk")
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $storages->SERIAL)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $storages->SERIAL));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            case "macAddress":
                            foreach($criteriaValue as $networks)
                            {
                                if ($networks->VIRTUALDEV!=1 AND $networks->DESCRIPTION=="eth0")
                                {
                                    if (file_exists($this->_getCriteriaDSN($criteria, $networks->MACADDR)))
                                    {
                                        $internalId = scandir($this->_getCriteriaDSN($criteria, $networks->MACADDR));
                                    } else {
                                        $falseCriteriaNb++;
                                    }
                                }
                            }
                            break;

                            default:
                            if (file_exists($this->_getCriteriaDSN($criteria, $criteriaValue)))
                            {
                                $internalId = scandir($this->_getCriteriaDSN($criteria, $criteriaValue));
                            } else {
                                $falseCriteriaNb++;
                            }
                            break;

                        }
                    }
                }
            }
        }
        if($falseCriteriaNb == $this->_configs["maxFalse"])
        {
            return false;
        }
        if (isset($internalId[2]))
        {
            return $internalId[2];
        }
        else {
            throw new MyException ("no avalaible criterias to compare");
        }


    }

    /**
    * We create directory tree for machine and store the externalId within INI file.
    * @param string $internalId
    * @param $externalId
    */
    public function addLibMachine($internalId, $externalId)
    {
        $infoPath = $this->_getInfoPathDSN($internalId);

        if(!is_dir($infoPath))
        {
            mkdir($infoPath,0777,true);
        }
        if (!file_exists($infoPath."/infos.file"))
        {
            $infoFile = fopen($infoPath."/infos.file","w");
            fclose($infoFile);
        }

        $data = <<<INFOCONTENT
$externalId
INFOCONTENT;

        file_put_contents($infoPath."/infos.file", $data);

    }

    /**
    * We create directory tree for criteria and internalId.
    * @param string $internalId
    */
    public function addLibCriteriasMachine($internalId)
    {
        $criteriasPathList = array();
        foreach($this->_possibleCriterias as $criteriaName => $criteriaValue)
        {
            if ($criteriaValue)
            {
                switch($criteriaName)
                {
                    case "drivesSerial":
                    foreach($criteriaValue as $drives)
                    {
                        if ($drives->SYSTEMDRIVE==1)
                        {
                            $criteriaPath = $this->_getCriteriaDSN($criteriaName, $drives->SERIAL);

                            $internalIdPath = sprintf('%s/%s',
                            $criteriaPath,
                            $internalId);

                            mkdir($internalIdPath,0777,true);

                            array_push($criteriasPathList, $criteriaPath);
                        }
                    }
                    break;

                    case "storagesSerial":
                    foreach($criteriaValue as $storages)
                    {
                        if (($storages->TYPE=="disk") AND (isset($storages->SERIAL)))
                        {
                            $criteriaPath = $this->_getCriteriaDSN($criteriaName, $storages->SERIAL);

                            $internalIdPath = sprintf('%s/%s',
                            $criteriaPath,
                            $internalId);

                            mkdir($internalIdPath,0777,true);

                            array_push($criteriasPathList, $criteriaPath);
                        }
                    }
                    break;

                    case "macAddress":
                    foreach($criteriaValue as $networks)
                    {
                        if ($networks->VIRTUALDEV!=1 AND $networks->DESCRIPTION=="eth0")
{'fraction_non_alphanumeric': 0.10480153649167734, 'fraction_numerical': 0.0026888604353393084, 'mean_word_length': 1.0953722334004024, 'pattern_counts': {'":': 12, '<': 11, '<?xml version=': 0, '>': 176, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6966134', 'n_tokens_mistral': 3907, 'n_tokens_neox': 3686, 'n_words': 560}