/** * Processes file. * * @param string $file File. * * @return integer */ protected function processFile($file) { $size = filesize($file); $relative_file = $this->removeProjectPath($file); $sql = 'SELECT Id, Size FROM Files WHERE Name = :name'; $file_data = $this->db->fetchOne($sql, array('name' => $relative_file)); $this->db->beginTransaction(); if ($file_data === false) { $sql = 'INSERT INTO Files (Name, Size) VALUES (:name, :size)'; $this->db->perform($sql, array('name' => $relative_file, 'size' => $size)); $file_id = $this->db->lastInsertId(); } else { $file_id = $file_data['Id']; } // File is not changed since last time it was indexed. if ($file_data !== false && (int) $file_data['Size'] === $size) { $sql = 'UPDATE Files SET Found = 1 WHERE Id = :file_id'; $this->db->perform($sql, array('file_id' => $file_data['Id'])); $this->db->commit(); return $file_data['Id']; } $sql = 'UPDATE Files SET Found = 1 WHERE Id = :file_id'; $this->db->perform($sql, array('file_id' => $file_data['Id'])); $new_classes = array(); $parsed_file = new ReflectionFile($file); foreach ($parsed_file->getFileNamespaces() as $namespace) { foreach ($namespace->getClasses() as $class) { $new_classes[] = $class->getName(); $this->processClass($file_id, $class); } } if ($new_classes) { $sql = 'SELECT Id FROM Classes WHERE FileId = :file_id AND Name NOT IN (:classes)'; $deleted_classes = $this->db->fetchCol($sql, array('file_id' => $file_id, 'classes' => $new_classes)); } else { $sql = 'SELECT Id FROM Classes WHERE FileId = :file_id'; $deleted_classes = $this->db->fetchCol($sql, array('file_id' => $file_id)); } foreach ($deleted_classes as $deleted_class_id) { $this->deleteClass($deleted_class_id); } $this->db->commit(); ReflectionEngine::unsetFile($file); return $file_id; }
/** * * Commits the existing transaction and restores autocommit mode. * * @return bool True on success, false on failure. * * @see http://php.net/manual/en/pdo.commit.php * */ public function commit() { $result = $this->pdo->commit(); $this->logProfiles(__FUNCTION__); return $result; }