PartKeepr\SetupBundle\Services\SiPrefixSetupService::importSiPrefixes PHP Method

importSiPrefixes() public method

Imports or updates the existing si prefixes.
public importSiPrefixes ( ) : array
return array An array with the keys "skipped" and "imported" which contain the number of si prefixes skipped and imported
    public function importSiPrefixes()
    {
        $path = $this->kernel->locateResource(self::SIPREFIX_PATH . self::SIPREFIX_DATA);
        $yaml = new Parser();
        $data = $yaml->parse(file_get_contents($path));
        $count = 0;
        $updated = 0;
        foreach ($data as $prefixName => $prefixData) {
            $prefix = $this->getSiPrefix($prefixName);
            if ($prefix === null) {
                $prefix = new SiPrefix();
                $prefix->setPrefix($prefixName);
                $this->entityManager->persist($prefix);
                $count++;
            }
            $prefix->setExponent($prefixData['exponent']);
            $prefix->setSymbol($prefixData['symbol']);
            $prefix->setBase($prefixData['base']);
            $updated++;
        }
        $this->entityManager->flush();
        return ['updated' => $updated - $count, 'imported' => $count];
    }