本文整理汇总了PHP中ca_objects::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_objects::getErrors方法的具体用法?PHP ca_objects::getErrors怎么用?PHP ca_objects::getErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_objects
的用法示例。
在下文中一共展示了ca_objects::getErrors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertLoadAndDeleteCycleWithCaObjectsModel
public function testInsertLoadAndDeleteCycleWithCaObjectsModel()
{
$t_list = new ca_lists();
$va_object_types = $t_list->getItemsForList('object_types');
$this->assertGreaterThan(0, sizeof($va_object_types), "No object types available");
$va_object_types = caExtractValuesByUserLocale($va_object_types);
$this->assertGreaterThan(0, sizeof($va_object_types), "No locale-filtered object types available");
$vn_locale_id = 1;
$t_object = new ca_objects();
$t_object->setMode(ACCESS_WRITE);
$vn_item_id = 0;
foreach ($va_object_types as $va_object_type) {
if (intval($va_object_type['is_enabled']) === 1) {
$vn_item_id = $va_object_type['item_id'];
}
}
$this->assertGreaterThan(0, $vn_item_id, 'No enabled object type found');
$t_object->set('type_id', $vn_item_id);
$t_object->set('locale_id', $vn_locale_id);
$t_object->set('idno', time());
$t_object->addAttribute(array('description' => 'Test description', 'locale_id' => $vn_locale_id), 'description');
$vb_res = $t_object->insert();
$this->assertTrue($vb_res !== false, 'Insert returned non-true value');
// insert() returns false OR the primary key, therefore simply asserting $vb_res being true doesn't cut it
$this->assertEquals($t_object->numErrors(), 0, "Errors on insert: " . join('; ', $t_object->getErrors()));
$this->opa_test_record_ids['ca_objects'][] = $t_object->getPrimaryKey();
$vb_res = $t_object->addLabel(array('name' => 'Unit test object'), $vn_locale_id, null, true);
$this->assertGreaterThan(0, $vb_res, 'AddLabel returned zero value but should return non-zero label_id: ' . join('; ', $t_object->getErrors()));
$t_object2 = new ca_objects();
$vb_res = $t_object2->load($t_object->getPrimaryKey());
$this->assertTrue($vb_res, 'Load of newly created record failed [record does not seem to exist or return row id was invalid?]');
$this->assertEquals($t_object2->getLabelForDisplay(), 'Unit test object', 'Retrieved row label does not match');
$this->assertEquals($t_object2->getAttributesForDisplay('description'), 'Test description', 'Retrieved value for attribute "description" does not match expected value');
// try to search for it
$o_search = new ObjectSearch();
$qr_hits = $o_search->search("Unit test object");
$this->assertGreaterThan(0, $qr_hits->numHits(), 'Search for ca_object by label found no results');
$vb_found_object = false;
while ($qr_hits->nextHit()) {
if ($qr_hits->get('object_id') == $t_object->getPrimaryKey()) {
$vb_found_object = true;
break;
}
}
$this->assertTrue($vb_found_object, 'ca_object was not in returned search results for ca_object by label');
// try delete
$t_object->delete(true, array('hard' => true));
$this->assertEquals($t_object->numErrors(), 0, "Errors on delete: " . join('; ', $t_object->getErrors()));
}
示例2: getObjectID
/**
* Returns object_id for the object_id with the specified name, regardless of specified type. If the object does not already
* exist then it will be created with the specified name, type and locale, as well as with any specified values in the $pa_values array.
* $pa_values keys should be either valid object fields or attributes.
*
* @param string $ps_object_name Object label name
* @param int $pn_parent_id The parent_id of the object; must be set to a non-null value
* @param int $pn_type_id The type_id of the object type to use if the object needs to be created
* @param int $pn_locale_id The locale_id to use if the object needs to be created (will be used for both the object locale as well as the label locale)
* @param array $pa_values An optional array of additional values to populate newly created object records with. These values are *only* used for newly created objects; they will not be applied if the object named already exists. The array keys should be names of ca_objects fields or valid object attributes. Values should be either a scalar (for single-value attributes) or an array of values for (multi-valued attributes)
* @param array $pa_options An optional array of options, which include:
* outputErrors - if true, errors will be printed to console [default=false]
* matchOnIdno - try to match on idno if name match fails [default=false]
* dontCreate - if true then new entities will not be created [default=false]
* transaction - if Transaction object is passed, use it for all Db-related tasks [default=null]
* returnInstance = return ca_objects instance rather than object_id. Default is false.
* generateIdnoWithTemplate = A template to use when setting the idno. The template is a value with automatically-set SERIAL values replaced with % characters. Eg. 2012.% will set the created row's idno value to 2012.121 (assuming that 121 is the next number in the serial sequence.) The template is NOT used if idno is passed explicitly as a value in $pa_values.
* importEvent = if ca_data_import_events instance is passed then the insert/update of the object will be logged as part of the import
* importEventSource = if importEvent is passed, then the value set for importEventSource is used in the import event log as the data source. If omitted a default value of "?" is used
* log = if KLogger instance is passed then actions will be logged
*/
static function getObjectID($ps_object_name, $pn_parent_id, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null)
{
if (!is_array($pa_options)) {
$pa_options = array();
}
if (!isset($pa_options['outputErrors'])) {
$pa_options['outputErrors'] = false;
}
$pb_match_on_idno = caGetOption('matchOnIdno', $pa_options, false);
$t_object = new ca_objects();
if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
$t_object->setTransaction($pa_options['transaction']);
}
$o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null;
$vs_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?";
$o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null;
if (!($vs_idno = isset($pa_values['idno']) ? (string) $pa_values['idno'] : null)) {
if (isset($pa_options['generateIdnoWithTemplate']) && $pa_options['generateIdnoWithTemplate']) {
$vs_idno = $t_object->setIdnoTWithTemplate($pa_options['generateIdnoWithTemplate'], array('dontSetValue' => true));
}
}
$va_find_arr = array();
if ($pn_type_id) {
$va_find_arr['type_id'] = $pn_type_id;
}
if ($pn_parent_id) {
$va_find_arr['parent_id'] = $pn_parent_id;
}
if (!($vn_id = ca_objects::find(array_merge(array('preferred_labels' => array('name' => $ps_object_name)), $va_find_arr), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction'])))) {
if ($pb_match_on_idno && $vs_idno) {
$va_find_arr['idno'] = $vs_idno;
$vn_id = ca_objects::find($va_find_arr, array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']));
}
}
if (!$vn_id) {
if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) {
return false;
}
if ($o_event) {
$o_event->beginItem($vs_event_source, 'ca_objects', 'I');
}
$t_object->setMode(ACCESS_WRITE);
$t_object->set('locale_id', $pn_locale_id);
$t_object->set('type_id', $pn_type_id);
$t_object->set('parent_id', $pn_parent_id);
$t_object->set('source_id', isset($pa_values['source_id']) ? $pa_values['source_id'] : null);
$t_object->set('access', isset($pa_values['access']) ? $pa_values['access'] : 0);
$t_object->set('status', isset($pa_values['status']) ? $pa_values['status'] : 0);
$t_object->set('idno', $vs_idno);
$t_object->set('hier_object_id', isset($pa_values['hier_object_id']) ? $pa_values['hier_object_id'] : null);
$t_object->insert();
if ($t_object->numErrors()) {
if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
print "[Error] " . _t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())) . "\n";
}
if ($o_log) {
$o_log->logError(_t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())));
}
return null;
}
$vb_label_errors = false;
$t_object->addLabel(array('name' => $ps_object_name), $pn_locale_id, null, true);
if ($t_object->numErrors()) {
if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
print "[Error] " . _t("Could not set preferred label for object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())) . "\n";
}
if ($o_log) {
$o_log->logError(_t("Could not set preferred label for object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())));
}
$vb_label_errors = true;
}
unset($pa_values['access']);
unset($pa_values['status']);
unset($pa_values['idno']);
unset($pa_values['source_id']);
unset($pa_values['hier_object_id']);
$vb_attr_errors = false;
if (is_array($pa_values)) {
foreach ($pa_values as $vs_element => $va_value) {
//.........这里部分代码省略.........
示例3: getObjectID
/**
* Returns object_id for the object with the specified name (and type) or idno (regardless of specified type.) If the object does not already
* exist then it will be created with the specified name, type and locale, as well as with any specified values in the $pa_values array.
* $pa_values keys should be either valid object fields or attributes.
*
* @param string $ps_object_name Object label name
* @param int $pn_parent_id The parent_id of the object; must be set to a non-null value
* @param int $pn_type_id The type_id of the object type to use if the object needs to be created
* @param int $pn_locale_id The locale_id to use if the object needs to be created (will be used for both the object locale as well as the label locale)
* @param array $pa_values An optional array of additional values to populate newly created object records with. These values are *only* used for newly created objects; they will not be applied if the object named already exists. The array keys should be names of ca_objects fields or valid object attributes. Values should be either a scalar (for single-value attributes) or an array of values for (multi-valued attributes)
* @param array $pa_options An optional array of options, which include:
* outputErrors - if true, errors will be printed to console [default=false]
* matchOn = optional list indicating sequence of checks for an existing record; values of array can be "label" and "idno". Ex. array("idno", "label") will first try to match on idno and then label if the first match fails.
* dontCreate - if true then new objects will not be created [default=false]
* transaction - if Transaction object is passed, use it for all Db-related tasks [default=null]
* returnInstance = return ca_objects instance rather than object_id. Default is false.
* generateIdnoWithTemplate = A template to use when setting the idno. The template is a value with automatically-set SERIAL values replaced with % characters. Eg. 2012.% will set the created row's idno value to 2012.121 (assuming that 121 is the next number in the serial sequence.) The template is NOT used if idno is passed explicitly as a value in $pa_values.
* importEvent = if ca_data_import_events instance is passed then the insert/update of the object will be logged as part of the import
* importEventSource = if importEvent is passed, then the value set for importEventSource is used in the import event log as the data source. If omitted a default value of "?" is used
* nonPreferredLabels = an optional array of nonpreferred labels to add to any newly created objects. Each label in the array is an array with required object label values.
* log = if KLogger instance is passed then actions will be logged
* @return bool|\ca_objects|mixed|null
*/
static function getObjectID($ps_object_name, $pn_parent_id, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null)
{
if (!is_array($pa_options)) {
$pa_options = array();
}
if (!isset($pa_options['outputErrors'])) {
$pa_options['outputErrors'] = false;
}
$pa_match_on = caGetOption('matchOn', $pa_options, array('label', 'idno'), array('castTo' => "array"));
/** @var ca_data_import_events $o_event */
$o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null;
$t_object = new ca_objects();
if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
$t_object->setTransaction($pa_options['transaction']);
if ($o_event) {
$o_event->setTransaction($pa_options['transaction']);
}
}
$vs_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?";
/** @var KLogger $o_log */
$o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null;
$vs_idno = isset($pa_values['idno']) ? (string) $pa_values['idno'] : null;
if (preg_match('!\\%!', $vs_idno)) {
$pa_options['generateIdnoWithTemplate'] = $vs_idno;
$vs_idno = null;
}
if (!$vs_idno) {
if (isset($pa_options['generateIdnoWithTemplate']) && $pa_options['generateIdnoWithTemplate']) {
$vs_idno = $t_object->setIdnoWithTemplate($pa_options['generateIdnoWithTemplate'], array('dontSetValue' => true));
}
}
$vn_id = null;
foreach ($pa_match_on as $vs_match_on) {
switch (strtolower($vs_match_on)) {
case 'label':
case 'labels':
if (trim($ps_object_name)) {
if ($vn_id = ca_objects::find(array('preferred_labels' => array('name' => $ps_object_name), 'parent_id' => $pn_parent_id, 'type_id' => $pn_type_id), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
break 2;
}
}
break;
case 'idno':
if ($vs_idno == '%') {
break;
}
// don't try to match on an unreplaced idno placeholder
if ($vn_id = ca_objects::find(array('idno' => $vs_idno ? $vs_idno : $ps_object_name), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
break 2;
}
break;
}
}
if (!$vn_id) {
if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) {
return false;
}
if ($o_event) {
$o_event->beginItem($vs_event_source, 'ca_objects', 'I');
}
$t_object->setMode(ACCESS_WRITE);
$t_object->set('locale_id', $pn_locale_id);
$t_object->set('type_id', $pn_type_id);
$t_object->set('parent_id', $pn_parent_id);
$t_object->set('source_id', isset($pa_values['source_id']) ? $pa_values['source_id'] : null);
$t_object->set('access', isset($pa_values['access']) ? $pa_values['access'] : 0);
$t_object->set('status', isset($pa_values['status']) ? $pa_values['status'] : 0);
$t_object->set('idno', $vs_idno);
$t_object->set('hier_object_id', isset($pa_values['hier_object_id']) ? $pa_values['hier_object_id'] : null);
$t_object->insert();
if ($t_object->numErrors()) {
if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
print "[Error] " . _t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())) . "\n";
}
if ($o_log) {
$o_log->logError(_t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())));
}
//.........这里部分代码省略.........
示例4: commandImportSIPs
//.........这里部分代码省略.........
$va_side_audio[$va_tmp[2]] = $va_tmp[3];
break;
case 'xml':
if (preg_match('!meta!', $va_tmp[3])) {
$va_side_xml[$va_tmp[2]] = ($vb_is_dir ? "{$vs_file}/sides/" : "phar://{$vs_file}/{$vs_idno}/sides/") . $va_tmp[2] . "/" . $va_tmp[3];
}
break;
}
}
}
break;
case 'artifacts':
if (sizeof($va_tmp) == 3) {
$va_artifacts[] = ($vb_is_dir ? "{$vs_file}/artifacts/" : "phar://{$vs_file}/{$vs_idno}/artifacts/") . $va_tmp[2];
}
break;
}
}
//print "[6] ".$t->getTime(4)."\n";
//print_R($va_side_xml); die;
// Process
// Create parent record
$vn_image_count = 0;
$o_progress->next(_t('Processing %1', $vs_archive_file));
$o_progress->setMessage(_t("Creating reel for %1", $vs_idno));
$va_ids = ca_objects::find(array('idno' => $vs_idno, 'deleted' => 0, 'type_id' => 'reel'), array('returnAs' => 'ids'));
if (!is_array($va_ids) || !sizeof($va_ids)) {
$t_object = new ca_objects();
$t_object->setMode(ACCESS_WRITE);
$t_object->set(array('status' => 5, 'type_id' => 'reel', 'idno' => $vs_idno));
$vn_object_id = $t_object->insert();
if ($t_object->numErrors()) {
if ($o_log) {
$o_log->logError(_t("Could not add reel record %1: %2", $vs_idno, join("; ", $t_object->getErrors())));
}
}
$t_object->addLabel(array('name' => $vs_idno_padded), $pn_locale_id, null, true);
if ($t_object->numErrors()) {
if ($o_log) {
$o_log->logError(_t("Could not add label to reel record %1: %2", $vs_idno, join("; ", $t_object->getErrors())));
}
}
if ($t_object->numErrors()) {
if ($o_log) {
$o_log->logError(_t("Could not add artifct media %1 to reel %2: %3", pathinfo($vs_artifact, PATHINFO_BASENAME), $vs_idno, join("; ", $t_object->getErrors())));
}
}
} else {
if ($o_log) {
$o_log->logDebug(_t("Found existing reel record %1 for %2", $va_ids[0], $vs_idno));
}
$t_object = new ca_objects($vn_object_id = $va_ids[0]);
$t_object->setMode(ACCESS_WRITE);
$t_object->set('status', 5);
$t_object->update();
if (($vn_image_count = $t_object->numberOfRepresentationsOfClass("image")) > 0) {
// skip reels that have images already
//if ($o_log) { $o_log->logDebug(_t("Skipped existing reel record %1 because it already has %2 images", $vs_idno, $vn_image_count)); }
//if ($o_progress) { $o_progress->setError(_t("Skipped existing reel record %1 because it already has %2 images", $vs_idno, $vn_image_count)); }
//continue;
}
$t_object->setMode(ACCESS_WRITE);
}
//print "[7] ".$t->getTime(4)."\n";
if ($vn_image_count > 0) {
$t_object->removeAllRepresentations();
示例5: importMediaFromDirectory
/**
* @param array $pa_options
* progressCallback =
* reportCallback =
* sendMail =
*/
public static function importMediaFromDirectory($po_request, $pa_options = null)
{
global $g_ui_locale_id;
$t_object = new ca_objects();
$o_eventlog = new Eventlog();
$t_set = new ca_sets();
$va_notices = $va_errors = array();
$vb_we_set_transaction = false;
$o_trans = isset($pa_options['transaction']) && $pa_options['transaction'] ? $pa_options['transaction'] : null;
if (!$o_trans) {
$vb_we_set_transaction = true;
$o_trans = new Transaction();
}
$o_log = new Batchlog(array('user_id' => $po_request->getUserID(), 'batch_type' => 'MI', 'table_num' => (int) $t_object->tableNum(), 'notes' => '', 'transaction' => $o_trans));
if (!is_dir($pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid"));
return null;
}
$vs_batch_media_import_root_directory = $po_request->config->get('batch_media_import_root_directory');
if (!preg_match("!^{$vs_batch_media_import_root_directory}!", $pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid"));
return null;
}
if (preg_match("!/\\.\\.!", $vs_directory) || preg_match("!\\.\\./!", $pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid"));
return null;
}
$vb_include_subdirectories = (bool) $pa_options['includeSubDirectories'];
$vb_delete_media_on_import = (bool) $pa_options['deleteMediaOnImport'];
$vs_import_mode = $pa_options['importMode'];
$vs_match_mode = $pa_options['matchMode'];
$vn_object_type_id = $pa_options['ca_objects_type_id'];
$vn_rep_type_id = $pa_options['ca_object_representations_type_id'];
$vn_object_access = $pa_options['ca_objects_access'];
$vn_object_representation_access = $pa_options['ca_object_representations_access'];
$vn_object_status = $pa_options['ca_objects_status'];
$vn_object_representation_status = $pa_options['ca_object_representations_status'];
$vs_idno_mode = $pa_options['idnoMode'];
$vs_idno = $pa_options['idno'];
$vs_set_mode = $pa_options['setMode'];
$vs_set_create_name = $pa_options['setCreateName'];
$vn_set_id = $pa_options['set_id'];
$vn_locale_id = $pa_options['locale_id'];
$vs_skip_file_list = $pa_options['skipFileList'];
$va_relationship_type_id_for = array();
if (is_array($va_create_relationship_for = $pa_options['create_relationship_for'])) {
foreach ($va_create_relationship_for as $vs_rel_table) {
$va_relationship_type_id_for[$vs_rel_table] = $pa_options['relationship_type_id_for_' . $vs_rel_table];
}
}
if (!$vn_locale_id) {
$vn_locale_id = $g_ui_locale_id;
}
$va_files_to_process = caGetDirectoryContentsAsList($pa_options['importFromDirectory'], $vb_include_subdirectories);
if ($vs_set_mode == 'add') {
$t_set->load($vn_set_id);
} else {
if ($vs_set_mode == 'create' && $vs_set_create_name) {
$va_set_ids = $t_set->getSets(array('user_id' => $po_request->getUserID(), 'table' => 'ca_objects', 'access' => __CA_SET_EDIT_ACCESS__, 'setIDsOnly' => true, 'name' => $vs_set_create_name));
$vn_set_id = null;
if (is_array($va_set_ids) && sizeof($va_set_ids) > 0) {
$vn_possible_set_id = array_shift($va_set_ids);
if ($t_set->load($vn_possible_set_id)) {
$vn_set_id = $t_set->getPrimaryKey();
}
} else {
$vs_set_code = mb_substr(preg_replace("![^A-Za-z0-9_\\-]+!", "_", $vs_set_create_name), 0, 100);
if ($t_set->load(array('set_code' => $vs_set_code))) {
$vn_set_id = $t_set->getPrimaryKey();
}
}
if (!$t_set->getPrimaryKey()) {
$t_set->setMode(ACCESS_WRITE);
$t_set->set('user_id', $po_request->getUserID());
$t_set->set('type_id', $po_request->config->get('ca_sets_default_type'));
$t_set->set('table_num', $t_object->tableNum());
$t_set->set('set_code', $vs_set_code);
$t_set->insert();
if ($t_set->numErrors()) {
$va_notices['create_set'] = array('idno' => '', 'label' => _t('Create set %1', $vs_set_create_name), 'message' => _t('Failed to create set %1: %2', $vs_set_create_name, join("; ", $t_set->getErrors())), 'status' => 'SET ERROR');
} else {
$t_set->addLabel(array('name' => $vs_set_create_name), $vn_locale_id, null, true);
if ($t_set->numErrors()) {
$va_notices['add_set_label'] = array('idno' => '', 'label' => _t('Add label to set %1', $vs_set_create_name), 'message' => _t('Failed to add label to set: %1', join("; ", $t_set->getErrors())), 'status' => 'SET ERROR');
}
$vn_set_id = $t_set->getPrimaryKey();
}
}
} else {
$vn_set_id = null;
// no set
}
}
if ($t_set->getPrimaryKey() && !$t_set->haveAccessToSet($po_request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
//.........这里部分代码省略.........