コード例 #1
0
function _ops_update()
{
    $OID = max(0, intval($_POST['OID']));
    $CID = max(0, intval($_POST['CID']));
    $msg = "";
    loginRequireMgmt();
    if (!loginCheckPermission(USER::MGMT_RPI)) {
        redirect("errors/401");
    }
    $itemName = "RPI";
    $urlPrefix = "mgmt_rpi";
    $object = new RPI();
    if ($OID) {
        $object->retrieve($OID, $CID);
        if (!$object->exists()) {
            $msg = "{$itemName} not found!";
        } else {
            transactionBegin();
            $object->merge($_POST);
            if ($object->update()) {
                transactionCommit();
                $msg = "{$itemName} updated!";
            } else {
                transactionRollback();
                $msg = "{$itemName} update failed";
            }
        }
    } else {
        $object->merge($_POST);
        transactionBegin();
        if ($object->create()) {
            transactionCommit();
            $msg = "{$itemName} created!";
        } else {
            transactionRollback();
            $msg = "{$itemName} Create failed";
        }
    }
    redirect("{$urlPrefix}/manage", $msg);
}
コード例 #2
0
function _join($stationTag = null)
{
    try {
        if ($stationTag === false) {
            trace("stationTag not present", __FILE__, __LINE__, __METHOD__);
            throw new RestException(400, "stationTag not present");
        }
        $station = Station::getFromTag($stationTag);
        if ($station === false) {
            trace("_join station not found stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
            throw new RestException(500, "station not found stationTag=" . $stationTag);
        }
        trace("tag=" . $stationTag . " station OID=" . $station->get('OID'), __FILE__, __LINE__, __METHOD__);
        $json = json_getObjectFromRequest("POST");
        // if ($json === NULL) return;
        json_checkMembers("message_version,station_type,station_url", $json);
        $rpi = RPI::getFromStationId($station->get('OID'));
        if ($rpi === false) {
            // output
            $rpi = new RPI();
            $rpi->set('stationId', $station->get('OID'));
            $rpi->set_contact_data($stationTag, $json);
            if ($rpi->create() === false) {
                trace("create failed", __FILE__, __LINE__, __METHOD__);
                throw new RestException(500, "join create failed");
            }
        } else {
            $rpi->set_contact_data($stationTag, $json);
            if ($rpi->update() === false) {
                trace("update failed", __FILE__, __LINE__, __METHOD__);
                throw new RestException(500, "join update failed");
            }
        }
        rest_sendSuccessResponse(202, "Accepted", "{$stationTag} has joined M");
    } catch (RestException $e) {
        rest_sendBadRequestResponse($e->statusCode, $e->statusMsg);
        // doesn't return
    }
}