public function install() { $result = true; // We need CURL to function correctly if (!$this->curlExists()) { $this->context->controller->errors[] = $this->l('Riskified require CURL to be installed and enabled.'); $result = false; } if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE)) { return false; } else { if (!($sql = Tools::file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_FILE))) { return false; } } $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); $sql = preg_split("/;\\s*[\r\n]+/", trim($sql)); foreach ($sql as $query) { if (!Db::getInstance()->execute(trim($query))) { return false; } } if (!parent::install() || !$this->registerHook('displayAdminOrder') || !$this->registerHook('displayBackOfficeHeader') || !$this->registerHook('displayBackOfficeTop') || !$this->registerHook('actionValidateOrder') || !$this->registerHook('header')) { $result = false; } RiskifiedLogger::insertLog(__METHOD__ . ' : ' . __LINE__, 'Riskified::install() = ' . $result); return $result; }
/** * creates the log file if it doesn't exist * rename the log file then creates a new one if the existing one has reached the max allowed size (100Ko) * open the log file * assigns the log file handle to the local var $handle * * @return void */ private static function openHandle() { if (!file_exists(RISKIFIED_ROOT_DIR . '/logs/')) { if (!mkdir(RISKIFIED_ROOT_DIR . '/logs/')) { die('Error creating logs folder'); } } $log_filename = RISKIFIED_ROOT_DIR . '/logs/riskified.log'; //renames the log file and creates a new one if max allowed size reached if (file_exists($log_filename) && filesize($log_filename) > 100000) { $prefix = RISKIFIED_ROOT_DIR . '/logs/riskifiedlog-'; $base = date('YmdHis'); $sufix = '.txt'; $filename = $prefix . $base . $sufix; for ($i = 0; file_exists($filename); $i++) { $filename = $prefix . $base . "-{$i}" . $sufix; } rename($log_filename, $filename); } self::$handle = self::openFile($log_filename); register_shutdown_function('fclose', self::$handle); }