public function handle() { try { // Make sure all warnings are properly intercepted set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) { error_log("{$errstr} in {$errfile} on line {$errline}"); throw new Exception("PHP error at {$errfile}:{$errline}: {$errstr}"); }); if ($this->shouldValidteSession()) { $this->validateSession(); } $args = $this->parseRequest(); try { $args = $this->getRequestValidator()->exec("REQUEST", $args); } catch (Validator\ValidationException $e) { throw new Exception($e->getMessage(), self::STATUS_BAD_REQUEST); } $result = null; Model::beginTransaction(); try { $result = $this->handleRequest($args); $result = $this->getResponseValidator()->exec("RESPONSE", $result); Model::commitTransaction(); } catch (Validator\ValidationException $e) { Model::rollbackTransaction(); throw new Exception($e->getMessage(), self::STATUS_SERVER_ERROR); } catch (Exception $e) { Model::rollbackTransaction(); throw $e; } $this->sendResponse(self::STATUS_SUCCESS, $result); } catch (Exception $e) { $code = $e->getCode() ?: self::STATUS_SERVER_ERROR; $message = $e->getMessage(); $this->sendResponse($code, array(self::FIELD_ERROR_MESSAGE => $message)); } }
<?php namespace bmtmgr; require_once \dirname(__DIR__) . '/src/common.php'; utils\csrf_protect(); $u = user\check_current(); $u->require_perm('admin'); if (!config\get('allow_import', false)) { throw new \Exception('Configuration directive allow_import not set!'); } // TODO This should later be http://www.blv-nrw.de/blvdb/fb/blv_club_kontakte.php?id=%d $url_pattern = 'http://localhost/bmtmgr/import/clubs/blv_club_kontakte.php%%3fid=%d'; $imported_clubs = []; $not_found_since = 0; Model::beginTransaction(); for ($i = 1; $i < 100000; $i++) { $url = \sprintf($url_pattern, $i); $page = \file_get_contents($url); $r = \preg_match('/ <label>ClubID:<\\/label><div>(?P<id>[0-9-]+)<\\/div>.* <label>Vereinsname:<\\/label><div>(?P<name>[^<]+)<\\/div>.* <label>Email:<\\/label><div><a.*?>(?P<email>[^<]+)<\\/a> /xs', $page, $m); if (!$r) { $not_found_since++; if ($not_found_since > 100) { break; } continue; }