| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of EC-CUBE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * http://www.lockon.co.jp/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This program is free software; you can redistribute it and/or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * modify it under the terms of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * as published by the Free Software Foundation; either version 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * of the License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * along with this program; if not, write to the Free Software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | namespace Eccube\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Doctrine\ORM\EntityManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Eccube\Annotation\Inject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Eccube\Annotation\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Symfony\Component\Process\PhpExecutableFinder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @Service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class SystemService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var EntityManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @Inject("orm.em") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 3 |  |     protected $em; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     public function getDbversion() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 3 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 | 3 |  |         $rsm->addScalarResult('v', 'v'); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 3 |  |         $platform = $this->em->getConnection()->getDatabasePlatform()->getName(); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         switch ($platform) { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             case 'sqlite': | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 $prefix = 'SQLite version '; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                 $func = 'sqlite_version()'; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 3 |  |                 break; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             case 'mysql': | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |                 $prefix = 'MySQL '; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |                 $func = 'version()'; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 3 |  |                 break; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 3 |  |             case 'pgsql': | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 3 |  |             default: | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                 $prefix = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 $func = 'version()'; | 
            
                                                                        
                            
            
                                    
            
            
                | 65 | 3 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 3 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 3 |  |         $version = $this->em | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             ->createNativeQuery('select '.$func.' as v', $rsm) | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 3 |  |             ->getSingleScalarResult(); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         return $prefix.$version; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * Get environment php command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function getPHP() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         return (new PhpExecutableFinder())->find(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Try to set new values memory_limit | return true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param string $memory | EX: 1536M | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function canSetMemoryLimit($memory) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $ret = ini_set('memory_limit', $memory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         } catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return ($ret === false) ? false : true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * Get memory_limit | Megabyte | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @return float|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function getMemoryLimit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         // Data type: bytes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $memoryLimit = (new MemoryDataCollector())->getMemoryLimit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         if (-1 == $memoryLimit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             return -1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         return ($memoryLimit == 0) ? 0 : ($memoryLimit / 1024) / 1024; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |  |