Beispiel #1
0
 public function commitRead()
 {
     return instance::commit($this->read());
 }
 public function deleteDocument($id)
 {
     //--
     $connect = $this->solr_connect();
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-queries', 1, '+');
         //--
         $time_start = microtime(true);
         //--
     }
     //end if
     //--
     if ((string) $id == '') {
         Smart::log_warning('Solr ERROR # deleteDocument # ' . 'Document ID is Empty');
         return -100;
     }
     //end if
     //--
     try {
         //--
         $updateResponse = $this->instance->deleteById((string) $id);
         $this->instance->commit();
         // save
         //--
     } catch (Exception $e) {
         //--
         Smart::log_warning('Solr ERROR # deleteDocument # EXCEPTION: ' . $e->getMessage() . "\n" . 'ID=' . $id);
         return -201;
         //--
     }
     //end try catch
     //--
     $response = $updateResponse->getResponse();
     // get answer message
     //print_r($response);
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $time_end = (double) (microtime(true) - (double) $time_start);
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-time', $time_end, '+');
         //--
         SmartFrameworkRegistry::setDebugMsg('db', 'solr|log', ['type' => 'nosql', 'data' => 'DELETE-QUERY', 'command' => array('ID' => (string) $id), 'time' => Smart::format_number_dec($time_end, 9, '.', '')]);
         //--
     }
     //end if
     //--
     if (is_object($response)) {
         if ($response instanceof SolrObject) {
             if (is_object($response['responseHeader'])) {
                 if ($response['responseHeader'] instanceof SolrObject) {
                     if ($response['responseHeader']->status === 0) {
                         // OK
                     } else {
                         Smart::log_warning('Solr ERROR # deleteDocument # Invalid Status (' . $response['responseHeader']->status . ') : ' . 'ID=' . $id);
                         return -206;
                     }
                     //end if else
                 } else {
                     Smart::log_warning('Solr ERROR # deleteDocument # Invalid responseHeader / Not instanceof SolrObject: ' . 'ID=' . $id);
                     return -205;
                 }
                 //end if else
             } else {
                 Smart::log_warning('Solr ERROR # deleteDocument # Invalid responseHeader / Invalid Object: ' . 'ID=' . $id);
                 return -204;
             }
             //end if else
         } else {
             Smart::log_warning('Solr ERROR # deleteDocument # Invalid Answer / Not instanceof SolrObject: ' . 'ID=' . $id);
             return -203;
         }
         //end if else
     } else {
         Smart::log_warning('Solr ERROR # deleteDocument # Not Object: ' . 'ID=' . $id);
         return -202;
     }
     //end if else
     //--
     return 0;
     // OK
     //--
 }
 /**
  * alterのマイグレーションを適用する
  * @param instance $argDBO
  * @return boolean
  */
 public function alter($argDBO, $argDescribes)
 {
     $executed = FALSE;
     // ALTERは一行づつ処理
     foreach ($argDescribes as $field => $propaty) {
         $sql = '';
         if ('DROP' === $propaty['alter']) {
             $sql = 'ALTER TABLE `' . $this->tableName . '` DROP COLUMN `' . $field . '`';
         } else {
             $fielPropatyQuerys = $this->_getFieldPropatyQuery(array($field => $propaty));
             $fieldDef = $fielPropatyQuerys['fieldDef'];
             if (strlen($fieldDef) > 0) {
                 $sql = 'ALTER TABLE `' . $this->tableName . '` ' . $propaty['alter'] . ' COLUMN ' . $fieldDef;
                 if (isset($propaty['first']) && TRUE === $propaty['first']) {
                     $sql .= ' FIRST ';
                 } else {
                     if (isset($propaty['after']) && 0 < strlen($propaty['after'])) {
                         $sql .= ' AFTER `' . $propaty['after'] . '`';
                     }
                 }
             }
         }
         if (strlen($sql) > 0) {
             try {
                 debug('migration alter sql=' . $sql);
                 $argDBO->execute($sql);
                 $executed = TRUE;
             } catch (Exception $Exception) {
                 logging($Exception->getMessage(), 'exception');
                 // ALTERのADDは、2重実行でエラーになるので、ここでのExceptionは無視してModfyを実行してみる
                 $sql = str_replace('ALTER TABLE `' . $this->tableName . '` ' . $propaty['alter'] . ' COLUMN ', 'ALTER TABLE `' . $this->tableName . '` MODIFY COLUMN ', $sql);
                 // MODIFYに変えて実行しなおし
                 $argDBO->execute($sql);
                 $executed = TRUE;
                 // XXX それでもダメならException!
             }
         }
     }
     if (TRUE === $executed) {
         $argDBO->commit();
     }
     return TRUE;
 }